I have a C# / WPF project that references a webservice. However, sometimes I get a NullReferenceException
when creating an instance of the auto-generated class that represents it:
var service = new SSO();
The stacktrace is as follows:
System.NullReferenceException: Object reference not set to an instance of an object.
in System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
in System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
in System.Web.Services.Protocols.SoapClientType..ctor(Type type)
in System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
in MyNamespace.SSO..ctor()
Does anyone have an idea what's going on here? The server may have small periods of downtime, but that's not the exception I expect to see in case of network connection issues!
Update: the code of the auto-generated class SSO
in case someone finds it relevant:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.17929")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="SSOSoap", Namespace="http://schemas.example.com/SSO")]
public partial class SSO : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public SSO()
{
this.Url = "http://example.com/SSO.asmx";
if ((this.IsLocalFileSystemWebService(this.Url) == true))
{
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else
{
this.useDefaultCredentialsSetExplicitly = true;
}
}
// a lot of methods here
}