C#C
C#2y ago
temp0

✅ Sharing executing Assembly in Roslyn script

Howdy, this could be a very specific use case, but if anyone has any insights here I would appreciate it:

I am hosting am embedded .net runtime in a c++ app using nethost.h and loading my assembly and getting fn pointers with load_assembly_and_get_function_pointer. It's invoking everything fine. In the function I'm calling on the .net side I am using Roslyn to run .csx scripts. In that .net lib I define an interface INpcEvent and in the .csx I create a class that implements that interface and returns a new instance. I want to be able to get a reference to that new instance via this code:

var scriptOptions = ScriptOptions.Default.WithReferences(Assembly.GetExecutingAssembly());
var state = await CSharpScript.RunAsync<GlobalType.INpcEvent>(text, scriptOptions, globals: global, globalsType: typeof(GlobalType));

And I get the error Exception thrown: 'System.ArgumentException' in System.Private.CoreLib.dll: 'Cannot bind to the target method because its signature is not compatible with that of the delegate type.'
  • seems to be that although they're the same types it's not the same assembly reference so it can't be cast as the return value. I see that Roslyn is loading that dll in runtime with the WithReferences option. Is there a way to use what I have defined in memory as the caller for types to sync those up?
Was this page helpful?