title: How to call a method in a .NET Core assembly from .NET Framework
body: <p>I have two assemblies:</p>
  <ol>
  <li>The parent assembly is compiled against .NET Framework.</li>
  <li>The child assembly is compiled against .NET Core.</li>
  </ol>
  <p><strong>I want to call a method in the child assembly, and retrieve its return object</strong>.  The constructor doesn't take any parameters. The method does not take any parameters, and returns a <code>Microsoft.OData.Edm.IEdmModel</code></p>
  <p>Things I've tried so far:</p>
  <ol>
  <li>Creating a separate appdomain, and calling <code>domain.CreateInstanceAndUnwrap</code>:</li>
  </ol>
  <pre><code>AppDomainSetup setup = new AppDomainSetup()
  {
     ApplicationBase = path
     PrivateBinPath = path
  };
  AppDomain domain = AppDomain.CreateDomain(&quot;Child&quot;, null, setup);
  AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
  object instance = domain.CreateInstanceAndUnwrap(assemblyName.FullName, className);
  </code></pre>
  <ol start="2">
  <li>Creating a class that extends <code>MarshalByRefObject</code>, and using that to load the assembly, call the function, and marshal the return type:</li>
  </ol>
  <pre><code>AppDomain domain = AppDomain.CreateDomain(&quot;Child&quot;);
  BinaryMarshal marshal = (BinaryMarshal) domain.CreateInstanceAndUnwrap(typeof(BinaryMarshal).Assembly.FullName, typeof(BinaryMarshal).FullName);
  IEdmModel model = marshal.LoadEdmModel(path, className, functionName);
  
  //BinaryMarshal.cs:
  internal class BinaryMarshal : MarshalByRefObject
  {
      public IEdmModel LoadEdmModel(string binary, string className, string functionName)
      {
          Assembly assembly = Assembly.LoadFrom(binary);
          Type type = assembly.GetType(className);  //returns null because of exception listed below
       }
  }
  </code></pre>
  <p>In both cases, the code doesn't work because of the following exception (obtained from <code>Fuslogvw.exe</code>):</p>
  <pre><code>*** Assembly Binder Log Entry  (4/29/2019 @ 10:34:48 AM) ***
  
  The operation failed.
  Bind result: hr = 0x80070002. The system cannot find the file specified.
  
  Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
  Running under executable  C:\develop\parent\out\debug-amd64\Parent.exe
  --- A detailed error log follows. 
  
  === Pre-bind state information ===
  LOG: DisplayName = System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
   (Fully-specified)
  LOG: Appbase = file:///C:/develop/parent/out/debug-amd64/
  LOG: Initial PrivatePath = NULL
  LOG: Dynamic Base = NULL
  LOG: Cache Base = NULL
  LOG: AppName = Parent.exe
  Calling assembly : Child, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null.
  ===
  LOG: This bind starts in LoadFrom load context.
  WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
  LOG: Using application configuration file: C:\develop\parent\out\debug-amd64\Parent.exe.Config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
  LOG: Post-policy reference: System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  LOG: GAC Lookup was unsuccessful.
  LOG: Attempting download of new URL file:///C:/develop/parent/out/debug-amd64//System.Runtime.DLL.
  LOG: Attempting download of new URL file:///C:/develop/parent/out/debug-amd64//System.Runtime/System.Runtime.DLL.
  LOG: Attempting download of new URL file:///C:/develop/parent/out/debug-amd64//System.Runtime.EXE.
  LOG: Attempting download of new URL file:///C:/develop/parent/out/debug-amd64//System.Runtime/System.Runtime.EXE.
  LOG: Attempting download of new URL file:///C:/develop/child/out/debug-amd64/netcoreapp2.0/System.Runtime.DLL.
  LOG: Attempting download of new URL file:///C:/develop/child/out/debug-amd64/netcoreapp2.0/System.Runtime/System.Runtime.DLL.
  LOG: Attempting download of new URL file:///C:/develop/child/out/debug-amd64/netcoreapp2.0/System.Runtime.EXE.
  LOG: Attempting download of new URL file:///C:/develop/child/out/debug-amd64/netcoreapp2.0/System.Runtime/System.Runtime.EXE.
  LOG: All probing URLs attempted and failed.
  </code></pre>
  <p>From what I can tell, it's trying to load System.Runtime, which fails because parent app already has a different version of System.Runtime loaded.</p>
  <p>Is this even possible?</p>