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

Expose compiled Assembly instance to user through CSharpScript Script instance #32200

Open
SamVanheer opened this Issue Jan 5, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@SamVanheer
Copy link

SamVanheer commented Jan 5, 2019

CSharpScript compiles to an assembly in memory. This assembly's System.Reflection.Assembly instance can be accessed by returning either the assembly or a type defined in it as a the return value from a script, but there is currently no way to access the instance directly through the Script class API.

This prevents using scripts as compiled-on-demand assemblies that can otherwise be treated as dynamically loaded assemblies, using Reflection to access its types.

Ideally the Script class should be extended with a GetCompiledAssembly() method that provides the instance, and either throws if it hasn't been compiled yet or compiles it just as RunAsync and related methods do.

From what i can tell the assembly is created here:

var assembly = _assemblyLoader.LoadAssemblyFromStream(peStream, pdbStreamOpt);

So making it accessible directly may require some refactoring first.

However, caching the generated assembly may result in reduced memory usage when the script is executed repeatedly. Since ContinueWith leaves the original script untouched there is no need to worry about outdated assemblies being returned.

The assembly should probably be returned by ScriptBuilder's CreateExecutor method and cached in Script.

A good reason to add this is to allow using CSharpScript assemblies with MEF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment