Closed lihaochen910 closed 2 years ago
Can you please collapse your sample into something lighter? Is this the accurate equivalent:
var script = Path.Combine ( "/Users/Kanbaru/OneDrive/Documents/GameSolution/GameScriptLibrary", "main.csx" );
CSScript.EvaluatorConfig.Access = EvaluatorAccess.Singleton;
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
CSScript.EvaluatorConfig.ReferenceDomainAssemblies = true;
CSScript.GlobalSettings.AddSearchDir ( "/Users/Kanbaru/OneDrive/Documents/GameSolution/GameScriptLibrary" );
if ( File.Exists ( script ) )
try {
object scriptEntryComponent =
CSScript.Evaluator
.ReferenceAssembly ( Assembly.GetExecutingAssembly () )
.ReferenceAssembly ( Assembly.GetExecutingAssembly ().Location )
.ReferenceAssemblyOf ( this )
.ReferenceDomainAssemblies ()
.LoadCode< IGameComponent > ( File.ReadAllText ( script ), this, _services );
}
catch ( Exception e ) {
Console.WriteLine ( e );
}
If yes I can try to debug it on Linux. Sorry, I do not have Mac handy
The error itself is about an invalid path. Being an empty string is only one possible reason. The error message lists others too.
I'm sure the load path is correct. Because before I used Mono runtime, CS-Script 3.30 version was working fine. These problems only appeared because I switched to .Net SDK 6, Just now I get the same error when running on win11.
Not a problem. Will have a look. Is the code (I extracted) accurate?
BTW this code adds the same assembly 3 times:
.ReferenceAssembly ( Assembly.GetExecutingAssembly () )
.ReferenceAssembly ( Assembly.GetExecutingAssembly ().Location )
.ReferenceAssemblyOf ( this )
And .ReferenceDomainAssemblies ()
does it all anyway
Thank you for your reminder :)
BTW my main.csx file starts like this:
//css_engine dotnet
//css_co /unsafe
//css_co /d:TRACE /d:DEBUG
//css_reference netstandard.dll
//css_reference System.Xml.Linq.dll
//css_reference System.Numerics.dll
//css_reference System.Numerics.Vectors.dll
//css_reference ImGui.NET.dll
//css_reference DigitalRune.ImGui.Editor.dll
//css_include AppBootstrapper
//css_include TestComponent
css_engine: dotnet or csc got the same error when running
Tested, your scenario works OK on Linux. The sample is attached.
Let's now go through your code. I think there is a problem there that is caused by the leftovers from the Mono version.
//css_engine dotnet
does not do anything as it is a directive for CLI but not hosted script engine//css_reference netstandard.dll
//css_reference System.Xml.Linq.dll
//css_reference System.Numerics.dll
//css_reference System.Numerics.Vectors.dll
Not needed as all default assemblies will be referenced anyway.
I feel that there is something wrong with your imported scripts.
I suggest, if you still experience the problem, take the sample I gave you modify it a little to start exhibiting the problem and send me the sample back so I can debug it.
macOS 12.3.1 .net sdk 6.0.201 arm64 I tried the sample you gave
/Users/Kanbaru/Downloads/hosting/bin/Debug/net6.0/hosting
/Users/Kanbaru/Downloads/hosting/bin/Debug/net6.0
Unhandled exception. CSScriptLib.CompilerException: BUILD: error : Unknown compiler error
at CSScriptLib.CodeDomEvaluator.CompileAssemblyFromFileBatch_with_Csc(String[] fileNames, String[] ReferencedAssemblies, String outAssembly, Boolean IncludeDebugInformation, CompileInfo info)
at CSScriptLib.CodeDomEvaluator.Compile(String scriptText, String scriptFile, CompileInfo info)
at CSScriptLib.EvaluatorBase`1.CompileCode(String scriptText, String scriptFile, CompileInfo info)
at CSScriptLib.EvaluatorBase`1.CompileCode(String scriptText)
at CSScriptLib.EvaluatorBase`1.LoadCode[T](String scriptText, Object[] args)
at App.Main() in /Users/Kanbaru/Downloads/hosting/Program.cs:line 37
Process finished with exit code 134.
Running this sample with .net 6 sdk x86_64 on windows platform works fine.
C:\Users\Kanbaru\Downloads\hosting\bin\Debug\net6.0
YourPrinter is printing...
C:\Users\Kanbaru\Downloads\hosting\bin\Debug\net6.0\hosting.exe (进程 17188)已退出,代码为 0。
按任意键关闭此窗口. . .
Tested, your scenario works OK on Linux. The sample is attached.
Let's now go through your code. I think there is a problem there that is caused by the leftovers from the Mono version.
//css_engine dotnet
does not do anything as it is a directive for CLI but not hosted script engine//css_reference netstandard.dll
//css_reference System.Xml.Linq.dll
//css_reference System.Numerics.dll
//css_reference System.Numerics.Vectors.dll
Not needed as all default assemblies will be referenced anyway.I feel that there is something wrong with your imported scripts.
I suggest, if you still experience the problem, take the sample I gave you modify it a little to start exhibiting the problem and send me the sample back so I can debug it.
@oleg-shilo I found a bug about the CSScriptLib::CSharpParser.GetRawStatements method, using my test file main.csx, when parsing the css_include information of main.csx, the source file csparser.cs line 895 calls codeToanalyze.Substring(pos, endPos - pos).Trim() returned an incorrect value:
WorldRenderGameComponent\n\nusing System
This will cause subsequent compilation operations to fail.
Sample main.csx
Great. Thank you for such a detailed investigation report. Fixing it was just a matter of a few mins.
Done.
The fix is published as a HotFix release: https://www.nuget.org/packages/CS-Script/4.4.4-pre
Thank you for your quick fix. Good job!
cs-script 4.4.3 macOS 12.3.1 .net sdk 6.0.201 arm64
Output: