Solved

System.Activator.CreateInstance

Posted on 2004-04-21
4
701 Views
Last Modified: 2008-02-01
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
Comment
Question by:crazyman
  • 3
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10880433
What version are you using (2002 or 2003)?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10880492
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
 
LVL 13

Author Comment

by:crazyman
ID: 10896865
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 10903854
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now