CodeDom and ClickOnce not compatible?

M

Mark Evans

Hi Gurus

I have a windows application that is deployed via ClickOnce (No Touch
Deployment). It uses the CodeDom to create an assembly on the fly. The
problem is that this assembly can't find it's referenced assemblies
(IPSTypes.dll in the example below). It works fine when run locally
but fails when run using clickOnce. I was hoping that
"IO.Directory.GetCurrentDirectory()" would return the path to the
dependent assembly but it actually returns the path to the desktop!!
Any help gratefully appreciated.

Please send any replies to (e-mail address removed)



Imports System
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.Reflection

Module Module1

Sub Main()

Dim provider As Microsoft.VisualBasic.VBCodeProvider
Dim compiler As System.CodeDom.Compiler.ICodeCompiler
Dim params As System.CodeDom.Compiler.CompilerParameters
Dim results As System.CodeDom.Compiler.CompilerResults
Dim stbErrors As New System.Text.StringBuilder
Dim asmRule As System.Reflection.Assembly

' create simple test class as a string
Dim strFunction As String
strFunction = strFunction & " Namespace TestNamespace
" & vbCrLf
strFunction = strFunction & " Public Class TestClass
" & vbCrLf
strFunction = strFunction & " Public Function
TestFunction() As String " & vbCrLf
strFunction = strFunction & " Return ""blah""
" & vbCrLf
strFunction = strFunction & " End Function
" & vbCrLf
strFunction = strFunction & " End Class
" & vbCrLf
strFunction = strFunction & " End Namespace "


params = New System.CodeDom.Compiler.CompilerParameters
params.GenerateInMemory = True 'Assembly is created in
memory
params.GenerateExecutable = False
params.TreatWarningsAsErrors = False
params.WarningLevel = 4

Dim appDom As AppDomain = AppDomain.CreateDomain("RuleDomain")
Dim strDllPath As String = String.Format("{0}\IPSTypes.dll",
IO.Directory.GetCurrentDirectory())
params.ReferencedAssemblies.Add(strDllPath)

provider = New Microsoft.VisualBasic.VBCodeProvider
compiler = provider.CreateCompiler
results = compiler.CompileAssemblyFromSource(params,
strFunction)
asmRule = results.CompiledAssembly

End Sub

End Module
 
G

Guest

Hey Mark

If IPSTypes.dll is placed in the same directory as the assembly building the new assembly using the CodeDom, you can use AppDomain.BaseDirectory or Assembly.GetExecutingAssembly().Location

Regards, Jakob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top