2

How do I make sure my service gets registered in the AsyncPackage of my Visual Studio extension? I have been following a sample from VSSDK-Extensibility-Samples. I have also taken a look at how other extensions do it. I tried to do the same yet I cannot obtain my service from global service provider.

Steps I did:

  • [Shell.ProvideService(typeof(SMyService), IsAsyncQueryable = true)] for my async package class
  • [Guid(...)] interface SMyService { } defined interface in a new file
  • public class MyService { } as service implementation. It is created by CreateServiceAsync method
  • var container = (Shell.IAsyncServiceContainer)this; container.AddService(typeof(SMyService), CreateServiceAsync); inside of AsyncPackage.InitializeAsync method before calling base.InitializeAsync

Is there something I am missing to make my service accessible from other VS Extextension services? When I Do AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SMyService)) inside of say MEF component method I get a null. Do I need to register the service anywhere else?

Mylan719
  • 93
  • 9
  • Maybe you can get some help from [this thread](https://stackoverflow.com/questions/31194968/how-to-register-my-service-as-a-global-service-or-how-can-i-use-mef-in-my-scenar). – LoLance Oct 21 '19 at 11:43
  • My problem is I absolutely have to register the service the old way. The service I am trying to extend uses `serviceProvider.GetService(Type.GetTypeFromCLSID(...))` to obtain the dependancy I am triing to provide. So I need to pass a guid to the parent service and provide my service identified by the guid. – Mylan719 Oct 21 '19 at 14:18
  • May you get some help from [this document](https://learn.microsoft.com/en-us/visualstudio/extensibility/how-to-troubleshoot-services?view=vs-2019). And perhaps you're using an old version of VS? As I know, the behavior of VS extension differs in different versions, could I know what's the version you use, it would make great help for trouble shooting... :) – LoLance Oct 23 '19 at 02:38
  • I am using 16.2.5 and 15.9 – Mylan719 Oct 23 '19 at 13:46
  • Hi, I'm a bit confused about `My problem is I absolutely have to register the service the old way.` Since you're using VS2019, why do you need to register the service in an old way? – LoLance Oct 25 '19 at 11:32

0 Answers0