C# Webservice错误:对象引用未设置为对象的实例

C# Webservice错误:对象引用未设置为对象的实例,c#,.net,web-services,runtime-error,webmethod,C#,.net,Web Services,Runtime Error,Webmethod,我有一个构建得很好的Web服务。但当我尝试调试它并点击F5(在Visual Studio中)时,我得到了错误,因为对象引用未设置为对象的实例。读取更多堆栈跟踪后,错误似乎出现在我用作WebMethod参数的类对象中。该类如下所示: public class UserObject { public string UniqueID { get; set; } public string Password { protected internal get; set; } pub

我有一个构建得很好的Web服务。但当我尝试调试它并点击F5(在Visual Studio中)时,我得到了错误,因为
对象引用未设置为对象的实例。读取更多堆栈跟踪后,错误似乎出现在我用作
WebMethod
参数的类对象中。该类如下所示:

public class UserObject
{
    public string UniqueID { get; set; }
    public string Password { protected internal get; set; }
    public bool IsNew { get; protected internal set; }
    public string Error { get; protected internal set; }
    public bool HasError
    {
        get
        {
            return !string.IsNullOrEmpty(Error);
        }
    }
}
我怀疑这就是未能序列化的类。如果它看起来是一个错误的序列化对象,那么它是可能的。这是我第一次使用Web服务。我可以考虑以后把它转换成WCF。放置
[序列化]
属性也不起作用。从这里有什么方向吗

有人能告诉我如何追踪准确的错误吗

编辑

下面是完整的错误

    [NullReferenceException: Object reference not set to an instance of an object.
   System.Xml.Serialization.StructModel.CheckPropertyRead(PropertyInfo propertyInfo) +40
   System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo) +44
   System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo) +89
   System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +247
   System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +378
   System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1734

[InvalidOperationException: There was an error reflecting type 'Presenter.UserObject'.]
   System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1852
   System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +5539216
   System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +869
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +286

[InvalidOperationException: There was an error reflecting 'userObject'.]
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +899
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +133
   System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle paramStyle, String elementName, String elementNamespace, Boolean nsIsDefault, XmlReflectionMember[] members, Boolean validate, Boolean openModel, String key, Boolean writeAccess) +235
   System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +1971

[InvalidOperationException: Method MyWebService.MethodToAdd can not be reflected.]
   System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +6307
   System.Web.Services.Description.SoapProtocolReflector.ReflectMethod() +137
   System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +1587
   System.Web.Services.Description.ProtocolReflector.Reflect() +641
   System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +563
   System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +109
   System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri, Boolean excludeSchemeHostPortFromCachingKey) +230
   System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +473
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +122

[InvalidOperationException: Unable to handle request.]
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +326
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +171

[InvalidOperationException: Failed to handle request.]
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +346
   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +120
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +346
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

你能公布正在显示的实际错误吗?@JoelEtherton:请查看已编辑的问题以及完整的错误详细信息。好吧,这只是一个疯狂的想法,是受保护的内部属性在扮演扰流器吗?可能是你的复制品是对的,这个对象可能是你的NRE的来源。但很有可能是受保护的二传手造成的。它们是不可序列化的。上面链接的问题对如何纠正这个问题有一些建议。@JoelEtherton:公认的答案建议使用
[XmlIgnore]
。那么,是否建议完全忽略该属性?