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

System.NotSupportedException : Assembly.Load with a Codebase is not supported. #7752

Closed
rahku opened this issue Mar 29, 2017 · 4 comments
Closed
Assignees
Milestone

Comments

@rahku
Copy link
Contributor

rahku commented Mar 29, 2017

Either Assembly.GetName() should not set Codabase property or LoadFromAssemblyName should ignore CodeBase property in AssemblyName

@rahku rahku self-assigned this Mar 29, 2017
@rahku
Copy link
Contributor Author

rahku commented Apr 16, 2017

If you call Assembly.GetName() for a loaded assembly the returned AssemblyName object has its CodeBase property set to url based location of assembly. If you use the same AssemblyName object and pass it to Assembly.Load(AssemblyName n) then it fails saying Load using CodeBase is not supported. In my opinion this is not good experience. I have two options to fix this:

  1. Don't set property codebase & escapedcodebase in assemblyname. we already have a new property Location in assemblyname which provides path based location of assembly.
  2. In function Assembly.Load(AssemblyName n) ignore the value of codebase. Save value of codebase property and in the passed-in assemblyname object set codebase property to null before call to InternalLoadAssemblyName() function. Then before return from Load() function reset back the CodeBase property to its original value.

I would prefer option 1 but this could be problematic for desktop compat. or do you think it does not give much value to fix this and should stay the way it is?

@jkotas @gkhanna79 Let me know your thoughts

@jkotas
Copy link
Member

jkotas commented Apr 16, 2017

There is also Assembly.CodeBase property. It would be nice if Assembly.CodeBase and Assembly.GetName().CodeBase returned same results.

Another option is to turn AssemblyName loads with CodeBase property set into LoadFrom. E.g. the following works in desktop:

    class Program
    {
        static void Main(string[] args)
        {
            var a = typeof(Program).Assembly;

            var an = new AssemblyName();
            an.CodeBase = a.CodeBase;

            var loaded = Assembly.Load(an);
            Debug.Assert(a.Equals(loaded));
        }
    }

Any reason to not do that?

Save value of codebase property and in the passed-in assemblyname object set codebase property to null before call to InternalLoadAssemblyName() function. Then before return from Load() function reset back the CodeBase property to its original value.

I do not think you would ever want to mutate the AssemblyName passed in. You would want to create a copy if we want with this option.

problematic for desktop compat

Yes, both Assembly.CodeBase and AssemblyName.CodeBase have non-trivial usage.

@rahku
Copy link
Contributor Author

rahku commented Apr 16, 2017

Another option is to turn AssemblyName loads with CodeBase property set into LoadFrom. E.g. the following works in desktop:

We have already diverged a lot in behavior compared to desktop in Load* apis. So trying to do what desktop does should not be a goal I think. I feel it is better to be explicit between Load & LoadFrom and not combine the two. It is more simpler to explain & understand.
There is also the complication of when the assemblyname contains both display name and codebase. In desktop the behavior for when this turns into LoadFrom is to verify that display name matches the loaded assembly and if that fails then fail the load. This would turn out to be complicated to handle because of the way loadfrom is implemented in .net core.
And I do not think the complication is worth the benefit

So I am planning to go with this approach

I do not think you would ever want to mutate the AssemblyName passed in. You would want to create a copy if we want with this option.

@jkotas
Copy link
Member

jkotas commented Apr 17, 2017

Sounds good.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants