-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
AssemblyName.CodeBase
stripped from AssemblyName
before going to Resolving event handler
#59669
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsOn .NET Framework, For backwards compatibility when an app migrates from NetFX to .NET Core, being able to see the Repro: using System;
using System.Reflection;
#if NETCOREAPP
using System.Runtime.Loader;
#endif
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
#if NETCOREAPP
AssemblyLoadContext.Default.Resolving += ALC_Resolving;
#endif
AssemblyName an = AssemblyName.GetAssemblyName(@"C:\git\threading\bin\SosThreadingTools\Debug\net472\SosThreadingTools.dll");
an.CodeBase = @"C:\git\threading\bin\SosThreadingTools\Debug\net472\SosThreadingTools.dll";
Assembly a = Assembly.Load(an); // net472 succeeds. net5 fails.
}
#if NETCOREAPP
private static Assembly ALC_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
{
if (!string.IsNullOrEmpty(arg2.CodeBase)) // net5 sees this as null
{
return arg1.LoadFromAssemblyPath(arg2.CodeBase);
}
return null;
}
#endif
}
}
|
#7752 has some context |
Thanks for the context. I get that .NET Core wants to diverge in assembly load behavior from Framework. I would like to see the Codebase property preserved in the Resolving event just so an app can choose to re-implement Framework behavior. Right now, it appears to be impossible. |
We now have precedent from ProcessorArchitecture that we don't preserve obsolete information moving through AssemblyName. CodeBase is in the same category. Closing as Won't Fix. |
On .NET Framework,
Assembly.Load(AssemblyName)
will consider the value ofAssemblyName.CodeBase
before failing to load the assembly.On .NET Core, not only is the
CodeBase
property ignored, but it's omitted from a copy of theAssemblyName
that is given to theAssemblyLoadContext.Resolving
event handler, where I had hoped to re-implement the .NET Framework behavior of honoring that property.For backwards compatibility when an app migrates from NetFX to .NET Core, being able to see the
CodeBase
property would be useful. Why is it omitted? Would you consider modifying .NET Core to propagate that property when calling theResolving
event handler to give the host more options for finding assemblies?Repro:
The text was updated successfully, but these errors were encountered: