RavenDB + ASP.Net MVC Beta 4 WebApi + JSON.Net run time error - Raven.Json.Linq.RavenJTokenReader.ReadAsString not implemented

776 views
Skip to first unread message

mello702

unread,
Mar 29, 2012, 5:49:21 AM3/29/12
to ravendb
Hello

Didn't see any other references to this error, hope this is the right
forum to present it in. If it's unhelpful or unrelated, my apologies
in advance. I'm not sure that this is an issue within Raven itself or
if it even needs to be addressed but wanted to share in case someone
else runs across the same problem.

I'm experimenting with RavenDB 1.0.701 in an Asp.Net MVC 4 Beta WebApi
site. It works great, but I've ran into an issue after attempting to
change out the default JSON serializer for the MVC app with JSON.Net
4.0.8.

Method 'ReadAsString' in type 'Raven.Json.Linq.RavenJTokenReader' from
assembly 'Raven.Abstractions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=37f41c7f99471593' does not have an implementation.

Stack Trace:

[TypeLoadException: Method 'ReadAsString' in type
'Raven.Json.Linq.RavenJTokenReader' from assembly 'Raven.Abstractions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593'
does not have an implementation.]
System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly
assembly, ObjectHandleOnStack retTypes) +0
System.Reflection.RuntimeAssembly.GetExportedTypes() +122

System.Web.Http.Dispatcher.HttpControllerTypeCacheUtil.FilterTypesInAssemblies(IBuildManager
buildManager, Predicate`1 predicate) +210

System.Web.Http.Dispatcher.HttpControllerTypeCacheUtil.GetFilteredTypesFromAssemblies(String
cacheName, Predicate`1 predicate, IBuildManager buildManager) +65

System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()
+83

System.Web.Http.Dispatcher.HttpControllerTypeCache..ctor(HttpConfiguration
configuration) +69

System.Web.Http.Services.DefaultServiceResolver.<.ctor>b__0(HttpConfiguration
config) +279
System.Web.Http.Services.DefaultServiceResolver.GetService(Type t)
+80

System.Web.Http.DependencyResolverExtensions.GetService(DependencyResolver
resolver) +201

System.Web.Http.DependencyResolverExtensions.GetServiceOrThrow(DependencyResolver
resolver) +60

System.Web.Http.Dispatcher.HttpControllerDispatcher..ctor(HttpConfiguration
configuration) +65
System.Web.Http.GlobalConfiguration.<.cctor>b__1() +127
System.Lazy`1.CreateValue() +12776623
System.Lazy`1.LazyInitValue() +355
System.Web.Http.WebHost.HttpControllerHandler.<.cctor>b__b() +53
System.Lazy`1.CreateValue() +12776623
System.Lazy`1.LazyInitValue() +355

System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase
httpContextBase, AsyncCallback callback, Object state) +256

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+405
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +375

This was caused by adding the following snippet code to my
application_start (as well as the supporting class
"JsonNetFormatter"):


// Create Json.Net formatter serializing DateTime using
the ISO 8601 format
JsonSerializerSettings serializerSettings = new
JsonSerializerSettings();
serializerSettings.Converters.Add(new
IsoDateTimeConverter());
GlobalConfiguration.Configuration.Formatters[0] = new
JsonNetFormatter(serializerSettings);

The exact code and explanation for adding it can be found here:

http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx.

Essentially this is a work around to replace the built in JSON
formatter in MVC Beta 4 with the JSON.Net formatter to correct date
time formatting issues that, in my case, are causing problems with
jQuery week calendar.

From what I understand, MVC 4 WebApi will use JSON.Net as the default
serializer after it leaves beta.

Any suggestions for a quick fix?

Thanks and keep up the great work, I like what I see so far!

Oren Eini (Ayende Rahien)

unread,
Mar 29, 2012, 5:52:37 AM3/29/12
to rav...@googlegroups.com
You have mismatched versions between what RavenDB excepts and what the WebAPI expect, I guess.
Make sure to use the RavenDB version and to do a binding redirect in the config file

mello702

unread,
Mar 29, 2012, 6:01:36 AM3/29/12
to ravendb
The solution I found was to remove these lines from the Web.Config:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0"
newVersion="4.5.0.0" />
</dependentAssembly>

Which were added during the NuGet process for JSON.Net.

Korayem

unread,
Apr 24, 2012, 9:21:12 AM4/24/12
to rav...@googlegroups.com
In my case, json.net package dll wasnt referenced. HTH
Reply all
Reply to author
Forward
0 new messages