【问题标题】:The exception message is 'Value cannot be null. Parameter name: propertyResourceType'异常消息是“值不能为空。参数名称:propertyResourceType'
【发布时间】:2011-08-08 07:02:53
【问题描述】:

刚刚安装了 WCF CTP2 mar2011 并尝试通过浏览器访问 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 中一切正常。但它在 WCF CTP2march 中引发了异常。 ContactInfoType - 是一个枚举。

[IgnoreProperties("Type")] 无效。

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

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

【问题讨论】:

  • 我的水晶球丢了。你能发布一些代码吗?我唯一能告诉你的是,你不应该将null 作为propertyResourceType 传递给ResourceProperty 构造函数。
  • 对此感到抱歉。添加了 Web 服务主体。我只是试图通过在浏览器中打开它来访问这个网络服务。

标签: c# wcf entity-framework-4.1 wcf-data-services


【解决方案1】:

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

哇,WCF 数据服务 5.2.0 中仍然不支持枚举 - 它是此处投票最多的功能:http://data.uservoice.com/forums/72027-wcf-data-services-feature-suggestions(如果您关心它,请投票!)

目前有两种解决方法 - 一种是公开一个标量属性并在枚举属性上使用[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");
}

【讨论】:

    【解决方案2】:

    只是一个疯狂的猜测,但它可能是this issue

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

    【讨论】:

    • 如果我参考 WCF4,一切都很好。出现错误然后我使用 WCF4 CTP2 March2011
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2010-12-02
    • 2019-12-15
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多