{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/referencesource/issues/10","labels_url":"https://api.github.com/repos/Microsoft/referencesource/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/referencesource/issues/10/comments","events_url":"https://api.github.com/repos/Microsoft/referencesource/issues/10/events","html_url":"https://github.com/Microsoft/referencesource/issues/10","id":118122121,"number":10,"title":"Bug in ASP.NET WebServices ServerProtocol.GenerateFaultString() method","user":{"login":"pvones","id":2962335,"avatar_url":"https://avatars.githubusercontent.com/u/2962335?v=3","gravatar_id":"","url":"https://api.github.com/users/pvones","html_url":"https://github.com/pvones","followers_url":"https://api.github.com/users/pvones/followers","following_url":"https://api.github.com/users/pvones/following{/other_user}","gists_url":"https://api.github.com/users/pvones/gists{/gist_id}","starred_url":"https://api.github.com/users/pvones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pvones/subscriptions","organizations_url":"https://api.github.com/users/pvones/orgs","repos_url":"https://api.github.com/users/pvones/repos","events_url":"https://api.github.com/users/pvones/events{/privacy}","received_events_url":"https://api.github.com/users/pvones/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-20T20:41:38Z","updated_at":"2015-11-20T20:41:38Z","closed_at":null,"body":"There is bug in [ServerProtocol.GenerateFaultString method at 136](https://github.com/Microsoft/referencesource/blob/master/System.Web.Services/System/Web/Services/Protocols/ServerProtocol.cs#L136)\r\n\r\n```c#\r\nfor (Exception inner = e; inner != null; inner = inner.InnerException) {\r\n  string text = htmlEscapeMessage ? HttpUtility.HtmlEncode(inner.Message) : inner.Message;\r\n  if (text.Length == 0) text = e.GetType().Name;\r\n```\r\nIf there is a custom Exception class translated to SoapMessage that overrides Message property and returns null, the code throws **NullReferenceException** at *text.Length* expression becasue *text* variable has null value. Please fix it. Note that is occurs when custom errors mode is on only.\r\n\r\nSteps to reproduce. Create new ASP.NET Web Service \r\n\r\n```c#\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Web;\r\nusing System.Web.Services;\r\nusing System.Reflection;\r\nusing System.Web.Services.Protocols;\r\nusing System.Xml;\r\n\r\nnamespace WebService1\r\n{\r\n\tpublic class MyException : Exception\r\n\t{\r\n\t\tpublic MyException()\r\n\t\t\t: base(null)\r\n\t\t{\r\n\t\t}\r\n\r\n\t\tpublic override string Message\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\t// the null Message causes exception in .NET framework method when translating exception into SoapMessage\r\n\t\t\t\t// ServerProtocol.GenerateFaultString(Exception e, Boolean htmlEscapeMessage), line 136\r\n\t\t\t\t//\r\n\t\t\t\treturn null; \r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// Summary description for Service1\r\n\t/// </summary>\r\n\t[WebService(Namespace = \"http://tempuri.org/\")]\r\n\t[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]\r\n\t[System.ComponentModel.ToolboxItem(false)]\r\n\tpublic class Service1 : System.Web.Services.WebService\r\n\t{\r\n\t\t[WebMethod]\r\n\t\tpublic string HelloWorld()\r\n\t\t{\r\n\t\t\t// ! Required setting in web.config to reproduce the issue !\r\n\t\t\t//  <system.web>\r\n\t\t\t//    <customErrors mode=\"On\" />\r\n\r\n\t\t\tthrow new MyException();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\nSOAP request\r\n```xml\r\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n  <s:Header>\r\n    <Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/HelloWorld</Action>\r\n  </s:Header>\r\n  <s:Body>\r\n    <HelloWorld xmlns:d3p1=\"http://schemas.datacontract.org/2004/07/\" i:nil=\"true\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://tempuri.org/\" />\r\n  </s:Body>\r\n</s:Envelope>\r\n```\r\nSOAP response\r\n```xml\r\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <s:Header xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" />\r\n  <soap:Body>\r\n    <soap:Fault>\r\n      <faultcode>soap:Server</faultcode>\r\n      <faultstring>Server was unable to process request. ---&gt; Object reference not set to an instance of an object.</faultstring>\r\n      <detail />\r\n    </soap:Fault>\r\n  </soap:Body>\r\n</soap:Envelope>\r\n```"}}