Guy E
Guy E

Reputation: 1927

"Unable to load the specified metadata resource" after building using dotnet build

After some conclusions, a more precise questions:

I have a .NET 4.0 project with Entity Framework v4 which uses an .edmx file. Let's call it EFProject and MyDB to the database accessed by Entity Framework.

This project is part of a solution that includes projects - some of them are new SDK projects files.

In the project file of the EFProject, I define the .edmx and Designer.cs files as EmbeddedResources:

<ItemGroup>
    <EmbeddedResource Include=MyDB.edmx" />
    <EmbeddedResource Include=MyDB.Designer.cs" />
</ItemGroup>

In the app.config, I added to the MyDB connection string, the .edmx file:

<add name="MyDBConnectionString" 
     connectionString="metadata=res=://*/MyDB.edmx|res://MyDB.csdl|...."

When building the solution in VS or with CLI command:

dotnet build

the solution builds with no errors.

When I'm looking "into" the EFProject dll (decompiling using dotPeek), I can see the resources of the .edmx and designer.cs files, but I dont see any csdl files. Should I see these also ?

BUT: when executing the application (after building by using dotnet build) and reaching the EFProject - I'm getting an error claiming:

Unable to load the specified metadata resource

I've tried other options: to build the project also separately - but still - it doesn't work.

Any ideas how can I solve this?

Upvotes: 0

Views: 46

Answers (1)

Andrew Narvaez
Andrew Narvaez

Reputation: 56

Large parts of my answers are generated from this blog and concerning discussion thread.

The cause of this error is a missing or malformed Entity Framework connection string. In particular, the cause of this error is the metadata parameter of the connection string.

So in your connectionString=metadata=res=://*/MyDB.edmx|res://MyDB.csdl|.... that basic format is

  1. res://: Indicates we're loading CSDL from a resource
  2. *: The name of the assembly which contains the resource. In your case you're omitting the name by using *, which is common!
  3. MyDb.edmx: The name of the resource itself

I'd ensure you're second connection string resource res://MyDb.csdl is properly calling an assembly version in this case.

Upvotes: 2

Related Questions