C# 异常消息为';值不能为null。参数名称:propertyResourceType';

C# 异常消息为';值不能为null。参数名称:propertyResourceType';,c#,wcf,entity-framework-4.1,wcf-data-services,C#,Wcf,Entity Framework 4.1,Wcf Data Services,2011年3月刚刚安装WCF CTP2,并试图通过浏览器访问web服务。(http://localhost:99/Services/MyDataService.svc/) 我得到一个例外: **The server encountered an error processing the request. The exception message is 'Value cannot be null. Parameter name: propertyResourceType'. See server

2011年3月刚刚安装WCF CTP2,并试图通过浏览器访问web服务。(http://localhost:99/Services/MyDataService.svc/) 我得到一个例外:

**The server encountered an error processing the request. The exception message is 'Value cannot be null. Parameter name: propertyResourceType'. See server logs for more details.** The exception stack trace is:
at System.Data.Services.Providers.ResourceProperty..ctor(String name, ResourcePropertyKind kind, ResourceType propertyResourceType)
at System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMemberMetadata(ResourceType resourceType, IProviderMetadata workspace, IDictionary`2 knownTypes, PrimitiveResourceTypeMap primitiveResourceTypeMap)
at System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMetadata(IDictionary`2 knownTypes, IDictionary`2 childTypes, IDictionary`2 entitySets)
at System.Data.Services.Providers.BaseServiceProvider.LoadMetadata()
at System.Data.Services.DataService`1.CreateProvider()
at System.Data.Services.DataService`1.HandleRequest()
at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody)
at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
有什么帮助吗

更新。发现问题与此属性有关

 [Required]
    public byte TypeId { get; set; }

    public ContactInfoType Type
    {
        get
        {
            return (ContactInfoType)TypeId;
        }
        set
        {
            TypeId = (byte)value;
        }
    }
问题是WCF4中的一切都正常。但它在3月份的WCF CTP23中抛出了一个例外。 ContactInfoType-是一个枚举

[IgnoreProperties(“类型”)]无效

更新2。在调查一个问题后,发现在属性的setter部分引发了异常

  public ContactInfoType Type
    {
        set
        {
            TypeId = (byte)value;
        }
    }

这只是一个猜测,但可能是:

当实体数据模型包含具有属性的实体类型时 类型为DateTimeOffset的ADO.NET数据服务抛出未经处理的 这是一个例外。如果将属性类型更改为DateTime, 例外情况消失了


我在.NET 4.5 WCF数据服务(可能使用WCF数据服务5.0)中收到了相同的错误。升级到WCF Data Services 5.2.0(通过NuGet)后,我收到了更多有用的错误消息,指出问题属性,这是一个
enum
typed属性,如上所述

哇,枚举在WCF Data Services 5.2.0中仍然不受支持-这是这里投票最多的功能:(如果您关心它,请投票!)

目前有两种方法可以解决这个问题——一种是公开标量属性,并在enum属性上使用
[NotMapped]
属性,然后使用相同的单个值来支持它们。另一个选项是创建一个“类似枚举”的实体类来替换枚举类型,它还有一个额外的好处,即枚举值存储在数据库中。下面是一个例子:

public class Priority
{
    public Priority()
    {}

    protected Priority(short id, string name)
    {
        Id = id;
        Name = name;
    }

    public short Id { get; set; }
    public string Name { get; set; }

    public static readonly Priority Unknown = new Priority(0, "Unknown");
    public static readonly Priority Optional = new Priority(1, "Optional");
    public static readonly Priority Low = new Priority(2, "Low");
    public static readonly Priority Normal = new Priority(3, "Normal");
    public static readonly Priority High = new Priority(4, "High");
    public static readonly Priority Critical = new Priority(5, "Critical");
    public static readonly Priority Blocking = new Priority(6, "Blocking");
}

我的水晶球丢了。你能帮我发一些密码吗?我唯一能告诉您的是,您将
null
作为
propertyResourceType
传递给了
ResourceProperty
构造函数,而您不应该这样做。添加了web服务主体。我正试图通过在浏览器中打开它来访问此web服务。如果我参考WCF4,一切都很好。出现错误,然后我使用WCF4 CTP2 2011年3月2日