By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

Reflection Issues

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.