ICodeCompiler and CompileAssemblyFromSource

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Good morning,

I am trying to compile a DLL on the fly using ICodeCompiler. While I am
able to accomplish the task if I use a seperate code file along with
CompileAssemblyFromFile, however, when I try to embed the source code and
use CompileAssemblyFromSource, the DLL does not get created. Does anyone
have any ideas what might be causing this? BTW, no exceptions are being
thrown, it just doesn't create the DLL.

Below please find the source code:

Public Shared Sub createTest()
Dim sb As New System.Text.StringBuilder
Dim provider As Microsoft.VisualBasic.VBCodeProvider
Dim compiler As System.CodeDom.Compiler.ICodeCompiler
Dim cp As System.CodeDom.Compiler.CompilerParameters
Dim results As System.CodeDom.Compiler.CompilerResults

With sb
.Append("Namespace test")
.Append(vbCrLf)
.Append(" Public Class tSource")
.Append(vbCrLf)
.Append(" End Class")
.Append(vbCrLf)
.Append("End Namespace")
End With
cp = New System.CodeDom.Compiler.CompilerParameters
cp.ReferencedAssemblies.Add("System.dll")
cp.GenerateExecutable = False
cp.GenerateInMemory = False
cp.OutputAssembly = "D:\learnNET\bin\test.dll"

Try
provider = New Microsoft.VisualBasic.VBCodeProvider
compiler = provider.CreateCompiler
results = compiler.CompileAssemblyFromSource(cp,
sb.ToString)
sStatus = "test.dll created successfully"
Catch ex As Exception
sStatus = ex.Message
End Try
End Sub
 
the vb.net and c# compilers don't support this method only the
javascript.net compiler does.

-- bruce (sqlwork.com)
 
Thank you for the reply.

Apparently VB.NET does support it. The reason it wasnt working was due to a
compilation error that was being collected by the Errors collection rather
than throwing an exception. The error was a syntax error.

Eric
 
Back
Top