问题
[SOLVED] see my answer
I have a project running with ASP.NET 5 and EF7.
I have my EF model in a class library, framework 4.5.1. When I try to interact with data, I have this exception : the file "EntityFramework.Core.resources" is missing. But when I put the EF model in my UI project, it works fine. Any idea what's going on ? Is it possible to have the entity framework model in a dedicated class library ? (I always did this way but maybe it has changed with this version)
This is the package.config's content of the class library who contains my EF7's DbContext :
<?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>
And the 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)
回答1:
I finally found, it's relative to this issues : - https://github.com/aspnet/dnx/issues/3047 - https://github.com/aspnet/EntityFramework/issues/4422
It's a dnx bug but while we waiting for a fix, you can add this to your Startup's Configure method :
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);
//...
}
回答2:
If this error happens during the log of an exception with Microsoft.Extensions.Logging, the error has nothing to do with EntityFramework.Core.resources, you have an SQL exception (contrainst error, or something).
来源:https://stackoverflow.com/questions/35147284/entity-framework-7-error-entityframework-core-resources-is-missing-7-0-0-rc