Strange Type Initialization Exception

160 Views Asked by At

I am using the following code:

var client = new HttpClient();
var result = await client.GetAsync("http://example.com/");
var response = await result.Content.ReadAsStringAsync();
Console.WriteLine(response);

on Visual Studio 2019 version 16.9.4 and the project is in .NET 5
Everything is OK when I use :

  1. CTRL+F5 (Release or Debug)
  2. Step by step mode - F11 or F10 on Debug

But when i use F5 that strange error (TypeInitializationException) occurs:

The type initializer for 'Microsoft.IntelliTrace.TelemetryObserver.IntelliTraceObserver' threw an exception.
   at Microsoft.IntelliTrace.TelemetryObserver.IntelliTraceObserver.IsEnabled(String telemetryName)
   at System.Diagnostics.DiagnosticListener.<>c__DisplayClass2_0.<Subscribe>b__0(String name, Object arg1, Object arg2)
   at System.Diagnostics.DiagnosticListener.IsEnabled(String name, Object arg1, Object arg2)
   at System.Net.Http.DiagnosticsHandler.<SendAsyncCore>d__5.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<SendAsyncCore>d__85.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyAwesomeApp.Program.<Main>d__0.MoveNext() in X:\MyAwesomeApp\Program.cs:line 13

on Program.cs line 13 there exists first await statement(see code above)
And the inner exception is: (FileNotFoundException)

Could not load file or assembly 'Microsoft.IntelliTrace.TelemetryObserver.Common, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

   at Microsoft.IntelliTrace.TelemetryObserver.IntelliTraceObserver..cctor()

the same thing happens when using .net .netcore .net standard and with other project types.
and this prevents me normal debugging so as a lazy-fix I find TelemetryObserver.Common's dll file and add it as a reference to every project I want to debug normally but I know this is not a true solution
Another thing is that this exception occurs only when code does network calls or database connections or smth like that
I am aware when the TypeInitializationException may occur and its use cases.
Since it is not my code I dont know the cause so I think this is smth like configuration on Visual Studio to load that dll file on debugging and I dont know how to avoid it
That is where I need help.

0

There are 0 best solutions below