RickStrahl/Westwind.Scripting

External references are not parsed when using CompileClass()

BrettJaner opened this issue · 5 comments

Hi Rick,

When using the CompileClass() methods on the CSharpScriptExecution, it doesn't look like external references are parsed. The function call to ParseReferencesInCode() is missing. Was this intentional or maybe just an oversight?

Thanks,
Brett

Yeah that's intentional. When you have a full class and do full class execution you can manually add the references. Only the various permutations of ExecuteMethod() parse references in code because that's the common scenario for running script code (ie. a block of code) and you need to be able to inject the references from script. When you compile class that tends to be much more low level and you likely have control over the entire compilation process including the ability to add references.

What is your use case? Scripting entire classes that are user provided?

Currently our application allows user provided scripts that are entire classes. We were exploring allowing the user to add external references (those that didn't exist at compile time of the app or aren't in the application bin/runtime directory). I was hoping your library would handle all of the assembly loading magic for these external references, but it doesn't seem to. I'm not sure the assembly loading journey is one I'd like to undertake either, so I might be stuck regardless if the CompileClass() function could parse references or not.

I put the code into CompileClass() so it will now parse references, but there is a problem in that the stream version of CompileClass(Stream codeStream) doesn't do the same as the reference parsing is done on string input. The stream is directly passed to the compiler - there's no pre-processing.

Updated in 1.3.3

Thanks for the update. I've tested the latest (v1.3.3) and it seems to be working well. I, also, no longer have the assembly probing issue I had seen before. If the external reference is in the bin directory everything now seems to work. I think we are good to close this issue.