moonsharp icon indicating copy to clipboard operation
moonsharp copied to clipboard

UserData.RegisterAssembly() does not work in .Net Standard

Open xionglingfeng opened this issue 8 years ago • 6 comments

The library is targeted to .Net Standard 1.6 and running in .Net Framework 4.6.1 on Windows Server 2016. Calling UserData.RegisterAssembly() results

System.NotSupportedException: 'Assembly.GetCallingAssembly is not supported on target framework.'

xionglingfeng avatar Sep 30 '17 04:09 xionglingfeng

I'm having this problem in .NET Standard 2.0 too.

tonytins avatar Feb 04 '20 16:02 tonytins

Same in .NET 7

GoldenretriverYT avatar Jan 25 '23 10:01 GoldenretriverYT

I ran into this error today and i looked at the code inside of: https://github.com/moonsharp-devs/moonsharp/blob/master/src/MoonSharp.Interpreter/Loaders/EmbeddedResourcesScriptLoader.cs#L25

If you look it just checks the .NET version and throws an exception. I'm not sure if this is old code or not but Assembly.GetCallingAssembly is supported in .NET6,

To fix I just called it myself and passed it to the constructor and it worked just fine:

var script = new Script();
script.Options.ScriptLoader = new EmbeddedResourcesScriptLoader(Assembly.GetCallingAssembly());
var result = script.DoFile("Scripts/test.lua");
Console.WriteLine($"Result: {result.String}");

lua:

print('test')

VSCode console outputted test properly.

proudmane avatar Mar 10 '23 01:03 proudmane

@xanathar has the most commits on this repo so just pinging you as FYI I think this section of the code I linked above needs to be updated

proudmane avatar Mar 10 '23 01:03 proudmane

@GoldenretriverYT also see above

proudmane avatar Mar 10 '23 01:03 proudmane