An error message cannot be displayed because an optional resource assembly containing it cannot be found

gbzhhu
gbzhhu used Ask the Experts™
on
Hi,

I am using C# on Vista and windows mobile 5.0 on device and CF 2.0.

Everytime there is an exception in the application this error message is displayed which prevents me from knowing what has happened.
"An error message cannot be displayed because an optional resource assembly containing it cannot be found"  This error is discussed here
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2460541&SiteID=1

Everyone is saying to make sure I have System_SR_ENU_wm.cab installed on device but that doesn't help.  I am new to devices so can't think of anything else to do.

Help appreciated
H

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try to search this site for "optional resource assembly"
here is also some short explanation: http://blogs.msdn.com/netcfteam/archive/2004/08/06/210232.aspx

Author

Commented:
Thanks alexey_gusev

This error has been driving me mad but I now have more info that I didn't before.  On a button click i tried to create an error DivisonByZero and the exception message is displayed correctly.  However, if an error occured in a method in the same form called from same button the exception message is "An error message cannot be displayed because an optional resource assembly containing it cannot be found".  The method in question just captures the exception and rethrows like this

            catch (Exception)
            {
                throw;
            }

This is also how my web service handles its exceptions which is incorrect I believe.

I am wondering why the method rethrowing the exception is causing this "An error message cannot be displayed because an optional resource assembly containing it cannot be found". And what kis the best way to handle the exceptions in the web service.

Author

Commented:
Searching the site for optional resource assembly" leads me to my own questions!  

Yes, I have seen that article and I have the System_SR_ENU_wm.cab installed.  The issue now seems to be how I handle my exceptions
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

well, I would use another form of throwing the exception

catch (Exception ex)
            {
                throw ex;
            }

or even

catch (Exception ex)
            {
                throw new Exception(<put here what you need>);
            }

but I'm not sure if it changes something

Author

Commented:
First of all this is not good

catch (Exception ex)
            {
                throw ex;
            }

If you do this you will lose the stack trace of the exception source.

Strange enough, I just made a deliberate error in the web service (passed wrong parameter name to stored procedure).  Using the same exception handling as I was before the error gets sent to the client and is displayed correctly!!!

The same error handling in my client code (a method that reads an xml file) if the file doesn't exist then the method callee gets that obscure error!!!  I know I check for the existence of the file but this is for exercise tio see what causes that aweful error

If my device cannot connect to the Internet I also get that same dodgy error.  The method I mentioned is here

        private void LoadUsers()
        {
            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(Common.userListFile);
                XmlNodeList nodes = xdoc.SelectNodes("/localUsers/localUser/name");

                cboUsers.Items.Clear();

                foreach (XmlNode node in nodes)
                {
                    cboUsers.Items.Add(node.InnerText);
                }

                cboUsers.Items.Insert(0, "<-- Please select -->");
                cboUsers.SelectedIndex = 0;
            }
            catch (Exception)
            {
                throw;
            }
        }



Other ideas?
well, if you really need the whole stack trace, "throw" blocks I noted do loose it :)

and just to clarify: have you installed both cabs (xxx_ENU.cab and xxx_ENU_wm.cab) ?

Author

Commented:
This is what MS says about the topic
http://msdn2.microsoft.com/en-us/library/ds492xtk(VS.71).aspx

The web service as it is seems to be throwing the exceptions correctly.  

Can you do a simple test, just in case I am doing something else wrong.  If you can:

- Create a winforms device app
- Stick a button on the form
- Write a private method that reads a file and make sure that file doesn't exist
- Use my type of exception handling in the method
- Call the method from button click and also handle exceptions there, do you get correct exception details?

Thanks

Author

Commented:
No, I have only installed xxx_ENU_wm.cab.  In fact this device I am testing on I have uninstalled xxx_ENU_wm.cab and let VS 2005 install it as needed during debug.
here is what works correctly on my iPaq rx1900
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                GenerateException();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        private void GenerateException()
        {
            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("\\alex.xml");
                XmlNodeList nodes = xdoc.SelectNodes("/localUsers/localUser/name");
 
                foreach (XmlNode node in nodes)
                {
                    MessageBox.Show(node.InnerText);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

Open in new window

Author

Commented:
I used your code exactly as it is and I get the dodgy error.  My device SPV M3100

This tells me that it is not the code but either a device issue or resource conflict
Most Valuable Expert 2012
Top Expert 2008
Commented:
Are we talking about 2005 here?  Did you install the Vista SP1 for .NET?  Are you using 2005 SP1?

Bob

Author

Commented:
Bob,

Yes, VS 2005.  Yes, I installed Vista fix and yes I have SP1 for VS 2005.  This is info from my about VS box

Microsoft Visual Studio 2005
Version 8.0.50727.867 (vsvista.050727-8600)

Microsoft .NET Framework
Version 2.0.50727
Most Valuable Expert 2012
Top Expert 2008

Commented:
And for CF 2.0, did you install SP2?  What is the file information for System_SR_ENU_wm.cab?  It almost seems like you may have the right name, but the wrong file.

Bob

Author

Commented:
I downloaded CF 2.0 with SP2 and installed on the device.  However, I had the VS 2005 option to install the latest CF with service checked.  So VS was deploying the latest CF it could find.  I have that unchecked and tried to install CF 2.0 SP 2 and got a message "A newer version "A newer version of .NET CF is installed which must uninstalled before installing this version"

On the device, for System_SR_ENU_wm.cab, all I can get is modified date which is 01/09/05 (uk date)
Most Valuable Expert 2012
Top Expert 2008

Commented:
I see two files in these folders with dates as shown:

C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics

2007.02.14

C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\Diagnostics

2005.09.19

Bob
Most Valuable Expert 2012
Top Expert 2008

Commented:
>>However, I had the VS 2005 option to install the latest CF with service checked.

Remind me where this option is located?

Bob

Author

Commented:
OK Bob, let me see what files I have.

The option is in Project Properties->Device tab

Author

Commented:
My files are

C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics

2007.02.14

C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\Diagnostics

2005.08.19

Just in case VS copied wrong file I am going to try installing the 2007.02.14
Most Valuable Expert 2012
Top Expert 2008

Commented:
What folder did the .cab file get deployed into on the device?

Bob

Author

Commented:
I have no idea where VS deployed it to!  When I manually install I copy it to Program Files and then run it

Author

Commented:
My application is deployed to %CSIDL_PROGRAM_FILES%\MyMobileApp

Author

Commented:
Installing System_SR_ENU_wm.cab with date of 2007.02.14 didn't make any difference!

Author

Commented:
Strange enough I get the correct error message if put a deliberate error in the button click but the dodgy error if I call a method from button click and error happened in the method and rethrown 8-\

Author

Commented:
Bob,

What do you have in your devices windows folder?  I have System.SR.2.0.ENU dated 14/2/2007
Most Valuable Expert 2012
Top Expert 2008

Commented:
Interesting...mine is System.SR.2.0.ENU 2007.02.13, and is 57B.

Bob

Author

Commented:
Mine is also 57B!!

Too many of these files with too many versions and dates, very confusing.
Going home time for me.  Let's continue this thing tomorrow and thanks.

Hassan

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial