Home

News

(try alternative Compact News)

June 10, 2009

In a Visual Studio add-in Microsoft.VisualStudio.Shell.Package.GetGlobalService method always returns null. It works fine in Visual Studio integration package, but not in add-in. A workaround is to get IServiceProvider from DTE2 object which you always have in add-in:
System.IServiceProvider serviceProvider = 
	new Microsoft.VisualStudio.Shell.ServiceProvider(
		dte2_object as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
IMyGlobalService service = serviceProvider.GetService(typeof(SMyGlobalService)) as IMyGlobalService;
See How to get services from the VS DTE original blog post that presented this idea.

Full archive since February 9, 2003