oleg-shilo / cs-script.core

.NET Core port of CS-Script
MIT License
100 stars 18 forks source link

Error compiling CodeDom with .Net 5 #25

Open zubialevich opened 3 years ago

zubialevich commented 3 years ago

Hello!

I am trying CodeDom evaluator but randomly I am getting this error:


    CSScriptLib.CompilerException : D:\Users\user\AppData\Local\Temp\1\CSSCRIPT\8304.32641ef8-d66d-487b-9764-c3609e081ccb.tmp(0,0): error CS0006:  Metadata file 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\' could not be found

    Data:
      Errors: System.Collections.Generic.List`1[CSScripting.CodeDom.CompilerError]

  Stack Trace: 
    CodeDomEvaluator.CompileAssemblyFromFileBatch_with_Csc(String[] fileNames, String[] ReferencedAssemblies, String outAssembly, Boolean IncludeDebugInformation, CompileInfo info)
    CodeDomEvaluator.Compile(String scriptText, String scriptFile, CompileInfo info)
    EvaluatorBase`1.CompileCode(String scriptText, String scriptFile, CompileInfo info)
    EvaluatorBase`1.CompileCode(String scriptText)
    EvaluatorBase`1.LoadCode[T](String scriptText, Object[] args)```

For RoslynEvaluator and MonoEvaluator everything works without random exception.
I've checked content of `C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\` and it's not empty.

Can you point me to a right direction to check?
oleg-shilo commented 3 years ago

Not sure what is exactly happening but there is one suspicious detail in your description. MonoEvaluator is not available for all versions of CS-Script.Core and for the latest CS-Script (.NET5).

What version are you trying to use.

As a side note you should use CS-Script which has replaced now CS-Script.Core.

zubialevich commented 3 years ago

I am using CS-Script latest version on .net5 project.

I thought that in CS-Script Evaluator goes for MonoEvaluator, or it is not true anymore?

The only think I can think where I get Microsoft.AspNetCore.App is that one of nugget packages I use has this as dependency:


    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup> ```
oleg-shilo commented 3 years ago

When CS-Script was migrated to .NET Core (and .NET 5 is essentially .NET Core) I had to drop MonoEvaluator since .NET no longer supports Mono. Thus indeed it's not the case any more.

As for "CSScript.Evaluator" it points to the evaluator that is configured to be the evaluator of your choice:

CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;  

now CSScript.Evaluator is a CodeDomEvaluator

As for the random failures, can you please produce a "hello world" style test case that resamples your solution so I can run it repeatably and hopefully reproduce the problem.