473,651 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Activator.Creat eInstance for new Array Element. Type Problem

Hi,

I got the following problem :

I have an defined an Array of different Actions:
public PRootActions[] AllActions = new PRootActions [10];

I got a dynamic method where all Actions or other things like
Materials are loaded from a Database to my Actions or Materials
Array:
public void All_Db2Cl (Object[] AllData, ref int totalData)

This method is called like this:
PMain.myPArray. All_Db2Cl (AllAction, ref
PMain.myPGlobal s.totalActions) ;

Inside this Method I call the Activator.Creat eInstance Method to
initialize the Array Element:
AllData = Ativator.Create Instance (null,
"PentaEngine.PR ootActions");

With this instruction I receive the following error message :

An unhandled exception of type 'System.ArrayTy peMismatchExcep tion'
occurred in PentaEngine.exe

Additional information: Attempted to store an element of the incorrect
type into the array.
Does anyone has an idea ?

Thank you very much
Frank

Nov 16 '05 #1
4 7654
Hi,
Inside this Method I call the Activator.Creat eInstance Method to
initialize the Array Element:
AllData = Ativator.Create Instance (null,
"PentaEngine.PR ootActions");

With this instruction I receive the following error message :

An unhandled exception of type 'System.ArrayTy peMismatchExcep tion'
occurred in PentaEngine.exe


Arrays must be created using System.Array.Cr eateInstance.

Bye
Rob
Nov 16 '05 #2
garak <fp*******@gm x-dot-de.no-spam.invalid> wrote:
I got the following problem :

I have an defined an Array of different Actions:
public PRootActions[] AllActions = new PRootActions [10];

I got a dynamic method where all Actions or other things like
Materials are loaded from a Database to my Actions or Materials
Array:
public void All_Db2Cl (Object[] AllData, ref int totalData)

This method is called like this:
PMain.myPArray. All_Db2Cl (AllAction, ref
PMain.myPGlobal s.totalActions) ;

Inside this Method I call the Activator.Creat eInstance Method to
initialize the Array Element:
AllData = Ativator.Create Instance (null,
"PentaEngine.PR ootActions");

With this instruction I receive the following error message :

An unhandled exception of type 'System.ArrayTy peMismatchExcep tion'
occurred in PentaEngine.exe

Additional information: Attempted to store an element of the incorrect
type into the array.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
OK Thanks,
but with Array.CreateIns tance I need to have a TYPE variable,
describing the desired type. I only have the typename as a STRING
variable.
Is there a way to get a TYPE variable with the typename ?

Nov 16 '05 #4
garak <fp*******@gm x-dot-de.no-spam.invalid> wrote:
OK Thanks,
but with Array.CreateIns tance I need to have a TYPE variable,
describing the desired type. I only have the typename as a STRING
variable.
Is there a way to get a TYPE variable with the typename ?


Type.GetType.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

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

Similar topics

18
3341
by: David Sworder | last post by:
Hi, I need to design a method that creates and returns a large array of objects. The problem is that the *type* of object to create isn't know until runtime. As a result, a parameter of type "Type" must be passed in: IMyInterface CreateObjects(Type type,int numberOfObjects); Internally this method will call Activator.CreateInstance() to create the objects. Here's my question: Is there a significant performance penalty
2
505
by: shmeian | last post by:
I have the following code which works fine. However I want to pass the object I'm instantiating a string for its constructor. I can't get the syntax right. Can someone give me an example of Activator.CreateInstance where they pass an argument with the object type? Assembly a = Assembly.GetExecutingAssembly(); Type type = a.GetType("MyAssemb.MyClass"); Object o = Activator.CreateInstance(type); MyClass myObj=...
4
6705
by: Terry | last post by:
I'm building some dll assemblies that have in them the implementation of an abstract class defined in a different assembly. I'm trying to create objects of the type defined in the dlls with "Activator.CreateInstance". Everything was working fine until I started to fill out the class def with some implementation. At some point the CreateInstance was failing with a "MissingMethodException - No parameterless constructor defined for this...
7
12023
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass a token into the instantiated class DBPassword and return a string; ************************************** namespace DBPasswordProvider public class DBPassword {
2
1867
by: Frank Pleyer via .NET 247 | last post by:
Hi, I got the following problem : I have an defined an Array of different Actions: public PRootActions AllActions = new PRootActions ; I got a dynamic method where all Actions or other things like Materials are loaded from a Database to my Actions or Materials Array: public void All_Db2Cl (Object AllData, ref int totalData)
1
15313
by: John Jenkins | last post by:
Hi, I have a fairly simeple question. What are the differences between Assembly.CreateInstance and System.Activator.CreateInstance? I had read that one maps to the other, however when I use Assembly.CreateInstance to create an object that implements an interface it cannot cast to the appropriate interface type before returning. e.g. ISubmit lo_MessagingObject=null; string
3
17063
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); //Iterate through the Assembly to find Class with a Public Interface.
0
1226
by: MichaelSL | last post by:
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...
2
3340
by: jcomber | last post by:
Hi, I'd be grateful for some help... I'm trying to create a late bound object using: Activator.CreateInstance(Type, ConstructorParameters()) The constructor of the object takes a delegate as the only parameter. However, ConstructorParameters() is an object array and because a
0
8275
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
8792
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
8694
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...
0
8571
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
7294
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...
1
6157
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
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
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.