Unable to load the provided metadata resource? MetadataException

.net c# entity-framework


I have two pertinent tasks for a solution. The first creates My.exe, while the second creates MyModel.dll, a class library that just includes my EF model.

I'm receivingMetadataException VS-generated version of my modelObjectContext ctor. Despite reading Entity Framework Connection Strings Troubleshooting, I'm still unable to pinpoint the source of my issue.

The incorrect constructor code is:

public MyEntities() :
    base(@"name=MyEntities", "MyEntities") // MetadataException here
    this.ContextOptions.LazyLoadingEnabled = true;

Zzz-35-Zzz is scheduled toEmbedInOutputAssembly . When I launch Reflector and open MyModel.dll, I see:

  • DataAccessLayer.MyModel.csdl
  • DataAccessLayer.MyModel.msl
  • DataAccessLayer.MyModel.ssdl

I've tried changing my app.config's Develop Action toNone and Content , yet neither alters the situation. The configuration file includes:

<?xml version="1.0" encoding="utf-8" ?>
    <add name="MyEntities" 
            provider connection string=&quot;
                User Id=MY_USER;
                Persist Security Info=True&quot;"
         providerName="System.Data.EntityClient" />

I tried changing the resource prefix.res://*/ using bothres://MyModel.dll/ and res://MyModel/ , leaving the remainder unaltered (because it corresponds to the resources in MyModel.dll), but neither approach resolved the issue. It's strong-named in my class library.

Both my class library and executable projects have references toSystem.Data.Entity and Devart.Data.PostgreSql , and My.exe and My.dll are being constructed in the same spot.

10/10/2011 2:34:12 AM

Accepted Answer

I entered the source code for.NET and discovered that the resource assembly name was still set to by looking at the parameters and local variables of internal EF calls.* .

The default connection string for the model was set to before calling the model due to an error in my application code.ObjectContext ctor. It was taken from a Settings.settings file that wasn't currently in sync with the most recent, accurate app.config.

Observations on our conversation from the comments:

  • In the app.config file, the proper assembly name isMyModel instead ofMyModel.dll (As shown in Craig's post.)MyModel.dll causes the EF code to throw an error.

  • using the ctor's namebase(@"name=MyEntities") in place ofbase(@"name=MyEntities", "MyEntities") This fact generated a new exception inObjectContext.GetEntitySetName()

Now that Settings.settings and app.config are in harmony, everything is functional.

9/18/2011 5:28:25 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow