DevForce 2012 7.2.2, EF 5, Silverlight, C#, VS2012
Entity property of type System.DayOfWeek
, erroring (full error messages below) that it needs to be added to the list of known types when trying to update/save a change of this property to a different value.
Seems odd, considering it's a System Enumerable, and it's listed as a specific example that can be used in the DevForce documentation (http://drc.ideablade.com/devforce-2012/bin/view/Documentation/enum-types)
So I created an IKnownTypeProvider
and added DayOfWeek
as an entry:
public class LwKnownTypeProvider : IKnownTypeProvider
{
public IEnumerable<Type> AddKnownTypes()
{
var list = new Type[]
{
typeof (DayOfWeek)
};
return list;
}
}
For fun, I also tried being a bit more specific, in case there was somewhere the tools were getting confused (replace DayOfWeek
with System.DayOfWeek
throughout), but this yielded the same results.
Things I've checked:
IKnownTypeProvider
being found? Breakpoints successfully being hitvar lstKnownTypes = IdeaBlade.EntityModel.KnownTypeHelper.GetServiceKnownTypes(null);
)Inherited code, so maybe I'm overlooking something, but I'm not seeing it.
Error saving changes prior to adding the IKnownTypeProvider:
Type 'System.DayOfWeek' with data contract name DayOfWeek:http://schemas.datacontract.org/2005/07/system' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute or by adding them to the list of known types passed to DataContractSerializer
Error after adding the IKnownTypeProvider
listed above:
The formatter thew an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ideablade.com/EntityModel:workState. The InnerException message was 'Element 'ideablade.com/EntityModel:OriginalValue' contains data from a type that maps to the name 'http://schemas.datacontract.org/2005/07/System:DayOfWeek'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'DayOfWeek' to the list of known types - for example, by adding the KnownTypeAttribute attribute or by adding it to the list of known types pased to DataContractSerializer.'. Please see InnerException for more details.
This appears to be a bug with how the enum types are handled during an update when these changed properties are part of the original values passed to the server. The workaround for now is to implement your IKnownTypeProvider on both client and server.