CS-Script 3.20.0

Dynamic script-assembly loading 

Every time the script is executed it is always compiled into an assembly and after that the assembly is loaded to a particular AppDomain for further execution. Once assembly is loaded it cannot be unloaded any more. This is the limitation of CLR, which is important to remember when hosting the script engine.

In fact the script engine itself has to handle this problem as well (e.g. when executing the script from command prompt) . It does this by relying on the fact that it is possible to unload the entire AppDomain with all loaded assembles.

The script-assembly (compiled script) is never loaded into current AppDomain. Instead, the new temporary AppDomain is created and the assembly is loaded into it. After execution the temporary AppDomain is unloaded. Thus, it is possible for the script engine to clear (delete) the script assembly when not needed (which otherwise would be locked until the script process is completed).  The only exclusion from this rule is when the script is executed with /c switch or CleanupShellCommand in configuration is set. In this case script-assembly is loaded into current AppDomain because there is no need to do any cleanup.

AsmHelper class, which assists with assembly loading and browsing, supports two assembly loading modes:

The tutorial Text Processor shows how to use both Local and Remote script-assembly loading techniques.


See Also

ReferenceTutorial (Text Processor)