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="
Data Source=MyComputer\sqlexpress;
Initial Catalog=DaDatabase;
Integrated Security=true;
MultipleActiveResultSets=True""
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With