473,775 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this class instantiation using Activator fail?

When I build an executable which uses System.Activato r.CreateInstanc e 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 structProcessCl ass
{
public string Name;
public Type Class;
}

I fill the array:
structProcessCl ass tempProcessClas s;
Type[] MyTypes = Assembly.GetExe cutingAssembly( ).GetTypes();
foreach (Type thisType in MyTypes)
{
if (thisType.BaseT ype.ToString() == "ProcessTrackDa ta.ProcessingCl ass")
{
tempProcessClas s.Class = thisType;
tempProcessClas s.Name = tempStringOut;
ProcessClasses. Add (tempProcessCla ss);
}
}

I determine which class I want and instantiate it:
DesiredString = cmbProcessingTy pe.Text;
foreach (structProcessC lass thisClass in ProcessClasses)
{
if (thisClass.Name == DesiredString)
{
object[] args = new object[4]{DBFFile, NumberOfRecords , fsr, sw};
DesiredClass =
(ProcessingClas s)System.Activa tor.CreateInsta nce(thisClass.C lass, args);
break;
}
}

Nov 17 '05 #1
0 1231

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

Similar topics

1
289
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
2442
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 initialized with a constructor like this
9
1455
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 objects, for arguments sake, lets make these fruit : apple orange bannana
4
3118
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 it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
4
1127
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 (unistantiated) to the controller and let the controller do the instantiation. Is this possible? To clarify with pseudo code This is fine:
3
1720
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 that the following "If" statement will evaluate to True: Dim objGribble as New cGribble() If objGribble Is Nothing Then ... What code in the class's constructor (Sub New) would make that happen?
4
4244
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 similar to add a new control to a form using the controls collection: Private Sub CommandCreateInstance_Click()
18
1982
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 instance of it. So how can a class be threadsafe by itself but an instance of it not be? I guess I don't get what exactly being threadsafe means. Multiple theads can use the same instance of a class?
1
2837
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 the product source code, but still want to execute them under nunit. I am trying this idea on nunit sample source code. Here is my class and the experiemental code: both money.cs and Imoney.cs is compiled to cs_money.dll. then I create another...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10046
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9915
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5358
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4014
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 we have to send another system

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.