dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.04k forks source link

Could not load file or assembly 'Microsoft.AspNetCore.Diagnostics.Abstractions' with .net 7.0.5 #48244

Open tygore587 opened 1 year ago

tygore587 commented 1 year ago

Description

We are experiencing a problem with our .net mvc api running in service fabric which is getting the error Could not load file or assembly 'Microsoft.AspNetCore.Diagnostics.Abstractions.

The compile target is .net 7.

I search for other bugs and found the issue dotnet/runtime#3252 and searched for direct package references in our project, but found none.

We deploy the api as a self contained package, so the host runtime shouldn't matter?

Reproduction Steps

The problem is, that I can't reproduce it locally. It just happens, when it is deployed. But we can't find the cause.

Expected behavior

Not seeing an error

Actual behavior

Throws an exception:

Could not load file or assembly 'Microsoft.AspNetCore.Diagnostics.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Type: System.IO.FileNotFoundException
File not found: Microsoft.AspNetCore.Diagnostics.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Stack Trace: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
at Microsoft.AspNetCore.Server.HttpSys.RequestContext`1.ExecuteAsync()
at Microsoft.AspNetCore.Server.HttpSys.RequestContext`1.ExecuteAsync()

Regression?

It worked for month using .net 6 before. We just started to see this happen after upgrading to .net 7

Known Workarounds

We don't have one.

Configuration

Other information

If you need more information, please let me know.

LTAravindh92 commented 1 year ago

I'm also facing the same issue.

tygore587 commented 1 year ago

We also started to experience this issue with other packages even locally.

We have some wrapper code around the azure service bus sdk. They are located in a .net standard project.

The workaround we found was to directly instantiate a class from the package that was not found. If we do this the problem disappears. But we are not comfortable to use .net 7 with these kind of issues because they appeared out of nowhere. We never had a problem before even with .net 7 and .net 6 was stable for month on our prod system.

Just scrolled through the issues and it looks like these problems are in general similar to #48199

moellerm commented 1 year ago

These problems could be related to the issue https://github.com/dotnet/runtime/issues/60144 if the exceptions occur after upgrading the dotnet runtime (for example by Windows Update or another service/installer/update) while the application/service is running.

tygore587 commented 1 year ago

These problems could be related to the issue dotnet/runtime#60144 if the exceptions occur after upgrading the dotnet runtime (for example by Windows Update or another service/installer/update) while the application/service is running.

We are building self containted packages, so this shouldn't be an issue. Also it worked like 99% of the time until it randomly stopped working at all. At the moment we are still at .net 6 because this breaked our production environment like 3-4 times and some developers started to get the same issue randomly on their laptops.