This project has moved and is read-only. For the latest updates, please go here.

Compiles JavaScript into .NET bytecode (CIL)

Sep 15, 2011 at 9:37 AM


I am still on that AjaxDoc stuff, can this outputs the result to a file as .NET assembly?

Best regards,

Sep 15, 2011 at 11:01 AM

There is no built-in support for saving to generated code to a DLL, sorry.

There is support for building a Assembly using Reflection.Emit, however.  Changes required to save a DLL include the following:

  • Set ScriptEngine.EnableDebugging to true.  This enables the Reflection.Emit code path.
  • Change the second parameter of DefineDynamicAssembly to AssemblyBuilderAccess.RunAndSave and add another parameter (the directory to save to) [MethodGenerator.cs line 233]
  • Call reflectionEmitInfo.AssemblyBuilder.Save(fileName) after the code has been generated [MethodGenerator.cs line 284]

Note that if you do this the DLL will have a hard dependency on Jurassic.dll (i.e. Jurassic.dll must be in the same directory for it to work).

I'm not sure how this helps you with extracting documentation however, since the generated assembly bears no resemblence to the original javascript source code.


Sep 15, 2011 at 11:07 AM

Thanks so much for the quick and useful response. I will try it.

Sandcastle documentation requires two components; reflection file and comment file.
Trying to see if the assembly emitted by your library could be used for the reflection file.

Best regards,

Nov 8, 2011 at 10:47 PM

I am not able to save generated code to file this way - the generated assembly is empty. Can you help me?

Nov 8, 2011 at 11:57 PM

Ah, you're right - I missed a step.  You also need to specify the filename when defining the module (using DefineDynamicModule).


Nov 9, 2011 at 9:05 AM

Thank you. Now AssemblyBuilder.Save throws a NotSupportedException ("TypeBuilder.CreateType has not been called for any of the types in the modules of the assembly to be written to disk"). I really don't understand your code, but the CreateType method is called on line 281. Do you have an idea how to fix that?

Nov 10, 2011 at 10:20 AM

Hmm, that should work.  If you debug it, is CreateType() called before AssemblyBuilder.Save()?

Nov 10, 2011 at 10:24 AM

Yes, it is called before AssemblyBuilder.Save(). Please, if you have some time, try to create working example or add built-in support for saving generated code to an assembly.