Script evaluation code snippet:
using (var loader = new InteractiveAssemblyLoader())
{
var script = CSharpScript.Create<TDataType>(
code: expr,
options: ScriptOptions.Default.AddImports(globals.GetType().Namespace)
.AddReferences(refAssemblies),
globalsType: globals.GetType(),
assemblyLoader: loader);
return script.RunAsync(globals).Result.ReturnValue;
}
The code-analysis assemblies and the globals-type assembly are loaded into the same Collectible AssemblyLoadContext... Also tried adding references/imports explicitly through the ScriptOptions but get the same following error:
Inner Exception 1: InvalidCastException: [A]TestLibrary.TestClass cannot be cast to [B]TestLibrary.TestClass. Type A originates from 'TestLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location '...\TestLibrary.dll'. Type B originates from 'TestLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location '...\TestLibrary.dll'.