无法解析组件Model.dll组件、Model、dll

2023-09-04 08:53:41 作者:狙神猛禽ベΔ

我有一个类库项目,用于实体框架和它工作得很好,直到我把模型出一个单独的类库类型的项目。

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.

在我提出的模型出来一个单独的类库项目名为型号,我改变了连接字符串中的应用程序/ web.config文件,内容如下:

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" />

我已经包含在上面只为便于阅读的目的片段换行符。我的code没有这些换行符。

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:

不过,我得到一个 FileNotFound 例外,在运行时,上面写着:

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: 

我试过方案有2个客户,即一个控制台应用程序和一个MVC应用程序。

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

虽然控制台应用程序甚至不复制BusinessObjects.dll及其中引用的DLL,即Model.dll到控制台应用程序的bin目录,MVC应用程序一样。然而,他们两人似乎并没有找到Model.dll组装可言,并提高上述 FileNotFoundException异常

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)更改 RES://Model.dll/ 水库: //型号/ (不带.DLL的一部分)在连接字符串的所有地方。您还可以指定程序集的全名,例如: RES://型号,版本= 1.0.0.0,文化=中性公钥=空/ (更多的信息: https://msdn.microsoft.com/en-us/library/cc716756。 ASPX )。

1) Change res://Model.dll/ to res://Model/ (without the '.dll' part) 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)接下来,请确保以下命名空间是有效的: Model.Models.ResourceGlobalizationModel 。如果不是这样,相应地更改连接字符串和/或组件的名称。

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