oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.56k stars 234 forks source link

Assembly not found exception #365

Closed Alpini1980 closed 4 months ago

Alpini1980 commented 5 months ago

Hi,

I installed Version 4.8.14 via NuGet in Visual Studio Community 2022 but the CSScript.Evaluator.LoadCode<>() immediately throws an exception:

System.IO.FileNotFoundException: "Die Datei oder Assembly "System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden."

Sorry for German language exception it can be translated as "file or assembly or one of it's dependencies not found exception".

As a dependency the System.Runtime.Loader 4.3.0 was installed as NuGet package.


If I switch to CS-Script Version 3.30.5.1 with the System.Runtime.Loader 4.0.0 I get an other exception in the same line as above:

System.MissingMethodException: "Der Konstruktor für den Typ "Microsoft.CodeAnalysis.EmbeddedAttribute" wurde nicht gefunden."

This one is a "constructor not found exception".

I would be very grateful for any advises.

Regards, Stefan

oleg-shilo commented 5 months ago

I have just created the project as you described. Seems to work (see attached sample): image

ConsoleApp8.zip

Alpini1980 commented 5 months ago

Hi,

I found the problem. I did not read that .net 5.0 is required at least and installed it in a .net Framework 4.8 project . So this issue can be closed. Next try when we upgraded our project to .net 5.0 but at moment my team members won't do it.

Should the CS-Script.bin 3.30.5.1 work on .net Framework 4.8? It tried it too but also got a dependency not found exception for Microsoft.CodeAnalysis.Scripting.dll

Regards, Stefan

oleg-shilo commented 4 months ago

These two sample projects show how to use (though with some limitations) CS-Script .NET Core build on .NET FX host: image

You can also try a deprecated .NET FX stream ob .NET FX: https://github.com/oleg-shilo/cs-script.net-framework/releases/tag/v3.30.7.0.

Since MS abandoned .NET FX, I have stopped evolving CS-Script targeting this runtime. So that stream is about 2 years behind in terms of functionality with some minor updates done a few months ago.

While it is still fully functional, it is effectively out of support. Thus your best bet is to have a roadmap for the .NET Core transition.

Alpini1980 commented 4 months ago

Hello Oleg,

thank you - that sounds very interesting and I would like to give it a try. Where do I find the .net Framework sample projects? If it was the link behind your screenshot - it leads to a 404 Error. I tried to find the samples in the old https://github.com/oleg-shilo/cs-script.net-framework repo without luck.

And of course I fully understand that you don't want to waste your energy into developing the old version any longer.

oleg-shilo commented 4 months ago

It's OK, you just clone the code and samples are part of the codebase. You just change startup project and then you can run/debug it as any other VS proj.

In FX repo you will need to look at the tests (these 3 files). Wiki samples are also quite descriptive: image

Alpini1980 commented 4 months ago

Hello Oleg,

thank you very much for your support. I got it working (also in my own Framework project).

Regards, Stefan