473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with Activator.CreateInstance in C#

I am using CreateInstance to create an instance of a class and invoke
a function of that class. I really need it to execute in a single
line of code (long story, but I want to execute this code in the
command window on demand, without declaring any variables).

This code WORKS (but requires 2 lines of code and a variable
declaration):
Type typ = Type.GetTypeFromProgID("MyDLLx.clsMyClass");
Activator.CreateInstance(typ).mNoShow("Test");

This Code DOES NOT WORK:
Activator.CreateInstance((System.Type)Type.GetType FromProgID("MyDLLx.clsMyClass")))).mNoShow("Test") ;

The error, when executed from the command window is:
arguments do not match parameters for function ...

The error (compile), when coded in the application is:
\'object' does not contain a definition for 'mNoShow'

Any help is most appreciated.
Nov 16 '05 #1
3 12654
Type typ = Type.GetTypeFromProgID("MyDLLx.clsMyClass");
Activator.CreateInstance(typ).mNoShow("Test");

This Code DOES NOT WORK:
Activator.CreateInstance((System.Type)Type.GetType FromProgID("MyDLLx.clsMyClass")))).mNoShow("Test") ;

The error, when executed from the command window is:
arguments do not match parameters for function ...

The error (compile), when coded in the application is:
\'object' does not contain a definition for 'mNoShow'

Any help is most appreciated.


Are you sure these are verbatim lines? Neither one will work.(Although it
probably will in VB)


Nov 16 '05 #2
Doug,

Actually, neither line of code should work. The reason for this is that
the CreateInstance method returns an object. The only way I can see this
working is if it is in VB.

I would recheck the two lines you say that work, because they shouldn't.

Is it possible that the two lines are in a block that is swallowing the
exception?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Doug Riley" <dr****@platformdev.com> wrote in message
news:52*************************@posting.google.co m...
I am using CreateInstance to create an instance of a class and invoke
a function of that class. I really need it to execute in a single
line of code (long story, but I want to execute this code in the
command window on demand, without declaring any variables).

This code WORKS (but requires 2 lines of code and a variable
declaration):
Type typ = Type.GetTypeFromProgID("MyDLLx.clsMyClass");
Activator.CreateInstance(typ).mNoShow("Test");

This Code DOES NOT WORK:
Activator.CreateInstance((System.Type)Type.GetType FromProgID("MyDLLx.clsMyClass")))).mNoShow("Test") ;

The error, when executed from the command window is:
arguments do not match parameters for function ...

The error (compile), when coded in the application is:
\'object' does not contain a definition for 'mNoShow'

Any help is most appreciated.

Nov 16 '05 #3
If you remove the needless cast, and the two extra close parentheses, you
are left with:

Activator.CreateInstance(Type.GetTypeFromProgID("M yDLLx.clsMyClass")).mNoSho
w("Test");

Which compiles (except for the error Daniel & Nicholas pointed out)

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Doug Riley" <dr****@platformdev.com> wrote in message
news:52*************************@posting.google.co m...
I am using CreateInstance to create an instance of a class and invoke
a function of that class. I really need it to execute in a single
line of code (long story, but I want to execute this code in the
command window on demand, without declaring any variables).

This code WORKS (but requires 2 lines of code and a variable
declaration):
Type typ = Type.GetTypeFromProgID("MyDLLx.clsMyClass");
Activator.CreateInstance(typ).mNoShow("Test");

This Code DOES NOT WORK:
Activator.CreateInstance((System.Type)Type.GetType FromProgID("MyDLLx.clsMyCl
ass")))).mNoShow("Test");
The error, when executed from the command window is:
arguments do not match parameters for function ...

The error (compile), when coded in the application is:
\'object' does not contain a definition for 'mNoShow'

Any help is most appreciated.

Nov 16 '05 #4

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

Similar topics

2
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...
0
by: ka | last post by:
I'm implementing an IDesignerHost, for the CreateComponent method. The code below is quite standard. When loading a form, the CreateComponent works fine. However, when someone choose a control from...
4
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...
7
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...
4
by: Martin Maat | last post by:
Hi. I am using a COM component from managed code doing the following: Type type = Type.GetTypeFromCLSID(new Guid("B70FAAE6-4F85-480A-B1C5-DC9A6F175BFC"), serverMachineName, true); history =...
1
by: hazz | last post by:
this is a repost with a hopefully more clearly stated scenario and more concise questions at the end. given the following two classes, my intent is to use pass a token into the instantiated class...
1
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using...
0
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Found it. string name = Properties.Settings.Default.ClassName.ToString(); //"myproject.myclass, myassembly" format. //name = "ABC.MyClass, Assem" ; Type t = Type.GetType(name); Object obj...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.