This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ async Task EnsurePackageLoaded(Guid packageGuid)
128128 [ PartCreationPolicy ( CreationPolicy . Shared ) ]
129129 public class ServiceProviderExports
130130 {
131+ static readonly ILogger log = LogManager . ForContext < ServiceProviderExports > ( ) ;
131132 readonly IServiceProvider serviceProvider ;
132133
133134 [ ImportingConstructor ]
@@ -152,9 +153,33 @@ public ServiceProviderExports([Import(typeof(SVsServiceProvider))] IServiceProvi
152153 public IPackageSettings PackageSettings => GetService < IPackageSettings > ( ) ;
153154
154155 [ ExportForVisualStudioProcess ]
155- public ITippingService TippingService => GetService < ITippingService > ( ) ;
156+ public ITippingService TippingService
157+ {
158+ get
159+ {
160+ var tippingService = GetService < ITippingService > ( ) ;
161+ if ( tippingService == null )
162+ {
163+ // GetService<TippingService>() was returning null on Visual Studio 2015, so fall back to using new TippingService(...)
164+ log . Warning ( "Couldn't find service of type {Type}, using new TippingService(...) instead" , typeof ( ITippingService ) ) ;
165+ tippingService = new TippingService ( serviceProvider ) ;
166+ }
167+
168+ return tippingService ;
169+ }
170+ }
156171
157- T GetService < T > ( ) => ( T ) serviceProvider . GetService ( typeof ( T ) ) ;
172+ T GetService < T > ( ) where T : class
173+ {
174+ var service = ( T ) serviceProvider . GetService ( typeof ( T ) ) ;
175+ if ( service == null )
176+ {
177+ log . Error ( "Couldn't find service of type {Type}" , typeof ( T ) ) ;
178+ return null ;
179+ }
180+
181+ return service ;
182+ }
158183 }
159184
160185 [ PackageRegistration ( UseManagedResourcesOnly = true , AllowsBackgroundLoading = true ) ]
You can’t perform that action at this time.
0 commit comments