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

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

LVL 12
gbzhhuAsked:
Who is Participating?
 
alexey_gusevCommented:
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

0
 
alexey_gusevCommented:
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
0
 
gbzhhuAuthor 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.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
gbzhhuAuthor 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
0
 
alexey_gusevCommented:
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
0
 
gbzhhuAuthor 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?
0
 
alexey_gusevCommented:
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) ?
0
 
gbzhhuAuthor 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
0
 
gbzhhuAuthor 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.
0
 
gbzhhuAuthor 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
0
 
Bob LearnedCommented:
Are we talking about 2005 here?  Did you install the Vista SP1 for .NET?  Are you using 2005 SP1?

Bob
0
 
gbzhhuAuthor 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
0
 
Bob LearnedCommented:
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
0
 
gbzhhuAuthor 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)
0
 
Bob LearnedCommented:
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
0
 
Bob LearnedCommented:
>>However, I had the VS 2005 option to install the latest CF with service checked.

Remind me where this option is located?

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

The option is in Project Properties->Device tab
0
 
gbzhhuAuthor 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
0
 
Bob LearnedCommented:
What folder did the .cab file get deployed into on the device?

Bob
0
 
gbzhhuAuthor Commented:
I have no idea where VS deployed it to!  When I manually install I copy it to Program Files and then run it
0
 
gbzhhuAuthor Commented:
My application is deployed to %CSIDL_PROGRAM_FILES%\MyMobileApp
0
 
gbzhhuAuthor Commented:
Installing System_SR_ENU_wm.cab with date of 2007.02.14 didn't make any difference!
0
 
gbzhhuAuthor 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-\
0
 
gbzhhuAuthor Commented:
Bob,

What do you have in your devices windows folder?  I have System.SR.2.0.ENU dated 14/2/2007
0
 
Bob LearnedCommented:
Interesting...mine is System.SR.2.0.ENU 2007.02.13, and is 57B.

Bob
0
 
gbzhhuAuthor 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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.