Article ID: 962933 - Last Review: January 15, 2009 - Revision: 1.0 Wrong type of exception is thrown when using ADO.NET Data Services client encounters a bad server name or a request times outSource: Microsoft Support RAPID PUBLISHINGRAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION. SymptomThis article describes an issue that exists in the ADO.NET Data Services client (System.Data.Services.Client.dll) included with .NET 3.5 sp1 and Silverlight 2.0 SDK. The program does not throw the correct exception when a HTTP request has problems while being sent to the server. For instance a request times out, there is a bad server name, or any other problem that would normally raise a System.Net.WebException.
In version 1 of ADO.NET Data Services a NullReferenceException is raised instead of a WebException and the exception message is lost: DataServiceContext context = new DataServiceContext( new Uri("http://BadServer/Northwind.svc")); // Set small timeout amount to intentionally timeout request context.Timeout = 1; DataServiceQuery<Customer> query = context.CreateQuery<Customer>("Customers"); try { foreach (Customer c in query) { } } catch (NullReferenceException nre) { // in V1, NullReferenceException is //thrown instead of WebException. // Also, no useful description Console.WriteLine("Something bad happened!"); } ResolutionMicrosoft is researching this problem and is planning on fixing this bug in a future version of ADO.NET Data Services client (both in .NET and Silverlight). If your code relies exclusively on catching the NullReference exception, it will be broken when a fix becomes available. To make your code more robust by explicitly designing it to capture both exception types: DataServiceContext context = new DataServiceContext( new Uri("http://BadServer/Northwind.svc")); // Set small timeout amount to intentionally timeout request context.Timeout = 1; DataServiceQuery<Customer> query = context.CreateQuery<Customer>("Customers"); try { foreach (Customer c in query) { } } catch (WebException e) { // When fix is shippped, will ADO.NET Data Services // will correctly throw webException Console.WriteLine(e.Message); } catch (NullReferenceException nre) { // in V1, NullReferenceException is thrown // instead of WebException. // Also, no useful description Console.WriteLine("Something bad happened!"); } More InformationMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. http://blogs.msdn.com/astoriateam/archive/2009/01/13/timeout-workaround.aspx (http://blogs.msdn.com/astoriateam/archive/2009/01/13/timeout-workaround.aspx) DISCLAIMERMICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
|
|
Back to the top
