Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while compiling related to environment block #47

Closed
zerodevelop opened this issue Mar 3, 2017 · 4 comments
Closed

Error while compiling related to environment block #47

zerodevelop opened this issue Mar 3, 2017 · 4 comments

Comments

@zerodevelop
Copy link

Hi Oleg,

I've realized a system that uses several db stored script to respond to events.
At the moment I have thirty different script that can be launched from a windows service.
Recently I'm having issues when the service tries to compile a script.
Once I got the exception on the first script, that can be a random one, all other script compilations fail with the same error.
If I then restart the service, for a while the script won't compile becausa they can't find the host service assemblies that are located in the bin.

I think the problem is related to the environment variabled added by csscript.
Can you give some advice about how to avoid this problem?

The error is:
System.InvalidOperationException: The environment block used to start a process cannot be longer than 65535 bytes. Your environment block is 65633 bytes long. Remove some environment variables and try again. at System.Diagnostics.EnvironmentBlock.ToByteArray(StringDictionary sd, Boolean unicode) at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) at System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) at Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs) at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames) at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) at csscript.CSExecutor.CompileAssembly(ICodeCompiler compiler, CompilerParameters compilerParams, String[] filesToCompile) at csscript.CSExecutor.Compile(String scriptFileName) at csscript.CSExecutor.Compile(String scriptFile, String assemblyFile, Boolean debugBuild) at CSScriptLibrary.CSScript.LoadWithConfig(String scriptFile, String assemblyFile, Boolean debugBuild, Settings scriptSettings, String compilerOptions, String[] refAssemblies) at CSScriptLibrary.CSScript.LoadCode(String scriptText, String tempFileExtension, String assemblyFile, Boolean debugBuild, String[] refAssemblies) at CSScriptLibrary.CodeDomEvaluator.CompileCode(String scriptText) at CSScriptLibrary.CodeDomEvaluator.LoadCode[T](String scriptText, Object[] args)

oleg-shilo added a commit that referenced this issue Mar 5, 2017
* Issue #47: Error while compiling related to environment block
* Added CSScript.EnableScriptLocationReflection
* Added CSScript.IgnoreSystemWideConfig()
* Disabled "dbg.print" triggered injection of System.Linq/Core on Linux
* Disabled dbg.cs inclusion if dbg.print is disabled
* Adding extra referenced namespaces when `CSScript.GlobalSettings.EnableDbgPrint == true` is made 'runtime version aware' to avoid adding System.Linq for .NET 3.5. (System.Linq.dll exists only on .NET 4.0+)
* Fixed problem with propagating `CSScript.GlobalSettings.EnableDbgPrint` for hosted execution
@oleg-shilo
Copy link
Owner

oleg-shilo commented Mar 5, 2017

Indeed the error it related to CS-Script preserving the locations of the original scripts via environment variables. While this being a useful technique it can lead to the situations like yours. Thus it is a defect.

You can disable this feature in the very latest release (v3.24.2) via dedicated config variable:

CSScript.EnableScriptLocationReflection = false;

@oleg-shilo oleg-shilo added the done label Mar 6, 2017
@zerodevelop
Copy link
Author

Thank you Oleg!
I'll update my Nuget package and let you know if all work fine.

@zerodevelop
Copy link
Author

I've been monitoring the service in these days and the issue no longer shows up.
Thank you again.

@oleg-shilo
Copy link
Owner

Cool, thank you for reporting. Without your feedback I would never guess that there is a limit on how many environment variables a process can have. :)

oleg-shilo added a commit that referenced this issue Mar 21, 2017
* Added support for C# 7.
* Added setting `LastCompilingResult` even when compiling script has failed.
* Issue #47: Error while compiling related to environment block
* Added CSScript.IgnoreSystemWideConfig()
* Disabled "dbg.print" triggered injection of System.Linq/Core on Linux
* Disabled dbg.cs inclusion if dbg.print is disabled
* Fixed problem with propagating `CSScript.GlobalSettings.EnableDbgPrint` for hosted execution
* Adding extra referenced namespaces when `CSScript.GlobalSettings.EnableDbgPrint == true` is made runtime version aware to avoid adding System.Linq for .NET 3.5. (System.Linq.dll exists only on .NET 4.0+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants