Is there a simple way to trap a mysterious 'System.NullReferenceException' error?

  • Thread starter Thread starter PPCdude
  • Start date Start date
P

PPCdude

Hi,

I don't want to make this too long, but here's what I am doing. I have
taken most of my constructors out of the initializecomponent to
optimize loading speed. This has worked well for years. Then the
other day, I temporarily moved a constructor back to
initializecomponent in order to change a picturebox picture. It all
seemed to work just fine till I ran the program and suddenly I get
every time I click a button.

An unhandled exception of type 'System.NullReferenceException' occurred
in System.Windows.Forms.dll

I thought at first I wrecked the resx file, but replacing it with a
backup does nothing. I still crash.

I am pulling my hair out because if I set a breakpoint on a button it
doesn't find anything.

thanks.
 
Step through with the debugger, my guess is that its a problem retrieving
your image - if you are using GetManifestResourceStream make sure you
specify the full and correct namespace and resource name e.g. if your
project has a base namespace of MyCompany.MyApp and you add an embedded
MyPicture.jpg your resource name should be
MyCompany.MyApp.MyPicture.jpg

Here there are different behaviours between VB and C# projects, VB allows
you to specify a base namespace which all code/resources are below, C#
allows you to specify a default namespace which is added to code files when
they are created in the project. If you are in any doubt as to the resource
name, you can use ildasm or similar to inspect the contents of your exe

Peter
 
Thanks Peter,

Quick question...where would I manually change the namespace for the
picture?
 
Its based on the default/root namespace in the project properties dialog,
plus the folder hierarchy within your project, and finally the image file
name in your project

Peter
 
Back
Top