473,467 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why does this class instantiation using Activator fail?

When I build an executable which uses System.Activator.CreateInstance and
execute it on my PC, which has Microsoft Visual Studio installed, the
CreateInstance works just fine and the class constructor is called. But when
I move this executable to another PC (even one with Microsoft Visual Studio)
the execution proceeds all the way to the CreateInstance statement but hangs
there with the constructor never executing.

Any ideas? Is there another way I could do this that might work on the other
PCs.

I do know that once I know the name of the class I can use either an if/else
if construct to have a specific statement for each possible class. I would
rather not do this because I am continually creating new classes and would
have to modify the 'if' each time I added a new class.

A snipit of my code follows:

I set up a global variable:
string DesiredString;

I set up an array of a struct:

struct structProcessClass
{
public string Name;
public Type Class;
}

I fill the array:
structProcessClass tempProcessClass;
Type[] MyTypes = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type thisType in MyTypes)
{
if (thisType.BaseType.ToString() == "ProcessTrackData.ProcessingClass")
{
tempProcessClass.Class = thisType;
tempProcessClass.Name = tempStringOut;
ProcessClasses.Add (tempProcessClass);
}
}

I determine which class I want and instantiate it:
DesiredString = cmbProcessingType.Text;
foreach (structProcessClass thisClass in ProcessClasses)
{
if (thisClass.Name == DesiredString)
{
object[] args = new object[4]{DBFFile, NumberOfRecords, fsr, sw};
DesiredClass =
(ProcessingClass)System.Activator.CreateInstance(t hisClass.Class, args);
break;
}
}

Nov 17 '05 #1
0 1212

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mandar | last post by:
How do i instantiate a class if I get the name of the class at runtime ? I am looking for something like class.forname("classABC") in Java . TIA Mandar
27
by: djake | last post by:
In the stroustrup C++ programming language (third edition) i can find example like this: string s1= "Hello"; So I imagine string is a standard class. Furthermore the class in the example is...
9
by: Jon Rea | last post by:
I hav been looking for the last 2 hours on how to do this without much luck. Im going to give a simplifed model of the problem i have. I want a collection class that can holds a series or...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
4
by: web1110 | last post by:
I have a situation where I have a central control process for maintaining objects. Rather than instantiate an object and pass it to the controler object, I would like to pass the class...
3
by: Jeff Carver | last post by:
I'm creating a class (using VB.NET) that must read data from a database table during instantiation. If the data cannot be read (connection problem, etc.), I want the instantiation to fail such...
4
by: Andres | last post by:
Hi all, I have the problem to assign a variable of type object to a specific class at runtime. I want to use a string variable that specify the class a want to set this object. Is something...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
1
by: learning | last post by:
Hi how can I instaltiate a class and call its method. the class has non default constructor. all examples i see only with class of defatul constructor. I am trying to pull the unit test out from...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.