Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

ArgumentNullException caused by DefaultApplicationInsightsServiceConfigureOptions #696

Closed
Tadimsky opened this issue Jun 6, 2018 · 3 comments
Labels
Milestone

Comments

@Tadimsky
Copy link

Tadimsky commented Jun 6, 2018

I'm updating to .NET Core 2.1 and I'm running into an error that seems new.
I'm using this library in .NET Core services on Service Fabric (not Kestrel ASP.Net Core services) and it looks like a new change has caused some issues because IHostingEnvironment has a null ContentRootPath.

This is the callstack I get:

g
 Unhealthy event: SourceId='System.RA', Property='ReplicaOpenStatus', HealthState='Warning', ConsiderWarningAsError=false.
Replica had multiple failures during open on _nt1vm_0. API call: IStatelessServiceInstance.Open(); Error = System.ArgumentNullException (-2147467261)
Value cannot be null.
Parameter name: basePath
   at Microsoft.Extensions.Configuration.FileConfigurationExtensions.SetBasePath(IConfigurationBuilder builder, String basePath)
   at Microsoft.AspNetCore.Hosting.DefaultApplicationInsightsServiceConfigureOptions.Configure(ApplicationInsightsServiceOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ComponentVersionTelemetryInitializer..ctor(IOptions`1 options)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Intentional.Services.Utilities.ServiceFabric.Logging.ServiceFabricApplicationInsightsConfiguration.ConfigureServiceFabricApplicationInsights[T](ILoggingBuilder loggingBuilder, IConfiguration configuration, T serviceContext)
   at Microsoft.Intentional.SharesService.Program.<>c__DisplayClass0_0.
b__1(ILoggingBuilder builder) in C:\Users\joschm\Intentional\services\src\SharesService\Program.cs:line 55
   at Microsoft.Extensions.DependencyInjection.LoggingServiceCollectionExtensions.AddLogging(IServiceCollection services, Action`1 configure)
   at Microsoft.Intentional.SharesService.Program.<>c.
b__0_0(StatelessServiceContext context) in C:\Users\joschm\Intentional\services\src\SharesService\Program.cs:line 46
   at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceFactory.System.Fabric.IStatelessServiceFactory.CreateInstance(String serviceTypeName, Uri serviceName, Byte[] initializationData, Guid partitionId, Int64 instanceId)
   at System.Fabric.ServiceFactoryBroker.<>c__DisplayClass9_0.b__0(IStatelessServiceFactory factory, ServiceInitializationParameters initParams)
   at System.Fabric.ServiceFactoryBroker.CreateHelper[TFactory,TReturnValue](IntPtr nativeServiceType, IntPtr nativeServiceName, UInt32 initializationDataLength, IntPtr nativeInitializationData, Guid partitionId, Func`3 creationFunc, Action`2 initializationFunc, ServiceInitializationParameters initializationParameters)
For  [Truncated]

Here's the line of code where this happens: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blame/43a74c64d01b11929da6a96a9e4501dad5620e53/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs#L31

It looks like the DefaultApplicationInsightsServiceConfigureOptions was DI'ed by default now according to this change: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blame/05dbca38b5ebd54df3fdf1968d497d3ed91c6782/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs#L181

Is there any way to work around this? Without creating a fake IHostingEnvironment to get this happy?

Version Info

image

SDK Version : 2.3.0
.NET Version : .NET Core 2.1
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : Service Fabric
OS : Windows Server 2016 R2
Hosting Info (IIS/Azure WebApps/ etc) :

@cijothomas cijothomas added the bug label Jun 8, 2018
@cijothomas
Copy link
Contributor

Thanks @Tadimsky for reporting. Do you know on what situations ContentRootPath is null ? Is it only in ServiceFabric?

I will fix the sdk to not crash by doing null check.

@Tadimsky
Copy link
Author

It was in a .NET Core application where we were not using WebHostBuilder so we didn't have it set.

@cijothomas cijothomas added this to the 2.4.0-beta1 milestone Jun 14, 2018
@cijothomas
Copy link
Contributor

Ok. Fixed the nullref exception for 2.4.0-beta1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants