You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should throw System.BadImageFormatException when loading a non-CLR Assembly with Assembly.Load(String), e.g.: Microsoft.Data.SqlClient.SNI.dll. net48 program has the correct behavior, but the net8.0 program doesn't, which is different from the official document description.
Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Data.SqlClient.SNI' or one of its dependencies. The module was expected to contain an assembly manifest.
Actual behavior
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient.SNI, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Regression?
No response
Known Workarounds
AssemblyName.GetAssemblyName(String) works correctly in net8.0.
/// <summary>/// Load an assembly from the given path./// The assembly might not be a CLR assembly, e.g. Microsoft.Data.SqlClient.SNI.dll. But Assembly.Load doesn't throw BadImageFormatException, instead it throws FileNotFoundException, which can lead to confusion./// So we use AssemblyName.GetAssemblyName to check if the assembly is a CLR assembly./// </summary>/// <param name="assemblyPath">absolute path to the assembly</param>/// <returns>null if the assembly is not a CLR assembly; otherwise, the Assembly object.</returns>staticAssembly?LoadAssembly(stringassemblyPath){AssemblyName?assemblyName=null;try{assemblyName=AssemblyName.GetAssemblyName(assemblyPath);}catch(BadImageFormatException){}returnassemblyNameisnull?null:Assembly.Load(assemblyName);}
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered:
.NET Core assembly loader does not consider files that were manually copied into the application directory as application assemblies. It only considers files that the app has been composed from during the build - the list is in .deps.json file in the app directory. This behavior is different from .NET Framework by design.
It explains why you see FileNotFoundException in your repro project that is manually copying Microsoft.Data.SqlClient.SNI.dll into the application directory.
My repo is a simplified reproduction.
In real world, it still throws FileNotFoundException even .deps.json contains the Microsoft.Data.SqlClient.SNI.dll.
Description
It should throw
System.BadImageFormatException
when loading a non-CLR Assembly withAssembly.Load(String)
, e.g.:Microsoft.Data.SqlClient.SNI.dll
.net48
program has the correct behavior, but thenet8.0
program doesn't, which is different from the official document description.Reproduction Steps
reproduce-dotnet-runtime-issue-111597
Expected behavior
Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Data.SqlClient.SNI' or one of its dependencies. The module was expected to contain an assembly manifest.
Actual behavior
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient.SNI, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Regression?
No response
Known Workarounds
AssemblyName.GetAssemblyName(String)
works correctly innet8.0
.Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: