无法解析Assembly.dll的汇编 [英] Unable to resolve assembly Model.dll

查看:121
本文介绍了无法解析Assembly.dll的汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类库项目,使用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 =& quot;
数据源= MyComputer\sqlexpress;
初始目录= DaDatabase;
Integrated Security = true;
MultipleActiveResultSets = True& quot;
providerName =System.Data.EntityClient/>

(我在上面的代码段中包含换行符,仅用于可读性我的代码不现在我的解决方案结构如下所示:





但是,我得到一个 FileNotFound 异常在运行时读取:

 系统。 IO.FileNotFoundException被用户代码未处理
HResult = -2147024894
消息=无法解析程序集'Model.dll'。
Source = System.Data.Entity
StackTrace:
在System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.ResolveAssemblyName(String assemblyName,MetadataArtifactAssemblyResolver resolver)
在System.Data.Metadata .Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path,ExtensionCheck extensionCheck,String validExtension,ICollection`1 uriRegistry,MetadataArtifactAssemblyResolver resolver)
在System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path,ExtensionCheck extensionCheck,String validExtension, ICollection`1 uriRegistry,MetadataArtifactAssemblyResolver解析器)
在System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)
在System.Data.Common.Utils.Memoizer`2。<> c__DisplayClass2 。System.Data.Common.Utils.Memoizer`2.Evaluate(TArg)中的arg)
在系统。 Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
在System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
在System.Data.Objects.ObjectContext..ctor(EntityConnection连接,Boolean isConnectionConstructor)
在System.Data.Objects.ObjectContext..ctor(String connectionString,String defaultContainerName)
在Resources.BaseServices.Globalization.Models.ResourceGlobalizationEntities..ctor()在C:\SVN\Model\\ C:\SVN\Model\Culture.cs中的ResourcesResourceGlobalizationEntities.cs:第7行
在Resources.BaseServices.Globalization.Models.Culture.IsValidCulture(String shortName)行24
在资源C中的.BaseServices.Globalization.EntityFrameworkStringResourceLoader.set_CultureName(String value)在C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs:line 129
在Resources.BaseServices.Globalization.EntityFrameworkS C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs中的tringResourceLoader..ctor(String cultureName,IDataSource dataSource)行19
InnerException:

我尝试了2个客户端的场景,即一个控制台应用程序和一个MVC应用程序。



当控制台应用程序甚至不将 BusinessObjects.dll 及其引用的DLL,即 Model.dll 复制到控制台应用程序的 bin 目录,MVC应用程序。然而,他们似乎都没有找到 Model.dll 程序集,并提出上述 FileNotFoundException

解决方案

1)更改 res://Model.dll/ 到$ code> res:// Model / (不带'.dll'扩展名)在连接字符串的所有地方。您还可以指定程序集的全名,例如: res:// Model,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null / (更多信息: https://msdn.microsoft.com/en-us/library/cc716756的.aspx )。



2)接下来,确保以下命名空间有效: Model.Models.ResourceGlobalizationModel 。如果没有,请更改连接字符串和/或组合名称。


I had a class library project that used Entity Framework and it worked fine until I moved the model out to a separate class library type project.

After I moved the model out to a separate class library project called Model, I changed the connection string in the app/web.config to read as follows:

<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=&quot;
Data Source=MyComputer\sqlexpress;
Initial Catalog=DaDatabase;
Integrated Security=true;
MultipleActiveResultSets=True&quot;" 
providerName="System.Data.EntityClient" />

(I've included line breaks in the snippet above on purpose only for readability. My code does not have those line breaks.)

Now, my solution structure looks like this:

However, I get a FileNotFound exception at run-time that reads:

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: 

I tried the scenario with 2 clients, namely, a console app and an MVC app.

While the console app does not even copy BusinessObjects.dll and its referenced dlls, namely, the Model.dll to the console application's bin directory, the MVC app does. Yet, both of them seem not to find the Model.dll assembly at all, and raise the above-mentioned FileNotFoundException.

解决方案

1) Change res://Model.dll/ to res://Model/ (without the '.dll' extension) in all places in your connection string. You can also specify the full name of assembly, for example: res://Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/ (more info at: https://msdn.microsoft.com/en-us/library/cc716756.aspx).

2) Next, make sure that the following namespace is valid: Model.Models.ResourceGlobalizationModel. If not, change the connection string and/or the assembly name accordingly.

这篇关于无法解析Assembly.dll的汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆