Exception when using custom IContextProvider
johnduhart opened this issue · 3 comments
johnduhart commented
I have an IContextProvider
like so:
private class SchemaContextProvider : IContextProvider
{
public JToken GetContext(Type modelType)
{
return new JValue("http://schema.org");
}
}
1e02a27#diff-cc523edb5f4a1ba27289e9230dfe439eR62
Attempting to cast a JValue to a JToken is causing an exception. Stacktrace:
[ArgumentException: Target type Newtonsoft.Json.Linq.JToken is not a value type or a non-abstract class.
Parameter name: targetType]
Newtonsoft.Json.Utilities.ConvertUtils.Convert(Object initialValue, CultureInfo culture, Type targetType) +295
Newtonsoft.Json.Linq.JValueDynamicProxy.TryConvert(JValue instance, ConvertBinder binder, Object& result) +127
CallSite.Target(Closure , CallSite , Object ) +214
JsonLD.Entities.ContextResolver.GetContext(Object entity) in C:\projects\jsonld-entities\src\JsonLD.Entities\ContextResolver.cs:48
JsonLD.Entities.EntitySerializer.Serialize(Object entity, SerializationOptions options) in C:\projects\jsonld-entities\src\JsonLD.Entities\EntitySerializer.cs:93
johnduhart commented
Nevermind, this is resolved in a newer version of Newtonsoft.Json, JamesNK/Newtonsoft.Json@4c256e7
tpluscode commented
Hi. Thanks for reporting. Which version of Newtonsoft.Json were you using?
johnduhart commented
I was using 4.5 (I know, really old), so I just upgraded to 8.0.3 and it worked fine.