Solved

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

Posted on 2007-12-06
26
5,134 Views
Last Modified: 2013-12-21
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

0
Comment
Question by:gbzhhu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 6
  • 4
26 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 20418601
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20418780
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20418793
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 24

Expert Comment

by:alexey_gusev
ID: 20418884
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20418929
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
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 20419015
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20419025
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20419041
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
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 250 total points
ID: 20419112
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20419196
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 20419539
Are we talking about 2005 here?  Did you install the Vista SP1 for .NET?  Are you using 2005 SP1?

Bob
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20419897
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20420262
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420369
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20420500
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20420512
>>However, I had the VS 2005 option to install the latest CF with service checked.

Remind me where this option is located?

Bob
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420533
OK Bob, let me see what files I have.

The option is in Project Properties->Device tab
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420562
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20420563
What folder did the .cab file get deployed into on the device?

Bob
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420590
I have no idea where VS deployed it to!  When I manually install I copy it to Program Files and then run it
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420621
My application is deployed to %CSIDL_PROGRAM_FILES%\MyMobileApp
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420630
Installing System_SR_ENU_wm.cab with date of 2007.02.14 didn't make any difference!
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420645
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 20420743
Bob,

What do you have in your devices windows folder?  I have System.SR.2.0.ENU dated 14/2/2007
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20421436
Interesting...mine is System.SR.2.0.ENU 2007.02.13, and is 57B.

Bob
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 20421558
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

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question