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

Dynamically create instance of class

P: 6
I want to dynamically create instance of class stored in other application.
I am writing the following code for this purpose:

Here in the AssemblyFunc() I am loading the assembly of TariffClass application which is loaded successfully. In objectCreate() I am creating object of class present in TariffClass application. But I am getting the following error

'Could not load file or assembly 'file:///C:\Inetpub\wwwroot\QuickQuote\TariffClass, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'

Private Function objectCreate(ByVal Classnm As String) As Object
Dim objHandle2 As ObjectHandle
Dim objClient As Object
Dim clientType As String
Dim assemblyName As String

'-----Creating the runtime instances for client class---------
assemblyName = AssemblyFunc()
clientType = "TariffClass." + Classnm

objHandle2 = Activator.CreateInstanceFrom(assemblyName, clientType)
objClient = objHandle2.Unwrap
'-------instance created--------

Return objClient
End Function

Public Function AssemblyFunc() As String

'---------Creating Assembly to load the WebApplication6.dll----------
Dim assem As [Assembly]
assem = [Assembly].LoadFile("C:\Inetpub\wwwroot\QuickQuote\Classes\T ariffClass\bin\Release\TariffClass.dll")
Dim assemName As String
assemName = assem.ToString

Return assemName
End Function
Jul 26 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.