Help please: CreateInstanceFromAndUnwrap

G

Guest

I am trying to create and instantiate a class into a created domain, so that I can unload the domain and replace the class (assembly .dll) while the main application is running, but I can't get it to work for some reason.

Here is the code:

' Create an appdomain
Try
Dim setup As AppDomainSetup = New AppDomainSetup
setup.ApplicationBase = "C:\test"
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory
setup.ApplicationName = "MyDomain"
appd = AppDomain.CreateDomain("Domain", Nothing, setup)
Catch ex As Exception
MsgBox("Can't create domain: " & ex.Message)
End Try

' Loads an class into the newly created appdomain
Try
Dim test As Object = appd.CreateInstanceFromAndUnwrap("CAP Fast.dll", "CAPfast")
Catch ex As Exception
MsgBox("Can't initiate the class: " & ex.Message)
End Try

Creating the domain works, and the CreateInstanceFromAndUnwrap method finds the DLL, but it can't find the class according to the error message. I don't have any explicit namespace, and the class is called CAPfast, with the correct case. The class also have a public constructor without any arguments.

Anyone have any idea why this isn't working?
 
G

Grayson Myers [MSFT]

Can you include the text of the exception you are seeing?

One possibility is that a dependency required by the CAPfast class is missing, so the type cannot be loaded. If this is the
case, using the Fuslogvw.exe tool might help you figure out what's going wrong. If you're not familiar with this tool, it's part of
the .NET framework SDK. Launch fuslogvw.exe, check the "Log Failures" box, and run your code again. After it fails, go
back to fuslogvw.exe and click the Refresh button. If the problem is a missing dependency, you should see a log entry
describing the failure. Double click on the application name in the left-hand column to bring up a page with more details.

Thanks,
Grayson
--------------------
| >Thread-Topic: Help please: CreateInstanceFromAndUnwrap
| >thread-index: AcOchBg9QHfFmPGCSs+RDYErJBHKUw==
| >X-Tomcat-NG: microsoft.public.dotnet.general
| >From: "=?Utf-8?B?TGlsbGVTa3V0dA==?=" <[email protected]>
| >Subject: Help please: CreateInstanceFromAndUnwrap
| >Date: Mon, 27 Oct 2003 04:16:05 -0800
| >Lines: 25
| >Message-ID: <[email protected]>
| >MIME-Version: 1.0
| >Content-Type: text/plain;
| > charset="Utf-8"
| >Content-Transfer-Encoding: 7bit
| >X-Newsreader: Microsoft CDO for Windows 2000
| >Content-Class: urn:content-classes:message
| >Importance: normal
| >Priority: normal
| >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| >Newsgroups: microsoft.public.dotnet.general
| >NNTP-Posting-Host: TK2MSFTCMTY1 10.40.1.180
| >Path: cpmsftngxa06.phx.gbl!cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl
| >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:113310
| >X-Tomcat-NG: microsoft.public.dotnet.general
| >
| >I am trying to create and instantiate a class into a created domain, so that I can unload the domain and replace the class
(assembly .dll) while the main application is running, but I can't get it to work for some reason.



Here is the code:



' Create an appdomain

Try

Dim setup As AppDomainSetup = New AppDomainSetup

setup.ApplicationBase = "C:\test"

setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory

setup.ApplicationName = "MyDomain"

appd = AppDomain.CreateDomain("Domain", Nothing, setup)

Catch ex As Exception

MsgBox("Can't create domain: " & ex.Message)

End Try



' Loads an class into the newly created appdomain

Try

Dim test As Object = appd.CreateInstanceFromAndUnwrap("CAP Fast.dll", "CAPfast")

Catch ex As Exception

MsgBox("Can't initiate the class: " & ex.Message)

End Try



Creating the domain works, and the CreateInstanceFromAndUnwrap method finds the DLL, but it can't find the class
according to the error message. I don't have any explicit namespace, and the class is called CAPfast, with the correct
case. The class also have a public constructor without any arguments.



Anyone have any idea why this isn't working?
| >
 

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