How to let CompileAssemblyFromSource() refer to user defined types in calling program

194 views Asked by At

I'm successfully using dynamically compiled assemblies to evaluate user definable expressions at run time. My question is about how to pass references to the types defined in my own program into the CompileAssemblyFromSource() function. Currently I'm forced to use 'object' in my user definable expressions, which causes late binding. As soon as I try to use my own types in the assembly code, I get 'Error BC30002 - Type 'cMyClass' is not defined'

I found the following to add to the parameters which sounds exactly right:

Dim executingAssembly As Assembly
Dim executingAssemblyName As String
executingAssembly = Assembly.GetExecutingAssembly()
executingAssemblyName = executingAssembly.Location
params.ReferencedAssemblies.Add(executingAssemblyName)

But this doesn't seem to help at all...

Here is a sample function I'm trying to compile unsuccessfully:

Public Class Sample
Public Shared Function StaticFunction(ByVal myObject As cMyClass) As String
Return myObject.DoSomething
End Function
End Class

If I replace 'cMyClass' with 'object' all is well.

0

There are 0 answers