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

Fix TypeInitializationException for WebHostBuilder #821

Merged
merged 2 commits into from
Jan 4, 2019

Conversation

lmolkova
Copy link
Member

@lmolkova lmolkova commented Jan 4, 2019

System.TypeInitializationException : The type initializer for 'Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HostingDiagnosticListener' threw an exception.
---- System.TypeLoadException : Method 'ConfigureAppConfiguration' in type 'Microsoft.AspNetCore.Hosting.WebHostBuilder' from assembly 'Microsoft.AspNetCore.Hosting, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
   at Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HostingDiagnosticListener.Dispose()
   at Microsoft.ApplicationInsights.AspNetCore.RequestTrackingTelemetryModule.Dispose(Boolean disposing)

HostingDiagnosticListener uses WebHostBuilder class to determine Asp.NET Core version. Base IWebHostBuilder interface is loaded from Microsoft.AspNetCore.Hosting.Abstractions while WebHostBuilder is defined in Microsoft.AspNetCore.Hosting.
AppInsights SDK reference Ms.AspNetCore.Hosting 1.0.2.

In AspNetCore 2.0 timeframe, a new interface method ConfigureAppConfiguration was added to IWebHostBuilder, which 1.0.2 does not implement.

If user app does reference abstractions of relevant version (2.0+), but not hosting, the base interface has ConfigureAppConfiguration while implementation AppInsights brings in 1.0.2 does not implement it which causes this error.

This is the case in WebJobs.

This change determines AspNetCore version based on IWebHodstBuilder to avoid issues like this.

It also changes how we test HostingDiagnosticListener, allowing to parametrize aspnetcore version and test different combinations.

@lmolkova lmolkova changed the title Fix TypeInitializationException Fix TypeInitializationException for WebHostBuilder Jan 4, 2019
Copy link
Contributor

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chaneglog

@lmolkova lmolkova merged commit cdc3b18 into develop Jan 4, 2019
@lmolkova lmolkova deleted the lmolkova/FixTypeInitializationException branch October 4, 2019 22:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants