473,811 Members | 2,756 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
reflection.

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.

Skandy.

Feb 19 '06 #1
5 6591
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.
mscorlib
at System.RuntimeT ype.GetMethodIm pl(String name, BindingFlags
bindingAttr, Bi
nder binder, CallingConventi ons callConv, Type[] types,
ParameterModifi er[] modi
fiers)
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 . . .

TIA.
Skandy

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

4
1667
by: Nicolas | last post by:
The lat part is not working why ???????? Please help......... using System; namespace ConsoleApplication4 {
3
4416
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 | System.Reflection.BindingFlags.Public);
1
2404
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 error: "The file 'MyClass.dll' cannot be copied to the run directory. The process cannot access the...
0
2746
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: >>>>> START <<<<< Server Error in '/MyApp' Application....
6
4791
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 private members of a class. I am a little unfamiliar with this stipulation. I have checked the docs on...
1
1302
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 this is the/a good way to do it, or should I use another system.
2
2063
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
3535
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
15
11223
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
2982
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 the base class Page structure is a little more complex (see bottom of post). Hence i cannot do:
0
9605
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5554
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
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
3
3017
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.