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


.



Relevant Pages

  • Re: Reflection - Need advice
    ... I used reflection recently when I had to send a text-based command to objects implementing ISignalTarget. ... As a consequence you are able to read those contents yourself, and also execute methods etc too. ... If you have assemblies in a "Plugins" folder of your app that you want loaded dynamically, maybe because other people are allowed to write their own. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: reposted: accessing private members through reflection in vstu
    ... "If the requested property is non-public and the caller does not have ReflectionPermission to reflect non-public objects outside the current assembly, this method returns a null reference." ... You don't actually control reflection permission as narrowly as that. ... You cannot grant specific permission for reflection on specific assemblies to specific assemblies -- you give the assembly permission to perform reflection based on grant sets. ...
    (microsoft.public.dotnet.framework)
  • Re: Using "custom attributes"
    ... do you know reflection well? ... and assemblies ... Attributes only make sense in conjunction with one or more features. ... 2)AspectDNG AOP Framework ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using Reflection to Dynamically Determine Stored Procedure Name
    ... It is good to know that Reflection ... to know what stored procedures are being called by each aspx page. ... procs that are used by each of the three assemblies that are being ... then work my way down to the business/data layer assembly. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Invoking a Method via Reflection Issue
    ... This should be possible using Reflection. ... the Reflection namespace is designed specifically for inspecting objects and ... assemblies at runtime and accessing properties and methods. ... I am able to dynamically load both the DALC ...
    (microsoft.public.dotnet.languages.vb)