我像这样初始化我的RavenDB DocumentStore:
void InitializeDocumentStore( string address )
{
_documentStore = new DocumentStore()
{
Conventions =
{
FindTypeTagName = type =>
{
if ( typeof( IUser ).IsAssignableFrom( type ) )
return "IUser";
return DocumentConvention.DefaultTypeTagName( type );
}
}
};
_documentStore.ParseConnectionString( "Url = " + address );
_documentStore.Initialize();
LoadStore();
}
并加载如下文档:
void LoadStore()
{
using (var session = _documentStore.OpenSession("storename"))
{
var userResult = from user in session.Query<IUser>()
where user.BaseType == typeof(IUser).Name
select user;
foreach (var entry in userResult)
{
users.AddOrUpdate(entry.Id, entry, (key, oldValue) => entry != null ? entry : null);
}
}
}
这一直工作好几周,直到我今天清理了我的项目(因为XAML),现在我在尝试循环userResults时收到此异常:
A first chance exception of type 'Raven.Imports.Newtonsoft.Json.JsonSerializationException' occurred in Raven.Abstractions.dll
A first chance exception of type 'Raven.Imports.Newtonsoft.Json.JsonSerializationException' occurred in Raven.Abstractions.dll
A first chance exception of type 'Raven.Imports.Newtonsoft.Json.JsonSerializationException' occurred in Raven.Client.Lightweight.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>SmartWard.Whiteboard.vshost.exe</AppDomain><Exception><ExceptionType>Raven.Imports.Newtonsoft.Json.JsonSerializationException, Raven.Abstractions, Version=2.0.3.0, Culture=neutral, PublicKeyToken=37f41c7f99471593</ExceptionType><Message>Could not create an instance of type ABC.Model.Users.IUser. Type is an interface or abstract class and cannot be instantated. Path 'RoomNumber'.</Message><StackTrace> at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean&amp; createdFromNonDefaultConstructor) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1275
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 353
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 229
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 155
at Raven.Imports.Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 546
at Raven.Imports.Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 512
at Raven.Client.Connection.DocumentConventionJsonExtensions.Deserialize[T](RavenJObject self, DocumentConvention convention) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\DocumentConventionJsonExtensions.cs:line 22
at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity[T](String id, RavenJObject documentFound, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 450
at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T](String key, RavenJObject document, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 368
at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 153
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 135
at Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:line 753
at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryInspector.cs:line 100
at ABC.Infrastructure.ActivityBase.ActivitySystem.LoadStore() in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 246
at ABC.Infrastructure.ActivityBase.ActivitySystem.InitializeDocumentStore(String address) in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 104
at ABC.Infrastructure.ActivityBase.ActivitySystem.Run(String storeAddress) in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 308
at SmartWard.Infrastructure.WardNode.StartClientAndSystem() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 263
at SmartWard.Infrastructure.WardNode.StartNode() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 228
at SmartWard.Infrastructure.WardNode..ctor(WardNodeConfiguration configuration, WebConfiguration webConfiguration) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 221
at SmartWard.Infrastructure.WardNode.StartWardNodeAsSystem(WebConfiguration webConfiguration) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 211
at SmartWard.Whiteboard.ViewModels.BoardViewModel..ctor() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\ViewModels\BoardViewModel.cs:line 77
at SmartWard.Whiteboard.App.OnStartup(StartupEventArgs e) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\App.xaml.cs:line 16
at System.Windows.Application.&lt;.ctor&gt;b__1(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at SmartWard.Whiteboard.App.Main() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\obj\Release\App.g.cs:line 50
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>Raven.Imports.Newtonsoft.Json.JsonSerializationException: Could not create an instance of type ABC.Model.Users.IUser. Type is an interface or abstract class and cannot be instantated. Path 'RoomNumber'.
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean&amp; createdFromNonDefaultConstructor) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1275
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 353
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 229
at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 155
at Raven.Imports.Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 546
at Raven.Imports.Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in c:\Builds\RavenDB-Stable\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 512
at Raven.Client.Connection.DocumentConventionJsonExtensions.Deserialize[T](RavenJObject self, DocumentConvention convention) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\DocumentConventionJsonExtensions.cs:line 22
at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity[T](String id, RavenJObject documentFound, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 450
at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T](String key, RavenJObject document, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 368
at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 153
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 135
at Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:line 753
at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryInspector.cs:line 100
at ABC.Infrastructure.ActivityBase.ActivitySystem.LoadStore() in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 246
at ABC.Infrastructure.ActivityBase.ActivitySystem.InitializeDocumentStore(String address) in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 104
at ABC.Infrastructure.ActivityBase.ActivitySystem.Run(String storeAddress) in c:\Users\Pitlab\Documents\GitHub\ABC\ABC\ABC.Infrastructure\ActivityBase\ActivitySystem.cs:line 308
at SmartWard.Infrastructure.WardNode.StartClientAndSystem() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 263
at SmartWard.Infrastructure.WardNode.StartNode() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 228
at SmartWard.Infrastructure.WardNode..ctor(WardNodeConfiguration configuration, WebConfiguration webConfiguration) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 221
at SmartWard.Infrastructure.WardNode.StartWardNodeAsSystem(WebConfiguration webConfiguration) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard\Infrastructure\WardNode.cs:line 211
at SmartWard.Whiteboard.ViewModels.BoardViewModel..ctor() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\ViewModels\BoardViewModel.cs:line 77
at SmartWard.Whiteboard.App.OnStartup(StartupEventArgs e) in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\App.xaml.cs:line 16
at System.Windows.Application.&lt;.ctor&gt;b__1(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at SmartWard.Whiteboard.App.Main() in c:\Users\Pitlab\Documents\GitHub\SmartWard\SmartWard.Whiteboard\obj\Release\App.g.cs:line 50
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</ExceptionString><DataItems><Data></Data></DataItems></Exception></TraceRecord>
我完全不解为什么在干净之后完全相同的代码停止工作,我不知道从哪里开始调试它。有什么想法吗?
答案 0 :(得分:2)
看一下TraceRecord(第4行);它包含特定的序列化程序例外:
<Message>Could not create an instance of type ABC.Model.Users.IUser. Type is an interface or abstract class and cannot be instantated. Path 'RoomNumber'.</Message><StackTrace>