G
Guest
Based on the documentation that I have found on this subject, I am trying to
use ‘Activator.CreateInstance(string, string)’ for a replacement for
CreateObject, but I don’t seem to be able to get it to work. Let me explain
what I am trying to do. The VB6 project that I am trying to convert has
hundreds of Objects all of which implement the same interface. The objects
differentiate themselves based on the ‘entity’ that they represent and an
effective date. So we have hundreds of entities which change ‘implementation
details’ 1 or more times every year. Instead of maintaining all of these
objects in a single project, I use a ‘catalog’ to fiond the right Object tol
hand back to the client. The catalogs are grouped by year and the logic
works something like this. Note that each of the catalog classes also
imnplement a single interface (ISelectObj).
..
..
..
mCatalog = GetCatalog(Year)
..
..
Private Function GetCatalog(Yr as integer) as ISelectObj
Dim CatName as string
CatName = “gpiCat†& Yr.ToString & “.gpiCatâ€
GetCatalog = CreateObject(CatName)
End Function
This works fine in VB6.
Under VB 2005 I created a gpiCat2006 project and compiled it. I copied the
contents of the Debug directory to a new folder (2006) I created in my test
applications Debug directory. And I try to load as follows.
Private Function GetCatalog(ByVal Yr As Integer) as ISelObj
Dim CatYr As String = Yr.ToString
Dim CatName As String = "gpiCat" & CatYr
Dim CatPath As String = My.Application.Info.DirectoryPath & "\" & CatYr &
"\" & CatName & ".dll"
Try
Return Activator.CreateInstance(CatPath, CatName).Unwrap
Catch ex As Exception
Throw New ArgumentException("Catalog for Requested Year not found.")
End Try
I get the following exception:
System.IO.FileLoadException = {"Could not load file or assembly
'D:\\TestProj\\gpiCatalog\\WindowsApplication1\\bin\\Debug\\2006\\gpiCat2006.dll'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047
The Actual path I use is: CatPath =
"D:\TestProj\gpiCatalog\WindowsApplication1\bin\Debug\2006\gpiCat2006.dll"
Why are the ‘\’ replaced with ‘\\’?
I tried an end around and recompiled the Cat2006 project as a com object and
registered it. I was then able to use the following line w/o error:
mCatalog = CreateObject("gpiCat2006.gpiCat2006")
What am I doing wrong?
One other thing. I would like to be able to get to the ‘’gpiCat2006.dll’
w/o having to have it installed in the path of the client application. How
would I go about that and how would I use the ‘CreateInstance’ method to get
to it?
Thanks in advance for any input.
use ‘Activator.CreateInstance(string, string)’ for a replacement for
CreateObject, but I don’t seem to be able to get it to work. Let me explain
what I am trying to do. The VB6 project that I am trying to convert has
hundreds of Objects all of which implement the same interface. The objects
differentiate themselves based on the ‘entity’ that they represent and an
effective date. So we have hundreds of entities which change ‘implementation
details’ 1 or more times every year. Instead of maintaining all of these
objects in a single project, I use a ‘catalog’ to fiond the right Object tol
hand back to the client. The catalogs are grouped by year and the logic
works something like this. Note that each of the catalog classes also
imnplement a single interface (ISelectObj).
..
..
..
mCatalog = GetCatalog(Year)
..
..
Private Function GetCatalog(Yr as integer) as ISelectObj
Dim CatName as string
CatName = “gpiCat†& Yr.ToString & “.gpiCatâ€
GetCatalog = CreateObject(CatName)
End Function
This works fine in VB6.
Under VB 2005 I created a gpiCat2006 project and compiled it. I copied the
contents of the Debug directory to a new folder (2006) I created in my test
applications Debug directory. And I try to load as follows.
Private Function GetCatalog(ByVal Yr As Integer) as ISelObj
Dim CatYr As String = Yr.ToString
Dim CatName As String = "gpiCat" & CatYr
Dim CatPath As String = My.Application.Info.DirectoryPath & "\" & CatYr &
"\" & CatName & ".dll"
Try
Return Activator.CreateInstance(CatPath, CatName).Unwrap
Catch ex As Exception
Throw New ArgumentException("Catalog for Requested Year not found.")
End Try
I get the following exception:
System.IO.FileLoadException = {"Could not load file or assembly
'D:\\TestProj\\gpiCatalog\\WindowsApplication1\\bin\\Debug\\2006\\gpiCat2006.dll'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047
The Actual path I use is: CatPath =
"D:\TestProj\gpiCatalog\WindowsApplication1\bin\Debug\2006\gpiCat2006.dll"
Why are the ‘\’ replaced with ‘\\’?
I tried an end around and recompiled the Cat2006 project as a com object and
registered it. I was then able to use the following line w/o error:
mCatalog = CreateObject("gpiCat2006.gpiCat2006")
What am I doing wrong?
One other thing. I would like to be able to get to the ‘’gpiCat2006.dll’
w/o having to have it installed in the path of the client application. How
would I go about that and how would I use the ‘CreateInstance’ method to get
to it?
Thanks in advance for any input.