Runtime exception System.Resources.MissingManifestResourceExceptio

G

Guest

I have found a strange resource problem, but luckily I have also found the
solution which was not obvious from the runtime exception. I really think
that the compiler should pick up this problem and fix it. What do you people
think? Try the following:

1. Create a new c# windows application called MyTestApp
2. Create a notifyIcon on the form
3. Attach any icon you wish to the notifyIcon
4. Build and run the program to confirm that it works.

*** Causing the problem ***

5. In Form1.cs change the namespace to MyNewNamespace
6. Let's say that your form class needs to use an enum definition. If your
from a C/C++ background you would define this before the Form1 Class
defintion therefore, just after the namespace line and before the Form1 class
definition type the following

public enum eTest
{
Test1,
Test2
};

This enum and its contents are not critical to producing the problem just
the fact that it is before the form definition is enough. Adding a class here
also cuases the problem.

7. Compile and run the program again. The following exception is thrown:

Unhandled Exception: System.Resources.MissingManifestResourceException:
Could not find any resources appropriate for the specified culture (or the
neutral culture) in the given assembly. Make sure "Form1.resources" was
correctly embedded or linked into assembly "MyTestApp".
baseName: Form1 locationInfo: MyNewNamespace.Form1 resource file name:
Form1.resources assembly: MyTestApp, Version=1.0.1796.23855,
Culture=neutral, PublicKeyToken=null
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo
culture)
at System.Resources.ResourceManager.GetObject(String name)
at MyNewNamespace.Form1.InitThe program '[3376] MyTestApp.exe' has exited
with code 0 (0x0).
ializeComponent() in c:\projects\testapps\mytestapp\form1.cs:line 64
at MyNewNamespace.Form1..ctor() in
c:\projects\testapps\mytestapp\form1.cs:line 29
at MyNewNamespace.Form1.Main() in
c:\projects\testapps\mytestapp\form1.cs:line 85

*** Fixing the problem ***

8. To fix the problem either:
a) Change the namespace in the form1.cs file back to MyTestApp.
b) Move the enum definition AFTER the form1 class definition.
c) Go to the project properties under Project->Properties on the menus.
Select Common Properties/General and set the default namespace to
MyNewNamespace and click OK
compile and run the program again and it works!

I believe that the compiler should be able to see this problem and ask you
to change the Default namespace under the project settings or it says it can
change it for you if you click OK. The above exception is a little misleading
to the actual problem that has occured. In many cases people from a C or C++
background will want to declare the enum definition before the class
definition if the class was to use it as this is the way C & C++ likes to do
things.

It seems that if the Enum was place after the form class definition then the
namespace that is defined in the Form1.cs file is used otherwise it uses the
one from the project settings!

Is there a reason for this? Would anyone like to comment?
 
G

Guest

This is a known "feature":
http://support.microsoft.com/default.aspx?scid=kb;en-us;318603

Regards, Jakob.


DelboyJay said:
I have found a strange resource problem, but luckily I have also found the
solution which was not obvious from the runtime exception. I really think
that the compiler should pick up this problem and fix it. What do you people
think? Try the following:

1. Create a new c# windows application called MyTestApp
2. Create a notifyIcon on the form
3. Attach any icon you wish to the notifyIcon
4. Build and run the program to confirm that it works.

*** Causing the problem ***

5. In Form1.cs change the namespace to MyNewNamespace
6. Let's say that your form class needs to use an enum definition. If your
from a C/C++ background you would define this before the Form1 Class
defintion therefore, just after the namespace line and before the Form1 class
definition type the following

public enum eTest
{
Test1,
Test2
};

This enum and its contents are not critical to producing the problem just
the fact that it is before the form definition is enough. Adding a class here
also cuases the problem.

7. Compile and run the program again. The following exception is thrown:

Unhandled Exception: System.Resources.MissingManifestResourceException:
Could not find any resources appropriate for the specified culture (or the
neutral culture) in the given assembly. Make sure "Form1.resources" was
correctly embedded or linked into assembly "MyTestApp".
baseName: Form1 locationInfo: MyNewNamespace.Form1 resource file name:
Form1.resources assembly: MyTestApp, Version=1.0.1796.23855,
Culture=neutral, PublicKeyToken=null
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo
culture)
at System.Resources.ResourceManager.GetObject(String name)
at MyNewNamespace.Form1.InitThe program '[3376] MyTestApp.exe' has exited
with code 0 (0x0).
ializeComponent() in c:\projects\testapps\mytestapp\form1.cs:line 64
at MyNewNamespace.Form1..ctor() in
c:\projects\testapps\mytestapp\form1.cs:line 29
at MyNewNamespace.Form1.Main() in
c:\projects\testapps\mytestapp\form1.cs:line 85

*** Fixing the problem ***

8. To fix the problem either:
a) Change the namespace in the form1.cs file back to MyTestApp.
b) Move the enum definition AFTER the form1 class definition.
c) Go to the project properties under Project->Properties on the menus.
Select Common Properties/General and set the default namespace to
MyNewNamespace and click OK
compile and run the program again and it works!

I believe that the compiler should be able to see this problem and ask you
to change the Default namespace under the project settings or it says it can
change it for you if you click OK. The above exception is a little misleading
to the actual problem that has occured. In many cases people from a C or C++
background will want to declare the enum definition before the class
definition if the class was to use it as this is the way C & C++ likes to do
things.

It seems that if the Enum was place after the form class definition then the
namespace that is defined in the Form1.cs file is used otherwise it uses the
one from the project settings!

Is there a reason for this? Would anyone like to comment?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top