Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load assemblies using SDK 7.0.202 but worked on SDK 7.0.201 #83526

Closed
reduckted opened this issue Mar 16, 2023 · 23 comments
Closed

Unable to load assemblies using SDK 7.0.202 but worked on SDK 7.0.201 #83526

reduckted opened this issue Mar 16, 2023 · 23 comments

Comments

@reduckted
Copy link

reduckted commented Mar 16, 2023

Description

When compiled using .NET SDK 7.0.202, code that uses Assembly.Load(AssemblyName) fails to load assemblies that exists in the application directory.

Here's how you can reproduce the bug.

  1. Make sure you have .NET SDK 7.0.201 and 7.0.202 installed.
  2. Clone https://github.com/reduckted/LoadAssemblyBug
  3. Open PowerShell and run run.ps1.

The application is quite simple. It finds all .dll files in the current working directory, gets the assembly name from each file, then uses Assembly.Load() to load that assembly.

Use the run.ps1 script to reproduce the bug. It will first publish the application using SDK 7.0.201, then run the application. This will succeed and you will see it log the name of each assembly that it loads. Next it will publish the application using SDK 7.0.202, then run the application. This will fail for the vast majority of assemblies.

Here's a snippet of the output when using 7.0.201:

Loading assembly: LoadAssemblyBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Loading assembly: Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

And here's a snippet of the output when using 7.0.202:

Loading assembly: LoadAssemblyBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Loading assembly: Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.

Configuration

  • .NET version: .NET SDK 7.0.202, self-contained published application.
  • OS: Windows 10
  • Architecture: x64

I've tried using Microsoft.NET.Sdk.Web and Microsoft.NET.Sdk, and both exhibit the same bug.

I have not tried using a different OS.

Regression?

Yes. This works flawlessly when compiled with .NET SDK 7.0.201.

Related to dotnet/core#8285

@MWin10
Copy link

MWin10 commented Mar 16, 2023

I've a similar problem: When trying to run my application on .NET 7.0.4, I get assembly loading errors messages as below. Uninstalling 7.0.4 versions of the runtime and using 7.0.3 version instead brings my app back to work.

Error message is:
System.IO.FileNotFoundException: Could not load file or assembly 'NodaTime, Version=3.1.6.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1'. The system cannot find the file specified.

File NodaTime.dll exists in version 3.1.6.0 on the target machine in the same directory as my .exe file and all the other DLLs.
For me, this issue only occurrs when publishing the app to another machine running .NET 7.0.4, but not on my development machine where I'm using Visual Studio 2022 and where 7.0.4 runtime is also installed.

Configuration on the target machine

.NET version: .NET 7.0.4 ASP.Net Core runtime and .NET Windows Desktop runtime.
OS: Windows 10
Target Framework: net7.0-windows10.0.17763.0
Target Runtime: win-x64
Used Publish Options (in VS 2022): ReadyToRun: Enabled, Produce single file: NOT enabled.

@jeffschwMSFT jeffschwMSFT transferred this issue from dotnet/core Mar 16, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 16, 2023
@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Mar 16, 2023
@ghost
Copy link

ghost commented Mar 16, 2023

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When compiled using .NET SDK 7.0.202, code that uses Assembly.Load(AssemblyName) fails to load assemblies that exists in the application directory.

Here's how you can reproduce the bug.

  1. Make sure you have .NET SDK 7.0.201 and 7.0.202 installed.
  2. Clone https://github.com/reduckted/LoadAssemblyBug
  3. Open PowerShell and run run.ps1.

The application is quite simple. It finds all .dll files in the current working directory, gets the assembly name from each file, then uses Assembly.Load() to load that assembly.

Use the run.ps1 script to reproduce the bug. It will first publish the application using SDK 7.0.201, then run the application. This will succeed and you will see it log the name of each assembly that it loads. Next it will publish the application using SDK 7.0.202, then run the application. This will fail for the vast majority of assemblies.

Here's a snippet of the output when using 7.0.201:

Loading assembly: LoadAssemblyBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Loading assembly: Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Loading assembly: Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

And here's a snippet of the output when using 7.0.202:

Loading assembly: LoadAssemblyBug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Loading assembly: Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Cookies, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.
Loading assembly: Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Could not load file or assembly 'Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=AMD64'. The system cannot find the file specified.

Configuration

  • .NET version: .NET SDK 7.0.202, self-contained published application.
  • OS: Windows 10
  • Architecture: x64

I've tried using Microsoft.NET.Sdk.Web and Microsoft.NET.Sdk, and both exhibit the same bug.

I have not tried using a different OS.

Regression?

Yes. This works flawlessly when compiled with .NET SDK 7.0.201.

Related to dotnet/core#8285

Author: reduckted
Assignees: -
Labels:

area-AssemblyLoader-coreclr

Milestone: -

@jeffschwMSFT jeffschwMSFT added this to the 7.0.x milestone Mar 16, 2023
@jkotas
Copy link
Member

jkotas commented Mar 16, 2023

@VSadov This looks like a regression from #81101

@jkotas
Copy link
Member

jkotas commented Mar 16, 2023

I think we should revert the change.

@agocke
Copy link
Member

agocke commented Mar 16, 2023

Sorry, which change would we revert? My understanding is that #81101 was itself a fix for a regression. If we revert it that would presumably bring back the regression.

@VSadov
Copy link
Member

VSadov commented Mar 16, 2023

I think we should revert the change.

This was supposed to be a compat fix making behavior closer to what was a while ago.

Do we need to re-do the change (i.e. make the algorithm even closer to what native code used to do), or we want to just revert the change?

@VSadov
Copy link
Member

VSadov commented Mar 16, 2023

The original bug was - #77697
I do not recall that breaking any real scenarios, but it was an observable change, so we tried to get closer to the behavior of the native code (however ad-hoc it could be).

I think reverting this change and "Won't Fix"-ing the scenario is a possible way forward, so I am wondering - which way do we want to go?

@jkotas
Copy link
Member

jkotas commented Mar 16, 2023

My understanding is that #81101 was itself a fix for a regression

Yes, it was trying to fix a relatively minor regression in behavior of obsolete APIs.

I think reverting this change and "Won't Fix"-ing the scenario is a possible way forward

Yes, I think it would be the best path forward. The problem with the obsolete ProcessArchitecture part of the assembly name is that it is apparently not handled consistently throughout the system. Trying to fix it is just going to introduce more problems than it is worth it.

@arunchndr
Copy link
Member

Is going back to 7.0.201 the right workaround at this point?

@VSadov
Copy link
Member

VSadov commented Mar 16, 2023

Is going back to 7.0.201 the right workaround at this point?

Also, if code change is an option, it may help to set the ProcessorArchitecture property to ProcessorArchitecture.None once the AssemblyName is created.

@farnyser
Copy link

Show stopper for us, is there a workaround beside rollback ?

@ltrzesniewski
Copy link
Contributor

ltrzesniewski commented Mar 20, 2023

We got this issue with an AssemblyLoadContext. Specifically, AssemblyLoadContext.LoadFromAssemblyName rejects an AssemblyName with a ProcessorArchitecture other than None (when the project output is published with a RID).

Workaround to use at the start of AssemblyLoadContext.Load, in case it may help anyone:

#pragma warning disable SYSLIB0037
assemblyName = (AssemblyName)assemblyName.Clone();
assemblyName.ProcessorArchitecture = ProcessorArchitecture.None;
#pragma warning restore SYSLIB0037

CyrusNajmabadi pushed a commit to CyrusNajmabadi/roslyn that referenced this issue Mar 20, 2023
See dotnet/runtime#83526

MEF uses the APIs affected to load assemblies.  To workaround the issue we pre-load all the assemblies we're adding to the MEF composition
@reduckted
Copy link
Author

When will this be fixed? It still occurs in SDK 7.0.203.

@vitek-karas
Copy link
Member

@VSadov did we backport #84028 (or are we going to?)

@janstrube
Copy link

In the last few weeks we have experienced twice an intermittent error in our ASP.NET Core MVC web site:

FileNotFoundException(Could not load file or assembly 'System.Net.Mail, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.).

The other time another system assembly could not be found. A restart of the application (IIS app pool) resolved the issue. The web site is published self containing. In both cases the assembly with the correct PublicKeyToken existed on the server.

We have never seens such issues with 7.0.3 and below. Could this be the same issue?

@agocke
Copy link
Member

agocke commented Apr 25, 2023

I believe the fix for this issue should appear in 7.0.6, which should ship in May.

@mrunks
Copy link

mrunks commented May 9, 2023

I just noticed this issue today but have had the problem with System.Net.Mail FileNotFoundException as well as the same exception for the following:

System.IO.FileNotFoundException: Could not load file or assembly ‘System.Diagnostics.TraceSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The system cannot find the file specified.

The systems.diagnostics.Tracesource exception was triggered when executing an OrderBy the System.Linq.Dynamic.Core library.

The exceptions only occur when I use Self Contained instead of Framework Dependent as the publishing option.

@reduckted
Copy link
Author

@agocke Is there an issue tracking the fix for this in 7.0.6?

@mrunks
Copy link

mrunks commented May 12, 2023

@reduckted I hope there is. All of the problems that have occured for that apps I work on are with Self Contained publishing. So if others are looking for a short term solution, Framework Dependent is an option.

@schhwork
Copy link

Another option is to put

<RuntimeFrameworkVersion>7.0.3</RuntimeFrameworkVersion>

In your project files

@agocke
Copy link
Member

agocke commented May 15, 2023

@reduckted This is the issue. I'm waiting for the fix to ship and confirm that it fixes the problem, then I'll close this issue.

@agocke agocke added this to AppModel May 17, 2023
@reduckted
Copy link
Author

Seems to be fixed in .NET SDK 7.0.304.

@vitek-karas
Copy link
Member

Thanks for the confirmation @reduckted . Closing.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests