473,385 Members | 1,782 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,385 software developers and data experts.

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.GetType("MainObj");
MethodInfo info = type.GetMethod("GetOperatingSystemVersion");
Object activator = Activator.CreateInstance(type);
object x = info.Invoke(activator, 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 programmatically determine
which method to call. If I put the MainObj.GetOperatingSystemVersion() 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 1599
"Jason" <Ja*********@eclipsys.com> wrote:
My problem is trying to activate the method. On the final line of code
below, I get an error.

Type type = assembly.GetType("MainObj");
MethodInfo info = type.GetMethod("GetOperatingSystemVersion");
Object activator = Activator.CreateInstance(type);
object x = info.Invoke(activator, 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.com...
"Jason" <Ja*********@eclipsys.com> wrote:
My problem is trying to activate the method. On the final line of code
below, I get an error.

Type type = assembly.GetType("MainObj");
MethodInfo info = type.GetMethod("GetOperatingSystemVersion");
Object activator = Activator.CreateInstance(type);
object x = info.Invoke(activator, 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
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...
4
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...
1
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...
6
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
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...
7
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...
4
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...
11
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...
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.