[已解决]请参阅我的回答
我有一个运行ASP.NET 5和EF7的项目。
我的EF模型在类库中,框架4.5.1。当我尝试与数据交互时,我有这个例外:文件" EntityFramework.Core.resources"不见了。但是当我将EF模型放入我的UI项目中时,它运行正常。 知道发生了什么事吗?是否可以将实体框架模型放在专用的类库中? (我总是这样做,但也许这个版本已经改变了)
这是包含我的EF7的DbContext的类库的package.config内容:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework.Commands" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Core" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.MicrosoftSqlServer" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.MicrosoftSqlServer.Design" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Relational" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Relational.Design" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="Ix-Async" version="1.2.5" targetFramework="net451" />
<package id="Microsoft.Extensions.Caching.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Caching.Memory" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Binder" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.OptionsModel" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Remotion.Linq" version="2.0.1" targetFramework="net451" />
<package id="System.Collections.Immutable" version="1.1.36" targetFramework="net451" />
<package id="System.Diagnostics.DiagnosticSource" version="4.0.0-beta-23516" targetFramework="net451" />
<package id="System.Diagnostics.Tracing" version="4.0.0" targetFramework="net451" />
<package id="System.Runtime" version="4.0.0" targetFramework="net451" />
<package id="System.Threading" version="4.0.0" targetFramework="net451" />
</packages>
StackTrace:
à System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark) à System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark) à System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
à System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
à System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
à System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
à System.Resources.ResourceManager.GetString(String name)
à Microsoft.Data.Entity.Internal.CoreStrings.GetString(String name, String[] formatterNames)
à Microsoft.Data.Entity.Internal.CoreStrings.LogExceptionDuringQueryIteration(Object newline, Object error)
à Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__181.<CompileQuery>b__18_3(Exception e) à Microsoft.Data.Entity.Extensions.Internal.CoreLoggerExtensions.<>c__DisplayClass0_01.b__0(Object _, Exception e)
à Microsoft.Extensions.Logging.Debug.DebugLogger.Log(LogLevel logLevel, Int32 eventId, Object state, Exception exception, Func3 formatter) à Microsoft.Extensions.Logging.Logger.Log(LogLevel logLevel, Int32 eventId, Object state, Exception exception, Func3 formatter)
答案 0 :(得分:1)
我终于找到了,它与这个问题相关: - https://github.com/aspnet/dnx/issues/3047 - https://github.com/aspnet/EntityFramework/issues/4422
这是一个dnx错误,但在我们等待修复时,您可以将其添加到您的启动配置方法中:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
var localizationOptions = new RequestLocalizationOptions()
{
SupportedCultures = new List<CultureInfo> { new CultureInfo("") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("") }
};
var invariantCulture = new RequestCulture(new CultureInfo(""), new CultureInfo(""));
app.UseRequestLocalization(localizationOptions, invariantCulture);
//...
}
答案 1 :(得分:0)
如果在使用 Microsoft.Extensions.Logging 记录异常时发生此错误,则该错误与 EntityFramework.Core.resources 无关,您有一个错误SQL异常(反对错误或其他)。