AppDomain and Reflection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code that creates a new appDomain and loads an exe
using reflection. The problem I have is the exe file I pass in is still
locked by the application. I have showcopyfiles = "true" and specified the
locations for the appDomain to use. The shadowfiles and the original file is
locked when I execute the command tmpAssm = .Load(strApplicationName). Now
if I have shadowcopyfiles on, why would setting the assembly to the file
lock it? Any help is appreciated.

John

Private tmpDomain As AppDomain

Public Function LoadProgram(ByVal strApplicationName As String, ByVal
strApplicationEntryPoint As String) As Form

Dim tmpAppDomain As New AppDomainSetup

Dim tmpAssm As Assembly

Dim strName() As String

Dim strVersion As String

tmpAppDomain.ApplicationBase = "d:\wzprograms"

tmpAppDomain.ShadowCopyFiles = "true"

tmpAppDomain.ShadowCopyDirectories = "d:\wzprograms"

tmpAppDomain.PrivateBinPath = "d:\wzprograms"

'set the cache path for shadow files

tmpAppDomain.CachePath = "d:\wzprograms\tmp"

tmpDomain = AppDomain.CreateDomain("Temp", AppDomain.CurrentDomain.Evidence,
tmpAppDomain)

With tmpDomain

'.ExecuteAssembly("D:\wzprograms\versioncheck.exe")

tmpAssm = .Load(strApplicationName)

'.ExecuteAssembly(strApplicationName)

End With

'Get the version of the program

strName = Split(tmpAssm.FullName.ToString, ",")

strVersion = strName(1)

'set up the form to display by calling the Entry Point for the program.

LoadProgram = tmpAssm.CreateInstance(strApplicationEntryPoint, True)

Dim extType As Type = tmpAssm.GetType(strApplicationEntryPoint)

Dim extInfo As MethodInfo = extType.GetMethod("SetProperties")

If extInfo Is Nothing Then

MsgBox("This program cannot be run in the framework.", MsgBoxStyle.Critical,
"Invalid Framework Program")

Exit Function

End If

Dim myParamArray() As Object = {12345}

extInfo.Invoke(LoadProgram, myParamArray)

LoadProgram.Name = ("Test")

LoadProgram.Text = "VersionCheck. " & strVersion

AppDomain.Unload(tmpDomain)

End Function
 
John,
I have showcopyfiles = "true" and specified the
locations for the appDomain to use. The shadowfiles and the original file is
locked when I execute the command tmpAssm = .Load(strApplicationName). Now
if I have shadowcopyfiles on, why would setting the assembly to the file
lock it?

You have to execute the assembly and type loading code in the remote
appdomain. Right now the assembly is probably loaded into your current
appdomain as well.


Mattias
 
I figured as much. This is not an option to execute the code since I need to
host the assembly in my MDI application. I have found a work around that is
working quite well. Thanks.

John
 
Back
Top