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
{{ message }}
Repository navigation
Give more detailed information when assemblies fail to load #7051
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It would be great if this exception could tell me:
What version of System.Runtime.CompilerServices.Unsafe was referenced
What assembly referencing System.Runtime.CompilerServices.Unsafe triggered the load
What the version of the reference to System.Runtime.CompilerServices.Unsafe is that is causing the mismatch.
Bonus Points
Where the assembly was loaded on disk if it is on disk (though I can get this from the modules window in VS).
Reacted by Jonathan Dickinson, Jonathan Mezach, Richard Simpson, Alexander Köplinger, ikopylov, zabulus, Rich Keenan, David Roth, Thomas Krüger, Lukas Rieger and 34 more
Reacted by Rich Keenan, Stuart Blackler, Patrik Svensson, Geoffrey Huntley, Federico Andres Lois, Robin Sue and Ben {chmark} Adams
Worse case is below, which dependent library couldn't load, never know:
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
I've been hitting issues like this, too. I found that binding redirects weren't being correctly set despite my best efforts to have them generated. I solved the issues for myself using some duct tape PowerShell + ReGex, like so:
From the output directory:
Then with that list of "binaries which are actually present at runtime", search/replace:
Find: ([^,]+), Version=([^,]+), Culture=neutral, PublicKeyToken=(.*)
Replace:
Tooling could ease this, and better exception messages really would make our lives easier, but if anyone is hitting errors like these, that was my makeshift workaround.
In full Desktop, I enable Fusion logging for failures on all development and QA machines, and occasionally for onsite customer support as well. I know that Core does not have Fusion, but enabling a similar logging for load failures would be a great help. Of course some changes such as configuration would need to be done outside of the registry, though.
Before upgrading to 1.1, I got the error "Assembly with same name is already loaded" which is nice.
After 1.1, I got "System.IO.FileLoadException: Could not load file or assembly 'SimplCommerce.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)\r\n at SimplCommerce.WebHost.Extensions.ServiceCollectionExtensions.LoadInstalledModules(IServiceCollection services, IList`1 modules, IHostingEnvironment hostingEnvironment) in C:\DATA\Projects\SimplCommerce\SimplCommerce\src\SimplCommerce.WebHost\Extensions\ServiceCollectionExtensions.cs:line 44".
I don't know what going on, very confused. But then I try to get loaded assembly
It's not as convenient as exception message, but it provides more detail than could fit into exception message. We hope it can be used for at least the same scenarios as fusion logging was used in .NET Framework.
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Activity
Drawaes commentedon Nov 24, 2016
Agreed this causes nightmares when it happens in production
slawomirbrys commentedon Nov 24, 2016
Worse case is below, which dependent library couldn't load, never know:
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
ReubenBond commentedon Nov 24, 2016
I've been hitting issues like this, too. I found that binding redirects weren't being correctly set despite my best efforts to have them generated. I solved the issues for myself using some
duct tapePowerShell + ReGex, like so:From the output directory:
Then with that list of "binaries which are actually present at runtime", search/replace:
Find:
([^,]+), Version=([^,]+), Culture=neutral, PublicKeyToken=(.*)Replace:
Tooling could ease this, and better exception messages really would make our lives easier, but if anyone is hitting errors like these, that was my makeshift workaround.
bendono commentedon Nov 24, 2016
In full Desktop, I enable Fusion logging for failures on all development and QA machines, and occasionally for onsite customer support as well. I know that Core does not have Fusion, but enabling a similar logging for load failures would be a great help. Of course some changes such as configuration would need to be done outside of the registry, though.
thiennn commentedon Nov 24, 2016
Yeah, The same code
Before upgrading to 1.1, I got the error "Assembly with same name is already loaded" which is nice.
After 1.1, I got "System.IO.FileLoadException: Could not load file or assembly 'SimplCommerce.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)\r\n at SimplCommerce.WebHost.Extensions.ServiceCollectionExtensions.LoadInstalledModules(IServiceCollection services, IList`1 modules, IHostingEnvironment hostingEnvironment) in C:\DATA\Projects\SimplCommerce\SimplCommerce\src\SimplCommerce.WebHost\Extensions\ServiceCollectionExtensions.cs:line 44".
I don't know what going on, very confused. But then I try to get loaded assembly
It work the same as before.
The full source code can be found at https://github.com/simplcommerce/SimplCommerce/blob/master/src/SimplCommerce.WebHost/Extensions/ServiceCollectionExtensions.cs
vitek-karas commentedon Feb 10, 2021
We've added detailed tracing for this: https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/collect-details
It's not as convenient as exception message, but it provides more detail than could fit into exception message. We hope it can be used for at least the same scenarios as fusion logging was used in .NET Framework.
dotnet-policy-service commentedon Aug 13, 2025
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Aug 27, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.