Solved

System.Activator.CreateInstance

Posted on 2004-04-21
4
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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