473,493 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with reflection

Hello All:

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

objForm.GetType().GetMethod("ShowDialog",
BindingFlags.InvokeMethod).Invoke(objForm, null);

The above is the line of code that is causing this trouble. I'm getting
a NullreferenceException 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 NullReferenceException?

Thanks In Advance.

Skandy.

Feb 19 '06 #1
5 6567
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("ShowDialog", new Type[0]);
m.Invoke(objForm, 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 NullreferenceException.

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

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

Ambiguous match found.
mscorlib
at System.RuntimeType.GetMethodImpl(String name, BindingFlags
bindingAttr, Bi
nder binder, CallingConventions callConv, Type[] types,
ParameterModifier[] modi
fiers)
at System.Type.GetMethod(String name)
at ReferenceImplementationSmartClients.Program.Main(S tring[] args)
in Z:\Deve
lopment\RC1\ReferenceImplementationSmartClients\Re ferenceImplementationSmartClie
nts\Program.cs:line 34
Press any key to continue . . .

TIA.
Skandy

Feb 19 '06 #3
You get this error because runtime doesn't know what method you need
Show(IWin32Windows) 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

4
1655
by: Nicolas | last post by:
The lat part is not working why ???????? Please help......... using System; namespace ConsoleApplication4 {
3
4378
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 =...
1
2380
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...
0
2709
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,...
6
4772
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...
1
1283
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...
2
2036
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()
2
3517
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...
15
11147
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>
2
2962
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...
0
6989
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...
1
6873
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...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
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...

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.