question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resolve service for type 'Google.Cloud.Diagnostics.Common.IExceptionLogger' while attempting to activate 'Google.Cloud.Diagnostics.AspNetCore.ErrorReportingExceptionLoggerMiddleware'

See original GitHub issue

With exact same environment as https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/1186

dotnet publish 
dotnet project.dll

will generate this:

Unhandled Exception: System.InvalidOperationException: Unable to resolve service for type 'Google.Cloud.Diagnostics.Common.IExceptionLogger' while attempting to activate 'Google.Cloud.Diagnostics.AspNetCore.ErrorReportingExceptionLoggerMiddleware'.
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at ihs.Program.BuildWebHost(String[] args) in /Users/jdelfour/code/UCP/UDL-API/ihs/src/Program.cs:line 15
   at ihs.Program.Main(String[] args) in /Users/jdelfour/code/UCP/UDL-API/ihs/src/Program.cs:line 11
Abort trap: 6

in the startup.cs:

void ConfigureServices(IServiceCollection services) {
...
var tracingQPS = Configuration.GetSection("Diagnostics").GetValue<int>("TracingQPS", 1);
        services.AddGoogleTrace(options =>
        {
            options.ProjectId = Configuration["AppSettings:GoogleProjectID"];
            options.TraceFallbackPredicate = TraceDecisionPredicate.Default;
            options.Options = TraceOptions.Create(tracingQPS);
        });

        services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applifetime)
    {
        _logger.LogDebug("Configure() started...");

        //if we are not in prod or dev environments, do local logging to the console (do not send to cloud)
        if (env.IsProduction() || env.IsDevelopment())
        {
            app.UseGoogleExceptionLogging();

            loggerFactory.AddGoogle(Configuration["AppSettings:GoogleProjectID"]);

            app.UseGoogleTrace();
        }
...
}

Commenting out app.UseGoogleExceptionLogging(); fixes the issue

Packages of the project:

<ItemGroup>
    <PackageReference Include="Google.Cloud.Diagnostics.AspNetCore" Version="1.0.0-beta*" />
    <PackageReference Include="Google.Cloud.BigQuery.V2" Version="1.0.0-beta*" />
    <PackageReference Include="Slb.Realtime.Witsml.Objects" Version="13.0.200" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
    <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
    <PackageReference Include="Google.Apis" Version="1.27.1" />
  <PackageReference Include="Grpc.Core" Version="1.4.0" />
</ItemGroup>

Google.Cloud.Diagnostics.AspNetCore/1.0.0-beta11 Google.Cloud.BigQuery.V2/1.0.0-beta13

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iantalaricocommented, Jul 10, 2017

@Jonathan34 Perfect! Glad it’s working.

0reactions
Jonathan34commented, Jul 10, 2017

@iantalarico aaaah You are right, I did not have services.AddGoogleExceptionLogging.

Funny that i saw that it was required for the tracing but not for the exception logging…

Anyway, seems to work ok now 😃

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google.Cloud.Diagnostics.Common
The Google.Cloud.Diagnostics.Common package attempts to collect the filename and line number when error entries are collected.
Read more >
Google.Cloud.Diagnostics.AspNetCore
Google.Cloud.Diagnostics.AspNetCore is an ASP.NET Core instrumentation library for Google Logging, Error Reporting and Tracing.
Read more >
c# - 'Serilog.Extensions.Hosting.DiagnosticContext' while ...
DiagnosticContext' while attempting to activate 'Serilog.AspNetCore.RequestLoggingMiddleware' · Ask Question. Asked 2 years, 11 months ago.
Read more >
Google.Cloud.Diagnostics.AspNet
Google.Cloud.Diagnostics.AspNet is an ASP.NET instrumentation library for Google Stackdriver. It allows for simple integration of Stackdriver into ASP.
Read more >
Unable to resolve service for type 'Microsoft.AspNetCore. ...
I have search this error and tried every possible way but not able to resolve it. So can anyone help me to understand...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found