Water Cooler v2
Water Cooler v2

Reputation: 33880

Unable to resolve assembly Model.dll

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:

enter image description here

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.

Upvotes: 14

Views: 11506

Answers (3)

romanoza
romanoza

Reputation: 4862

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 the 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.

Upvotes: 8

Matas Vaitkevicius
Matas Vaitkevicius

Reputation: 61459

I have moved Ecom.edfx EF model to it's own folder (Ecom).
Check in Web.config/(app.config) if EF connection string generated has it's metadata set as following

<add name="EcomEntities" connectionString="metadata=res://*/Ecom.Ecom.csdl|res://*/Ecom.Ecom.ssdl|res://*/Ecom.Ecom.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;data source=****&quot;" providerName="System.Data.EntityClient" />

(Directory structure is done with .(dot) not /(slash)) like following res:///Ecom.Ecom.csdl (from being res:///Ecom.csdl while not in it's own folder).

Upvotes: 0

Amin Saqi
Amin Saqi

Reputation: 18977

I think the problem is from the EF ConStr. Usually, when you want to use an embedded resource, you should set the Metadata like the following:

Metadata=res://<assemblyFullName>/<resourceName>. 

You also can use the * wildcard instead of <assemblyFullName>. It causes the to search the following locations for the file at runtime:

  • The calling assembly.
  • The referenced assemblies.
  • The assemblies in the bin directory of an application.

More info is here

Upvotes: 1

Related Questions