Solved

System.Activator.CreateInstance

Posted on 2004-04-21
4
708 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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