You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come across some odd behaviour which is as much about our specific OData setup as it is a problem in the library, but I just wanted to note it here for our future reference and for the benefit of anyone searching for this error message.
Our client has a simple search using a c# Enum:
namespace Enums
{
public enum FooStatus
{
Published = 1,
Draft = 2,
Deleted = 3
}
}
Simple.OData.Client.UnresolvableObjectException: Type [FooStatus] not found
at Simple.OData.Client.V4.Adapter.Metadata.GetQualifiedTypeName(String typeName)
at Simple.OData.Client.Adapter.MetadataCache.<GetQualifiedTypeName>b__37_0(String x)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Simple.OData.Client.Adapter.MetadataCache.GetQualifiedTypeName(String typeOrCollectionName)
at Simple.OData.Client.V4.Adapter.CommandFormatter.ConvertValueToUriLiteral(Object value, Boolean escapeDataString)
at Simple.OData.Client.ODataExpression.FormatValue(ExpressionContext context)
at Simple.OData.Client.ODataExpression.FormatToStringFunction(ExpressionContext context)
at Simple.OData.Client.ODataExpression.FormatFunction(ExpressionContext context)
at Simple.OData.Client.ODataExpression.Format(ExpressionContext context)
at Simple.OData.Client.ODataExpression.FormatExpression(ODataExpression expr, ExpressionContext context)
at Simple.OData.Client.ODataExpression.Format(ExpressionContext context)
at Simple.OData.Client.ResolvedCommand.ResolveFilter(FluentCommandDetails details)
at Simple.OData.Client.ResolvedCommand..ctor(FluentCommand command, ISession session)
at Simple.OData.Client.FluentCommand.Resolve(ISession session)
at Simple.OData.Client.BoundClient`1.FindEntriesAsync(ODataFeedAnnotations annotations, CancellationToken cancellationToken)
Digging into this I've discovered that because we're using a C# Enum in our client code, the library assumes that we've also got an Enums in our OData service. In fact the OData service we're calling defines this column as a string, so in the example above we'd want the filter to be FooStatus eq "Published".
public class CommandFormatter : CommandFormatterBase
{
public override string ConvertValueToUriLiteral(object value, bool escapeDataString)
{
var type = value?.GetType();
if (value != null && _session.TypeCache.IsEnumType(type))
{
value = new ODataEnumValue(value.ToString(), _session.Metadata.GetQualifiedTypeName(type.Name));
}
...
}
}
IsEnumType checks if we have a c# enum.
Metadata.GetQualifiedTypeName looks up the name of the OData Enum.
Fix for us will be to use a string in our client code, instead of the c# enum.
The text was updated successfully, but these errors were encountered:
I've come across some odd behaviour which is as much about our specific OData setup as it is a problem in the library, but I just wanted to note it here for our future reference and for the benefit of anyone searching for this error message.
Our client has a simple search using a c# Enum:
This results in the following error:
Digging into this I've discovered that because we're using a C# Enum in our client code, the library assumes that we've also got an Enums in our OData service. In fact the OData service we're calling defines this column as a string, so in the example above we'd want the filter to be
FooStatus eq "Published"
.The relevant library code is:
IsEnumType checks if we have a c# enum.
Metadata.GetQualifiedTypeName looks up the name of the OData Enum.
Fix for us will be to use a string in our client code, instead of the c# enum.
The text was updated successfully, but these errors were encountered: