我有一个使用 Entity Framework 的类库项目,它运行良好,直到我将模型移到单独的类库类型项目中。
将模型移出到名为 Model 的单独类库项目后,我将 app/web.config 中的连接字符串更改为如下所示:
<add name="GlobalizationEntities"
connectionString="metadata=res://Model.dll/Models.ResourceGlobalizationModel.csdl|
res://Model.dll/Models.ResourceGlobalizationModel.ssdl|
res://Model.dll/Models.ResourceGlobalizationModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=MyComputer\sqlexpress;
Initial Catalog=DaDatabase;
Integrated Security=true;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
(我在上面的代码片段中包含换行符只是为了便于阅读。我的代码没有这些换行符。)
现在,我的解决方案结构如下所示:
但是,我FileNotFound
在运行时收到一个异常,内容如下:
System.IO.FileNotFoundException was unhandled by user code
HResult=-2147024894
Message=Unable to resolve assembly 'Model.dll'.
Source=System.Data.Entity
StackTrace:
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.ResolveAssemblyName(String assemblyName, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)
at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
at System.Data.Common.Utils.Memoizer`2.Result.GetValue()
at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
at Resources.BaseServices.Globalization.Models.ResourceGlobalizationEntities..ctor() in C:\SVN\Model\ResourceGlobalizationEntities.cs:line 7
at Resources.BaseServices.Globalization.Models.Culture.IsValidCulture(String shortName) in C:\SVN\Model\Culture.cs:line 24
at Resources.BaseServices.Globalization.EntityFrameworkStringResourceLoader.set_CultureName(String value) in C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs:line 129
at Resources.BaseServices.Globalization.EntityFrameworkStringResourceLoader..ctor(String cultureName, IDataSource dataSource) in C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs:line 19
InnerException:
我尝试了 2 个客户端的场景,即一个控制台应用程序和一个 MVC 应用程序。
虽然控制台应用程序甚至不会复制BusinessObjects.dll
其引用的 dll,即复制Model.dll
到控制台应用程序的bin
目录,但 MVC 应用程序会。然而,他们两个似乎根本没有找到Model.dll
大会,并提出了上述问题FileNotFoundException
。