Windows Develop Bookmark and Share   
 index > Windows Forms General > MethodNotFound when invoked from a forms control
 

MethodNotFound when invoked from a forms control

Hi all,
I am building a custom control that inherits from ListBox. I am overriding the WndProc Method to intercept WM_ERASEBKGND (0x014) to write a message on the listbox indicating that it is empty. When intercepted, I call a static method in some class that takes a string ("There are no items to show") and wraps it to fit the listbox width:

public static List<string> SplitSentence(string value, int width, Graphics g, Font f);

This will just break up the input string into whole words and build lines until the width is exceeded and add that line to the returned string collection.

My problem is that when I run my app, I get this:
System.MissingMethodException: Method not found:
'System.Collections.Generic.List`1<System.String>
Root.Library.ConvertTo.SplitSentence(System.String, Int32, System.Drawing.Graphics, System.Drawing.Font)'.

If I make the method a non-static method in the control class, it works fine. But if I leave it in the other static class (or a non-static class) in a different assembly, it doesn't. ??
tirpitz3  Friday, March 31, 2006 7:56 AM

Well the only reason i can think of is that a List<string> can not be called from a static context.

It gives u a System.MissingMethodException, maybe the internal method of a List<generic> declaration cannot be called static and therefor it can not find the method.

By the way, i am quite new to generics so i dont really know the innerworking of them but its a possibility.

Greets and goodluck!

M. Dirksma  Friday, March 31, 2006 9:32 AM
Thanks for your reply, but I don't know that that is the problem. If I place the class inside the assembly with the control, it works fine, even as a static method. It seems to have something to do with the fact that this method/class is not inside the same assembly.
tirpitz3  Friday, March 31, 2006 5:03 PM

You can use google to search for other answers

Custom Search

More Threads

• MIDI Parent
• Calculating text fields
• Zero-length byte array???
• Help with my alignment controls?
• wat is the actual way to open & close window form?
• How do I make a form read only (vb.net)
• Saving and Restoring MDI workspace
• How to debug a program that seems to crash without executing any added code.
• Richtextbox undo problem
• BackgroundWorker hoses message pump