Export (0) Print
Expand All

IVsaEngine.Compile Method

Causes the script engine to compile the existing source state.

public bool Compile();

Returns TRUE on successful compilation, indicating that the IVsaEngine.Run method can be called on the newly compiled assembly. Returns FALSE if the compilation failed.

Once the Compile method has been called successfully, the script engine can be placed into the running state by calling the IVsaEngine.Run method; alternatively, the compiled form of the script engine can be saved with the IVsaEngine.SaveCompiledState method.

The Compile method returns true to signify that the IVsaEngine.Run method can be called successfully, that is, to signify that the script engine created an assembly that can be run. The Compile method may return true even if one or more compiler errors were reported from the IVsaSite.OnCompilerError method, as some script engines can recover from these compiler errors. If the Compile method returns false, the compilation failed completely and the IVsaEngine.Run method cannot be called.

Compilation errors are reported to the host by means of the IVsaSite.OnCompilerError method, using the IVsaSite reference stored in the IVsaEngine.Site property. When a compiler error occurs, the site will be notified and it will either continue compilation by returning true from the IVsaSite.OnCompilerError method, or stop further compilation by returning false. If the Compile method returns false, the compilation failed completely and the Run method cannot be called.

In addition to actual compilation errors in the source code, the Compile method may fail for other reasons, such as if the script engine is currently running code. You can determine the current state of the script engine using the IVsaEngine.IsRunning property.

The Compile method disposes of existing compiled state prior to compiling a new version of the script engine. Therefore, if compilation fails, the old compiled state will no longer be available. This behavior differs from most command-line compilers, which only overwrite an existing assembly if compilation is successful.

The following table shows the exceptions that the Compile method can throw.

Exception Type

Condition

EngineClosed

The IVsaEngine.Close method has been called and the engine is closed.

EngineBusy

The engine is currently executing code for another thread.

EngineEmpty

There are no code items to compile.

EngineRunning

The engine is currently running.

EngineNotInitialized

The engine has not been initialized.

RootNamespaceNotSet

The IVsaEngine.RootNamespace property has not been set.

AssemblyExpected

One of the IVsaReferenceItem objects is not a valid assembly.

GlobalInstanceTypeInvalid

The typeString parameter of an IVsaGlobalItem object is not valid.

EventSourceTypeInvalid

The eventSourceTypeString parameter of an event source is not valid.

InternalCompilerError

There was an internal compiler error. Check System.Exception.InnerException for more information.

Community Additions

Show:
© 2014 Microsoft