Unable to resolve service for type 'Google.Cloud.Diagnostics.Common.IExceptionLogger' while attempting to activate 'Google.Cloud.Diagnostics.AspNetCore.ErrorReportingExceptionLoggerMiddleware'
See original GitHub issueWith 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Jonathan34 Perfect! Glad it’s working.
@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