Using Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.Scripting in C#

Hi,
this is a very specific and technical question which I doubt is of any interest to anyone else, but I will try to ask the question…at the same time the question is fairly general without an example provided so I understand it is a Hail Mary shot in search of an answer.

So, I am trying to use Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.Scripting packages to do some runtime compiling…I provide a class with a function in the form of a string and it is supposed to compile the code and run it.

I first created a simple Console App to test it and it all works.

However, when I try it within the Rhino Plug-in it always stops and tells me it cannot load the dll:

Without getting too technical I am trying two approaches, one is the “lighter” Scripting version (with CSharpScript.RunAsync()) and another is actually compiling the Assembly (using CSharpCompilation):…

…but I cannot test or debug the solutions because in all scenarios the needed Dll cannot be loaded (in the assembly compiling version the Microsoft.CodeAnalysis.dll cannot be loaded, if I am not mistaken.)

So…my hope is that there is an easy answer like:

Rhinocommmon is already using an earlier version of this library and that is why it cannot load it…you need to install the previous version

The dll is actually there in the folder, right next to the rhino plugin so that is not a problem for sure…so my best guess is that there is some mismatch in the version…or some incompatibility with net 7.0 windows…not sure.

I would appreciate any ideas.
Thanks
Milos

Do you have all dependencies of this assembly as well? See here for a list of the dependencies, there’s 7 other packages that you need to be able to use the CodeAnalysis.Scripting assembly.

Thanks Menno,

but unfortunately it is not that…I installed all of the packages listed there and I am getting the exact same error.

Is Rhino using those libraries and if yes which versions? Copilot suggest that is the most likely problem…the fact that the simple Net 7.0 Console App worked but the same setup within a Rhino Plug-in didn’t, is also (for me) indicative of something like that.

Rhino Plugin on the left, Console app on the right:

Greetings,
Milos

You should try version 4.6.0.0 instead of 4.12.0.0.

1 Like