MetadataException: Unable to load the specified metadata resource

This exception occurs when the project cannot use the connection string to locate the 3 parts of EDMX: csdl, msl, and ssdl.

Troubleshooting steps:

  1. Find the right configuration file.  Review the configuration file of the executing assembly.  For example, if you are running a unit test project which references another project with edmx, you should look at the unit test project’s app.config file.  You should add an app.config file to your unit test project if necessary.
  2. Verify that your executing project (i.e. unit test project) references an assembly containing the 3 parts of EDMX.  This is especially true if you are doing POCO.  It is the project that you added the item “ADO.NET Entity Data Model”.  To verify, use a 3rd party tool (e.g. ILSpy) to examine the assembly inside; you should see the resources containing the 3 parts of EDMX.  image Note: Your project may compile fine without it, but you need it at run time.
  3. Make sure you have a reference to the entity framework dll.
  4. Try different ways of configuring the connection string:
      The standard/default connection is probably not working for you or else you won’t be reading this. 

         1: <connectionStrings>

         2:   <add name="xxxxEntities" connectionString="metadata=

         3:     res://*/Modelxxxx.csdl|

         4:     res://*/Modelxxxx.ssdl|

         5:     res://*/Modelxxxx.msl;

         6:     provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=xxxxDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

         7: </connectionStrings>

    1. The safest way is to specify the fully qualified assembly name of your EMDX project in your connection string. 
         1: <connectionStrings>

         2:   <add name="xxxxEntities" 

         3:     connectionString="metadata=

         4:         res://LA.Infrastructure.xxxxAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/Modelxxxx.csdl|

         5:         res://LA.Infrastructure.xxxxAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/Modelxxxx.ssdl|

         6:         res://LA.Infrastructure.xxxxAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/Modelxxx.msl;

         7:         provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=xxxxDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

         8: </connectionStrings>

    2. The last resort is use an asterisk.  This may get you past the error “unable to load the specified meta resource.”  However, you may get some other error “The entity type is not part of the model for the current context” when you access the entity object within the model.
         1: <connectionStrings>

         2:   <add name="xxxxEntities" connectionString="metadata=

         3:     res://*/;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=WinDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

         4: </connectionStrings>

Note:

If you have the edmx in one project and the xxxx.Context.tt in another project, then you probably need to use approach A for your unit testing project’s connection string to point to the project with .edmx file.

If you have both edmx and xxxx.Context.tt in the same project, then your unit testing project’s default connection string should work.

References:

http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

http://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource

Advertisements

One thought on “MetadataException: Unable to load the specified metadata resource

  1. Option A having separate project as stated in your note. This option fixed my issue. I also needed to add a reference to the .edmx project dll to the executing project. Thanks -Russ.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s