Runtime exception System.Resources.MissingManifestResourceExceptio

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DelboyJay

    #1

    Runtime exception System.Resources.MissingManifestResourceExceptio

    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.Resource s.MissingManife stResourceExcep tion:
    Could not find any resources appropriate for the specified culture (or the
    neutral culture) in the given assembly. Make sure "Form1.resource s" was
    correctly embedded or linked into assembly "MyTestApp" .
    baseName: Form1 locationInfo: MyNewNamespace. Form1 resource file name:
    Form1.resources assembly: MyTestApp, Version=1.0.179 6.23855,
    Culture=neutral , PublicKeyToken= null
    at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    culture, Boolean createIfNotExis ts, Boolean tryParents)
    at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    culture, Boolean createIfNotExis ts, Boolean tryParents)
    at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    culture, Boolean createIfNotExis ts, Boolean tryParents)
    at System.Resource s.ResourceManag er.GetObject(St ring name, CultureInfo
    culture)
    at System.Resource s.ResourceManag er.GetObject(St ring name)
    at MyNewNamespace. Form1.InitThe program '[3376] MyTestApp.exe' has exited
    with code 0 (0x0).
    ializeComponent () in c:\projects\tes tapps\mytestapp \form1.cs:line 64
    at MyNewNamespace. Form1..ctor() in
    c:\projects\tes tapps\mytestapp \form1.cs:line 29
    at MyNewNamespace. Form1.Main() in
    c:\projects\tes tapps\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?
  • Jakob Christensen

    #2
    RE: Runtime exception System.Resource s.MissingManife stResourceExcep tio

    This is a known "feature":


    Regards, Jakob.


    "DelboyJay" wrote:
    [color=blue]
    > 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.Resource s.MissingManife stResourceExcep tion:
    > Could not find any resources appropriate for the specified culture (or the
    > neutral culture) in the given assembly. Make sure "Form1.resource s" was
    > correctly embedded or linked into assembly "MyTestApp" .
    > baseName: Form1 locationInfo: MyNewNamespace. Form1 resource file name:
    > Form1.resources assembly: MyTestApp, Version=1.0.179 6.23855,
    > Culture=neutral , PublicKeyToken= null
    > at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    > culture, Boolean createIfNotExis ts, Boolean tryParents)
    > at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    > culture, Boolean createIfNotExis ts, Boolean tryParents)
    > at System.Resource s.ResourceManag er.InternalGetR esourceSet(Cult ureInfo
    > culture, Boolean createIfNotExis ts, Boolean tryParents)
    > at System.Resource s.ResourceManag er.GetObject(St ring name, CultureInfo
    > culture)
    > at System.Resource s.ResourceManag er.GetObject(St ring name)
    > at MyNewNamespace. Form1.InitThe program '[3376] MyTestApp.exe' has exited
    > with code 0 (0x0).
    > ializeComponent () in c:\projects\tes tapps\mytestapp \form1.cs:line 64
    > at MyNewNamespace. Form1..ctor() in
    > c:\projects\tes tapps\mytestapp \form1.cs:line 29
    > at MyNewNamespace. Form1.Main() in
    > c:\projects\tes tapps\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?[/color]

    Comment

    Working...