473,580 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with reflection

Hello All:

I'm having this little trouble getting a form displayed using

objForm.GetType ().GetMethod("S howDialog",
BindingFlags.In vokeMethod).Inv oke(objForm, null);

The above is the line of code that is causing this trouble. I'm getting
a NullreferenceEx ception at this line.

I have debugged and checked that objForm is fine and is not null, and
the MethodInfo is correct too and is not null again.
Once I get the MethodInfo I try the Invoke(object, params);

Because the ShowDialog method for the Form class doesnt accept any
parameters, I pass a null value here.

Can anyone point why I'm getting this NullReferenceEx ception?

Thanks In Advance.


Feb 19 '06 #1
5 6582
I checked your code and MethodInfo is null. Use other overload of
GetMethod method to find ShowDialog:

Type t = objForm.GetType ();
MethodInfo m = t.GetMethod("Sh owDialog", new Type[0]);
m.Invoke(objFor m, null);

Feb 19 '06 #2
Hi Yury, Thanks for the reply.

Yes I relaized it just now, that the MethodInfo is returned NULL and
that explains why I get a NullreferenceEx ception.

But why is that I get the following exception against this code:
MethodInfo mi = objForm.GetType ().GetMethod("S how");

Form is not null
SmartClientAsse mbly.frmDisplay , Text: Reference Implementation for
Smart Clients

Ambiguous match found.
at System.RuntimeT ype.GetMethodIm pl(String name, BindingFlags
bindingAttr, Bi
nder binder, CallingConventi ons callConv, Type[] types,
ParameterModifi er[] modi
at System.Type.Get Method(String name)
at ReferenceImplem entationSmartCl ients.Program.M ain(String[] args)
in Z:\Deve
lopment\RC1\Ref erenceImplement ationSmartClien ts\ReferenceImp lementationSmar tClie
nts\Program.cs: line 34
Press any key to continue . . .


Feb 19 '06 #3
You get this error because runtime doesn't know what method you need
Show(IWin32Wind ows) or Show without parameters. So you need to specify
parameters types to help runtime to resolve method. If you need Show()
just pass empty array of Type as second parameter of GetMethod like in
first case.

GetMethod("Show ", new Type[0]);

Feb 19 '06 #4
Thanks a lot, Yury

Feb 19 '06 #5
Thanks a lot, Yury

Feb 19 '06 #6

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

Similar topics

by: Nicolas | last post by:
The lat part is not working why ???????? Please help......... using System; namespace ConsoleApplication4 {
by: dan | last post by:
Hi all, I have a reflection-problem I'm totally stuck with. Maybe someone has a hint... I want to get a fieldinformation of an event from the Control class, e.g. "TextChanged". FieldInfo fi = typeof(Control).GetField("TextChanged", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic |...
by: Raveendra M | last post by:
Hi! I am working with ASP.NET application. In my page I am creating one Application Domain and in that domain I am calling my DLL. Using the methods of the dll. And unloading the Application Domain. Till this point it is working fine. My problem is, while web page is open, than I am modifying the dll, and rebuilding. Then it is giving...
by: David Berman | last post by:
Hello, I'm receiving an error reading the machine.config file when I try to access my web application. This error came out of nowhere. After searching many sites, googelizing and searching here, I've found others with the same problem but no resolution. The problem for me (and for others) came out of nowhere. Here's the error message:...
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private members are not returned. I did some digging and the MSDN documentation states that the caller must have ReflectionPermission in order to get the...
by: Dominique Vandensteen | last post by:
I want to dynamicly load a type (typename is defined in the database). This type is located in the exe itself or one of the dll's in the directory with the exe file. When creating an instance directly it works, when using reflection none of the dll's is "scanned". I used following code to work around this problem. Now I just want to know if...
by: Marco | last post by:
Hi, I try to use reflection to retrieve class B members and not inherited members. I wonder why the myMember value is nothing. Any suggestions? Thanks Module Module1 Sub Main()
by: Andrea V.F. | last post by:
I use the code below (VB.NET) to display a Popup balloon in the Tray Icon of my application. The balloon is displayed, but the timeout never happens and the balloon is always visible even if I set it. Where is the error?? Please Help me. Thanks. Imports System.Runtime.InteropServices Public Class ClsNotifyBalloon
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
by: =?Utf-8?B?UmVuYXVkIExhbmdpcw==?= | last post by:
Hello, I have an asp.net web page (say page.aspx) which derives from a custom base page object (CustomPage : BasePage : System.Web.UI.Page) Which has a method called DoSomething(params). My web page contains a UserControl (say Control.ascx). In the control class, i want to call the DoSomething method. I cannot use type cast since in fact...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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. ...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.