Condividi tramite


Getting full exceptions in Silverlight 2 Beta 1

When debugging Silverlight 2 Beta 1 apps in Visual Studio, you might see exceptions show up like this:

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user codeAdditional information: [UnexpectedHttpResponseCode]Arguments:Not FoundDebugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See https://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.ServiceModel.dll&Key=UnexpectedHttpResponseCode

By default Silverlight does not include the full exception strings. They are stripped out of assemblies in order to realize cost savings in the Silverlight runtime download package.

This post talks about how to configure your machine to get the full exception strings back in Visual Studio debugging sessions.

Runtime (Core) Assemblies

The Silverlight runtime assemblies are installed on every user's machine when they download and install the Silverlight runtime. These assemblies live in the C:\Program Files\Microsoft Silverlight\2.0.30226.2 folder on the user's hard drive. To keep the Silverlight runtime download package small, these assembles do not contain any exception strings. When an exception is thrown and not caught, a barebones message is shown to the user, like the one shown above.

The size savings from removing the full exceptions make sense for the end user, but when developing apps the full exception strings are needed. They are included in the Silverlight SDK install. For each runtime assembly the SDK will install an additional .debug.resources.dll assembly (which contains the full exception string) in a "en-us" folder alongside the original assembly. The shows System.ServiceModel.dll as an example:

Silverlight runtime with debug resources installed

The only manual step needed to enable full exceptions is to modify the Silverlight manifest file - C:\Program Files\Microsoft Silverlight\2.0.30226.2\slr.dll.managed_manifest. This is shown in the Silverlight 2 SDK Beta 1 release notes, under the "slr.dll.managed_manifest needs to be manually edited ..." topic. For every runtime assembly you need to add something like:

<

localizedassembly>
<name>System.ServiceModel.debug.resources</name>
<version>2.0.5.0</version>
<publickeytoken>31bf3856ad364e35</publickeytoken>
<relfolder>.</relfolder>
<file>System.ServiceModel.debug.resources.dll</file>
</localizedassembly>

After this modification, Visual Studio will show the full exception text:

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user codeAdditional information: The remote server returned an unexpected response: (404) Not Found.

Extension Assemblies

These assemblies contain specialized functionality and are not installed with the Silverlight runtime. If a Silverlight app references one of these assemblies, the assembly gets packaged together with the app's own assemblies, inside the .xap package (something Visual Studio does automatically). Developers get these assemblies by installing the Silverlight SDK, which places them in the C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client folder. Again, the Silverlight runtime does not look inside this folder, and the only way the end user can get these assemblies is if they are in the app's .xap file.

Since the extension assemblies are included with apps on-demand, and are not part of the Silverlight runtime download, the full exception strings are included in the assemblies themselves. You will automatically get full exceptions, like so:

An exception of type 'System.NotSupportedException' occurred in System.ServiceModel.Syndication but was not handled in user codeAdditional information: Error in line 2 position 2. The Rss20Serializer does not support RSS version '4.0'.

Hope this is helpful!

Yavor Georgiev
Program Manager
Connected Framework

Comments

  • Anonymous
    April 08, 2008
    PingBack from http://blogs.msdn.com/silverlightws/archive/2008/04/06/getting-full-exceptions-in-silverlight-2-beta-1.aspx

  • Anonymous
    April 09, 2008
    Thanks for the great tip.  It would have been nice for the Silverlight SDK to come with the complete snippet of XML for all the assemblies that we need to add to the manifest, so that each of us doesn't have to painstakingly derive it on our own.  Anyway, in case it's useful to others, here's what I came up with:  <localizedassembly>    <name>mscorlib.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>mscorlib.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.Core.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.Core.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.Runtime.Serialization.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.Runtime.Serialization.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.ServiceModel.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>31bf3856ad364e35</publickeytoken>    <relfolder>.</relfolder>    <file>System.ServiceModel.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.ServiceModel.Web.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.ServiceModel.Web.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.Windows.Browser.debug.resources</name>    <version>0.0.0.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.Windows.Browser.debug.resources.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.Windows.Browser</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.Windows.Browser.dll</file>  </localizedassembly>  <localizedassembly>    <name>System.Xml.debug.resources</name>    <version>2.0.5.0</version>    <publickeytoken>7cec85d7bea7798e</publickeytoken>    <relfolder>.</relfolder>    <file>System.Xml.debug.resources.dll</file>  </localizedassembly>

  • Anonymous
    April 09, 2008
    @RajeevGoel: Rajeev, the release notes linked above actually do contain the corrected manifest, which you can copy-paste directly. Cheers, -Yavor

  • Anonymous
    April 09, 2008
    Thanks Yavor.  Before posting my comment, I did try clicking on that link to the Release Notes, but I keep getting a Page Not Found.  Don't know if it's a problem on my end or something else.

  • Anonymous
    April 09, 2008
    @RajeevGoel: Good catch, thank you. I updated it. -Yavor

  • Anonymous
    April 16, 2008
    Silverlight 2 Beta1 makes it easy to use Web Services based on either the WCF technology (Windows Communication

  • Anonymous
    October 08, 2015
    Hi, Is there any way of including these assemblies in the xap file ans copied to the client machine without our intention of doing it manually. since its not good to edit in user machine and manually doing stuffs.