Unable to access Extension Data Service in Azure DevOps extension

Leema Rose Priya Sheela 0 Reputation points
2025-09-18T10:34:16.9533333+00:00

I am using Azure DevOps storage, so I need to use the following code (as shown in the documentation: Azure DevOps Data Storage):

const extDataService = await SDK.getService<IExtensionDataService>(
  CommonServiceIds.ExtensionDataService
);
import { IExtensionDataService, CommonServiceIds } from "azure-devops-extension-api";

However, I am getting the error shown in the attached screenshot. Could you please provide a solution?

User's image

Azure DevOps
{count} votes

2 answers

Sort by: Most helpful
  1. Alex Burlachenko 18,570 Reputation points Volunteer Moderator
    2025-09-18T11:03:17.07+00:00

    hi,

    this often happens due to a timing issue. your code is trying to use the SDK.getService function before the azure devops sdk has fully finished loading on the page.

    the fix is to make sure your code runs only after the sdk is completely ready. wrap your service call in the SDK.init() or SDK.ready() function to ensure everything is loaded.

    try restructuring your code like this.

    import { IExtensionDataService, CommonServiceIds } from "azure-devops-extension-api";

    SDK.ready().then(async () => { try { const extDataService = await SDK.getService<IExtensionDataService>(CommonServiceIds.ExtensionDataService); // now u can use extDataService safely } catch (error) { console.error("Failed to get service:", error); } });

    this makes sure the sdk is fully initialized before u try to grab the extension data service.

    also, check your import statements. make sure you have the correct npm package installed. u need azure-devops-extension-api for those interfaces.

    if the problem persists, check the browser's developer console for any other errors about missing resources or failed network requests. sometimes a script might fail to load, breaking the whole sdk.

    hope this gets your extension back on track. those data services are super useful once u get them working.

    Best regards,

    Alex

    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    

    https://ctrlaltdel.blog/


  2. Rakesh Mishra 3,795 Reputation points Microsoft External Staff Moderator
    2025-10-15T06:07:31.3733333+00:00

    Hi Leema Rose Priya Sheela,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    Could you please confirm if you are still facing the issue. If yes, could you provide below information to assist you further on this.

    • the error details
    • where we are getting the error, during page loading only.
    • share code snippet (you can send via Private message also.)
    • try referring to sample code in which SDK.init() should be done in order to use SDK.getService().
    <!-- index.html loads your bundle which contains the code below -->
    <script type="module">
      import * as SDK from "azure-devops-extension-sdk";
      import { CommonServiceIds } from "azure-devops-extension-api";
    
      // initialize early
      SDK.init();
    
      // wait until host signals ready
      SDK.ready().then(async () => {
        try {
          console.log("SDK ready");
          const extDataService = await SDK.getService(CommonServiceIds.ExtensionDataService);
          if (!extDataService) throw new Error("ExtensionDataService is undefined");
          const token = await SDK.getAccessToken();
          const manager = await extDataService.getExtensionDataManager("publisher.extensionId", token);
          console.log("manager ready", manager);
          // manager.getValue / setValue ...
        } catch (err) {
          console.error("Failed to access extension data service:", err);
        }
      });
    </script>
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.