异常消息为'Value不能为空.参数名称:propertyResourceType'

本文关键字:propertyResourceType 参数 Value 消息 异常 不能 | 更新日期: 2023-09-27 18:04:51

刚刚安装了WCF CTP2 mar2011,试图通过浏览器访问web服务。(http://localhost: 99/服务/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中一切都很好。但是它在WCF CTP2march中抛出了一个异常。ContactInfoType -为enum。

[IgnoreProperties("Type")]不起作用。

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

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

异常消息为'Value不能为空.参数名称:propertyResourceType'

我在。net 4.5 WCF数据服务服务(大概使用WCF数据服务5.0)中收到了相同的错误。在升级到WCF Data Services 5.2.0(通过NuGet)之后,我收到了更多有用的错误消息,这些错误消息指向了问题属性,这是一个enum类型的属性,与上面相同。

哇,WCF数据服务5.2.0仍然不支持枚举-这是投票最多的特性:http://data.uservoice.com/forums/72027-wcf-data-services-feature-suggestions(如果你关心它就投票!)

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

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");
}

随便猜一下,可能是这个问题吧:

当实体数据模型包含具有属性的实体类型时类型为DateTimeOffset的ADO。. NET数据服务抛出未处理的ArgumentNullException。如果将属性类型更改为DateTime,异常消失。

相关文章:
  • 没有找到相关文章