By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

Help please: CreateInstanceFromAndUnwrap

P: n/a
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?
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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==?=" <an*******@discussions.microsoft.com>
| >Subject: Help please: CreateInstanceFromAndUnwrap
| >Date: Mon, 27 Oct 2003 04:16:05 -0800
| >Lines: 25
| >Message-ID: <DA**********************************@microsoft.co m>
| >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!cpmsftng xa10.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?
| >
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.