Apm-agent-dotnet: TypeInitializationException in Elastic.Apm.Helpers.PlatformDetection

Created on 26 May 2020  路  4Comments  路  Source: elastic/apm-agent-dotnet

From discuss.elastic.co.

We don't really have that much running in .cctor. First thing I can think of is that here RuntimeInformation.FrameworkDescription.StartsWith causes the issue, although that seems to be strange.

bug

Most helpful comment

Hi! I just got the exact same error message but when I tried to break on exception I found out that the real error was that I had <dependentAssembly> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly> in web.config which gave me a FileNotFoundException for InteropServices in PlatformDetection. But removing it solved the problem.

Thanks for the info @Towmeykaw,

that sounds very reasonable. We have static properties in PlatformDetection.cs, like here and those are initialized in the .cctor (that's where the exception happens) and those properties are indeed initialized by using System.Runtime.InteropServices.RuntimeInformation. So very likely that a wrong version or a missing System.Runtime.InteropServices.RuntimeInformation can cause this.

There is already a try-catch merged to master, so even if this happens, we won't crash once that's release.

Again, thanks for the nice summery about the fix.

All 4 comments

One option could be to try-catch the platform detection here and report "unknown" if it fails.

But I'd prefer to understand why it fails in that particular environment and find some fix for it, instead of workarounding with a try-catch.

Hi! I just got the exact same error message but when I tried to break on exception I found out that the real error was that I had <dependentAssembly> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly> in web.config which gave me a FileNotFoundException for InteropServices in PlatformDetection. But removing it solved the problem.

Hi! I just got the exact same error message but when I tried to break on exception I found out that the real error was that I had <dependentAssembly> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly> in web.config which gave me a FileNotFoundException for InteropServices in PlatformDetection. But removing it solved the problem.

Thanks for the info @Towmeykaw,

that sounds very reasonable. We have static properties in PlatformDetection.cs, like here and those are initialized in the .cctor (that's where the exception happens) and those properties are indeed initialized by using System.Runtime.InteropServices.RuntimeInformation. So very likely that a wrong version or a missing System.Runtime.InteropServices.RuntimeInformation can cause this.

There is already a try-catch merged to master, so even if this happens, we won't crash once that's release.

Again, thanks for the nice summery about the fix.

Closing now - the PR will prevent future crashes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gregkalapos picture gregkalapos  路  5Comments

graphaelli picture graphaelli  路  8Comments

fernandolamp picture fernandolamp  路  7Comments

mterwoord picture mterwoord  路  7Comments

SergeyKleyman picture SergeyKleyman  路  8Comments