【发布时间】:2013-10-21 14:59:24
【问题描述】:
在 EmbeddableDocumentStore 类上调用 Initialize 时遇到一个非常令人沮丧的错误。这是一个 WPF 应用程序,它试图在 c:\temp\ravenDb 启动或初始化 RavenDB 数据库。
我的代码是:
EmbeddableDocumentStore _documentStore = new EmbeddableDocumentStore()
{
DataDirectory = @"C:\temp\RavenDb"
};
using (_documentStore.Initialize())
{
}
相当简单。错误发生在调用 Initialize() 时。这是完整的错误:
Microsoft.Isam.Esent.Interop.EsentFileNotFoundException occurred
Message=File not found
Source=Esent.Interop
StackTrace:
at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:line 2736
InnerException:
令人沮丧的是,当我创建一个新的 WPF 应用程序并复制相同的代码时,它可以正常工作,并且能够初始化和创建基本文件。然后,当我回到我的主 WPF 应用程序时 - 数据库现在能够初始化(因为文件已创建),但任何 Session.Query 调用都会导致以下错误:
System.IO.FileNotFoundException occurred
Message=segments.gen
Source=Lucene.Net
StackTrace:
at Lucene.Net.Store.RAMDirectory.OpenInput(String name) in z:\Libs\lucene.net\src\core\Store\RAMDirectory.cs:line 301
InnerException:
编辑: 完整代码: 它是从后台工作人员委托中调用的:
private void RefreshGrid()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync(_domainType);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = EventStoreInstance.Instance.GetAggregateRoots((Type)e.Argument);
}
然后调用 GetAggregateRoots:
//Called in class ctor:
_publisher = publisher;
_documentStore = new EmbeddableDocumentStore()
{
DataDirectory = _dataDir // is "C:\temp\RavenDb"
};
public List<AggregateRootModel> GetAggregateRoots(Type AggregrateRootType)
{
using (_documentStore.Initialize())
{
using (var session = _documentStore.OpenSession())
{
var aggregateRoots = session.Query<AggregateRootModel>()
.Where(p => p.Type == AggregrateRootType.AssemblyQualifiedName).ToList();
return aggregateRoots;
}
}
}
【问题讨论】:
-
如果您在创建新的 WPF 应用程序时复制代码并且它在我看来听起来像是在您的 .config 文件中可能有问题......您是否使用 .config 文件来读取任何 WPF偶然设置..?
-
不,我的配置文件中没有任何内容。此外,当我的主 WPF 项目中的初始化方法发生故障时,它已成功创建 3 个文件夹:日志、系统和临时。
-
如果可能的话,您能否显示主 wpf 中的代码?您可能会忽略某些内容...
-
而你的 Initialize 只是一个空的构造函数..?还是您遗漏了代码..?
-
_documentStore.Initialize() 不接受任何参数。