• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 715
  • Last Modified:

System.Activator.CreateInstance

I am trying to create an object that implements a standard interface.
I am using the following method

    Function CreateComponentInstance(ByVal strAssembly As String, ByVal strType As String) As FTServiceInterface.IFTGenericService
        Return System.Activator.CreateInstance(System.IO.Path.GetFileNameWithoutExtension(strAssembly), strType).Unwrap
    End Function


I am always getting the following error

File or assembly name Test, or one of its dependencies, was not found.

But the file is definatley there!

I am calling using

dim objTest as FTServiceInterface.IFTGenericService
objtest = CreateComponentInstance("D:\DotNetCode\Generic Service\Test\bin\Test.dll","Test.Class1")

What could i be doing wrong?
0
crazyman
Asked:
crazyman
  • 3
1 Solution
 
Bob LearnedCommented:
What version are you using (2002 or 2003)?

Bob
0
 
Bob LearnedCommented:
Actually, you need to run ILDASM, open the assembly Test.dll, and double-click on the M A N I F E S T entry at the top.  When you look at it, it shows entries like:

.assembly extern mscorlib
.assembly extern System
.assembly extern System.Windows.Forms
...

These are the external references to assemblies that the program needs to locate in order to run.  

Bob
0
 
crazymanAuthor Commented:
This seems to work passing the full file name...


Function CreateComponentInstance(ByVal strAssembly As String, ByVal strType As String) As FTServiceInterface.IFTGenericService
        Return System.Activator.CreateInstanceFrom((strAssembly), strType).Unwrap
    End Function
0
 
Bob LearnedCommented:
Good point.   Full path names are best.  The assembly just needs to be in a place that can be located.  It is usually in the same directory as the executing assembly.  For ASP.NET, it is usually in the Bin directory for the web site.

Bob
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now