Reputation: 2100
just installed WCF CTP2 mar2011 and trying to access web service through browser. (http://localhost:99/Services/MyDataService.svc/) I get this exception:
**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)
Any help?
Update.Found out that problem is related with this property
[Required]
public byte TypeId { get; set; }
public ContactInfoType Type
{
get
{
return (ContactInfoType)TypeId;
}
set
{
TypeId = (byte)value;
}
}
Interresting thing is that everything is ok in WCF4. But it throws an exeption in WCF CTP2march. ContactInfoType - is an enum.
[IgnoreProperties("Type")] makes no effect.
Update2. After investigating a problem found out that exception thrown in the setter part of the property.
public ContactInfoType Type
{
set
{
TypeId = (byte)value;
}
}
Upvotes: 2
Views: 6452
Reputation: 11211
I received the same error in a .NET 4.5 WCF Data Services service (presumably using WCF Data Services 5.0). After upgrading to WCF Data Services 5.2.0 (via NuGet) I received more helpful error messages that pointed me to the problem property, which was an enum
typed property, same as above.
Wow, enums are still not supported in WCF Data Services 5.2.0 - it's the most voted for feature here: http://data.uservoice.com/forums/72027-wcf-data-services-feature-suggestions (vote if you care about it!)
There are currently two options for working around this - one is to expose a scalar property and use the [NotMapped]
attribute on the enum property, and back them with the same single value. The other option is to create an "enum-like" entity class that replaces the enum type, which has the added benefit that the enum values are stored in the DB. Here's an example:
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");
}
Upvotes: 3
Reputation: 49260
Just a wild guess, but could it be this issue:
When an Entity Data Model contains an entity type that has a property of type DateTimeOffset, an ADO.NET Data Service throws an unhandled ArgumentNullException. If you change the property type to DateTime, the exception goes away.
Upvotes: 2