473,763 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection Issues

Hello,

I"m trying to invoke a method using reflection on a DLL that is already
within a project. However, I"m having a few problems and didn't know if
anyone has any bright ideas. Please note, I've had lots of success with
Reflection in the past, so I'm familiar with Reflection a little bit.

I have assembly X and Method Y I want to call. This assembly and related
classes and assemblies are very complex to invoke, requiring database
connections, complex constructors, etc. Method Y, however, is a property. It
will return a simple string value, no parameters needed.

My problem is trying to activate the method. On the final line of code
below, I get an error.

Type type = assembly.GetTyp e("MainObj");
MethodInfo info = type.GetMethod( "GetOperatingSy stemVersion");
Object activator = Activator.Creat eInstance(type) ;
object x = info.Invoke(act ivator, null);

The error is an "Argument Null Exception". Any advice on trying to track
this down? Ironically, this Assembly is already referenced in the project
and I am only using Reflection because I need to programmaticall y determine
which method to call. If I put the MainObj.GetOper atingSystemVers ion() in my
code, I get an appropriate reply. Any advice on debugging this? Or using the
Assembly already referenced by my program?

-J
Jun 19 '06 #1
2 1628
"Jason" <Ja*********@ec lipsys.com> wrote:
My problem is trying to activate the method. On the final line of code
below, I get an error.

Type type = assembly.GetTyp e("MainObj");
MethodInfo info = type.GetMethod( "GetOperatingSy stemVersion");
Object activator = Activator.Creat eInstance(type) ;
object x = info.Invoke(act ivator, null);

The error is an "Argument Null Exception". Any advice on trying to track
this down?


Can you reproduce it with your own class, a minimal one that looks like
MainObj? What does MainObj look like?

-- Barry

--
http://barrkel.blogspot.com/
Jun 19 '06 #2
I've figured out what the issue was...

The class in question was static, and the activator wasn't required. I
simply made activator "null" and things work great.

Thanks for your help in getting back to me.

-J


"Barry Kelly" <ba***********@ gmail.com> wrote in message
news:eh******** *************** *********@4ax.c om...
"Jason" <Ja*********@ec lipsys.com> wrote:
My problem is trying to activate the method. On the final line of code
below, I get an error.

Type type = assembly.GetTyp e("MainObj");
MethodInfo info = type.GetMethod( "GetOperatingSy stemVersion");
Object activator = Activator.Creat eInstance(type) ;
object x = info.Invoke(act ivator, null);

The error is an "Argument Null Exception". Any advice on trying to track
this down?


Can you reproduce it with your own class, a minimal one that looks like
MainObj? What does MainObj look like?

-- Barry

--
http://barrkel.blogspot.com/

Jun 19 '06 #3

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

Similar topics

3
10926
by: Ken Durden | last post by:
Hey, I posted this a few months ago and got completely off-the-chart responses. At the time I wasn't using reflection very much, but more and more I find myself wanting to use it to write flexible implementations of IComparable or Min/Max based only on FieldInfos or PropertyInfos, but I still find the fact that I have to hardcore a string with the field / property name unbearable. I re-read my post and it still seems intelligeble to...
4
3213
by: Picho | last post by:
Hi all, Using reflection, I can invoke/call private methods of an object. is this intended? if yes, why? in what scenario (example would be good) should I be givven the option to use something that was declared private (not public) and not mine to use? seems to me this is somewhat malicious... if not.... well....
1
1478
by: Chad Dollins | last post by:
I've got everything going nearly except one line of code. I think I'm in over my head here so, I'm going to ask for some help. Basically what the preposal is that you will be able to open a folder browse dialogue with a root other than those specified in Environment::SpecialFolders::. and I'm hoping that I would be able to specify network as the root and the defaultpath as the usersdomain much like it is done on mstsc.exe (RDT) Only...
6
2804
by: Andrew Robinson | last post by:
assuming that I have a class public class MyClass { public string FirstName { get {...} set {...} } } how can I assign the FirstName property using reflection on a generic class
4
2195
by: Per Bolmstedt | last post by:
(This question has been asked previously in this group, but I don't think it was ever really properly answered.) I want to use reflection - preferably - to find all Web Forms in my web site that inherit my base page class (which in turn inherits System.Web.UI.Page). Behold the following code: For Each asm As System.Reflection.Assembly In System.AppDomain.CurrentDomain.GetAssemblies() For Each mdl As System.Reflection.Module In...
7
2367
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system "Custom Attributes" by type. The output below identifies that I can catch the "DefaultMemberAttribute", but I can not catch my own "DirectoryVersionAttribute". Cany anyone throw any light on this as it is driving mad Thanks in Advance, - Paul....
4
6814
by: =?Utf-8?B?QWJoaQ==?= | last post by:
I am using Reflection to invoke methods dynamically. I have got a special requirement where I need to pass a value to method by setting the custom method attribute. As I cannot change the signature of method to pass a new parameter, I am setting the custom attribute of a given method and then accessing the attribute from method. Since attribute value is decided at runtime I want to change the attribute of particular method at runtime....
11
189
by: Joe | last post by:
Hi all! I have an application which uses plug-ins. The plug-ins implement an interface. I have a case where 1 plug-in needs access to the an object of the calling application. I could create an event in the interface to allow for this but this will break all the other plug-ins using the interface. (Would be nice if I could add an Optional attribute or something). I was thinking of using reflection in the plug-in to call a method in the...
6
1520
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And I need to pass in an Enumeration which is in the class that contains the method below 1)How do I create a List of this Class thru Reflection and once i populate it
0
10145
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
9998
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
9938
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
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.