core icon indicating copy to clipboard operation
core copied to clipboard

AssemblyLoadContext missing ctor with parameters and Unload method

Open uffebjorklund opened this issue 7 years ago • 2 comments

AssemblyLoadContext missing ctor with parameters and Unload method

Have been playing with AssemblyLoadContext in previous versions of dotnet core 3, but in 3.0.100-preview8-013656 there are no overloads of the constructor. In previous versions (and in the docs) there are 3 constructors

 - protected AssemblyLoadContext ();
 - protected AssemblyLoadContext (bool isCollectible);
 - public AssemblyLoadContext (string name, bool isCollectible = false);

In 3.0.100-preview8-013656 I get error CS1729: 'AssemblyLoadContext' does not contain a constructor that takes 1 arguments, and if I take a look at the AssemblyLoadContext class from my project I see this

#region Assembly System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Runtime.Loader.dll
#endregion

using System.IO;
using System.Reflection;

namespace System.Runtime.Loader
{
    public abstract class AssemblyLoadContext
    {
        protected AssemblyLoadContext();

        public static AssemblyLoadContext Default { get; }

        public event Func<AssemblyLoadContext, AssemblyName, Assembly> Resolving;
        public event Action<AssemblyLoadContext> Unloading;

        public static AssemblyName GetAssemblyName(string assemblyPath);
        public static AssemblyLoadContext GetLoadContext(Assembly assembly);
        public Assembly LoadFromAssemblyName(AssemblyName assemblyName);
        public Assembly LoadFromAssemblyPath(string assemblyPath);
        public Assembly LoadFromNativeImagePath(string nativeImagePath, string assemblyPath);
        public Assembly LoadFromStream(Stream assembly);
        public Assembly LoadFromStream(Stream assembly, Stream assemblySymbols);
        public void SetProfileOptimizationRoot(string directoryPath);
        public void StartProfileOptimization(string profile);
        protected abstract Assembly Load(AssemblyName assemblyName);
        protected virtual IntPtr LoadUnmanagedDll(string unmanagedDllName);
        protected IntPtr LoadUnmanagedDllFromPath(string unmanagedDllPath);
    }
}

Missing constructors, but also missing the expected Unload method.

General

OS: MacOs High Sierra SDK: 3.0.100-preview8-013656

uffebjorklund avatar Aug 20 '19 03:08 uffebjorklund

Downloaded a simpler project from github with an example of assembly load context. In that sample I have no issues CollectibleAssemblies

When looking at the AssemblyLoadContext used in that sample it looks ok and also compiles just fine.

So it is clearly my project that has some assemblies from a previous version of dotnet core.

uffebjorklund avatar Aug 20 '19 03:08 uffebjorklund

I had missed to update all package references to the latest preview :( When fixed this is working just fine :)

uffebjorklund avatar Aug 20 '19 03:08 uffebjorklund