Entity Framework - Unable to load the specified me

2019-02-04 01:27发布

I realise that this has been asked a number of times but I just can't seem to get the bottom of my issue. I'm getting the following error stack:

enter image description here

When I reflect out my dll I can see the following

enter image description here

Reading http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ it suggests I'd expect to see the csdl, msl and ssdl files here, but they're not. They do exist here obj\Debug\edmxResourcesToEmbed though.

Never-the-less I tried to explicitly tell the web.config where to look by doing this:

...connectionString="metadata=res://DllName.dll/PaymentModel.csdl|res://DllName.dll/PaymentModel.ssdl|res://DllName.dll/PaymentModel.msl;provider=System.Data.SqlClient;provider ... />

Which just throws an error saying it cannot find the dll:

Unable to resolve assembly 'DllName.dll'.

Very similar to this unresolved SO question Unable to resolve assembly Model.dll

The final thing I tried was to change the metadata line to:

...connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider ... />

This threw a message about sql ce which I'm not using - is there a way to get round this??

enter image description here

Is there anything else I can try? Or can anyone see where I'm going wrong? Some extra detais:

  • Using EF 6 EDMX set to "Embedded Resource"

  • Copy to output directory:"Do not copy"

  • Metadata artifact processing: "Embed in output assembly"

Finally on this - if I set the EDMX from Embedded Resource to EntityDeploy then this will work locally but not build on the build server as it throws the exact same error as this SO question:

Could not find the Conceptual Schema node to embed as a resource for input file

But the fix doesn't seem to help and I can't install .NET 4.5 on the server unfortunately.

16条回答
够拽才男人
2楼-- · 2019-02-04 01:57

I have used EF6 in my visual studio 2013. I have solved this by doing the following steps.

  • Right click on the Entity model
  • Open with XML(Text) editor
  • in tag set ProviderManifestToken="2008"
  • build solution

Hope it works for you..

查看更多
成全新的幸福
3楼-- · 2019-02-04 01:58

you should specify the assembly fully qualified name and a path to your model file within it(separated by /), not the dll name

connectionString="metadata=res://Name.Of.The.Assembly, Culture=neutral, PublicKeyToken=8e2e51fcf4cf363e/Payment.PaymentModel.csdl|.........."

the same for ssdl and msl

查看更多
该账号已被封号
4楼-- · 2019-02-04 01:59

I want to share my experience on this and how I solved it. In my case it happens because I copy and pasted my connection string on production server. My application was using Entity framework.

Problem was on metadata

I named my entity model as 'BetModel' but on my connection string I was using 'Entity' - 'res:///Entity.csdl|res:///Entity.ssdl|res://*/Entity.msl' on 'metadata' (reason was because i copy pasted it).

So my wrong ConnectionString was:

connectionString="metadata=res://*/Entity.csdl|res://*/Entity.ssdl|res://*/Entity.msl;provider=System.Data.SqlClient;provider connection string="data source=;initial catalog=;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework""

and the corrected ConnectionString was:

<add name="BetEntities" connectionString="metadata=res://*/BetModel.csdl|res://*/BetModel.ssdl|res://*/BetModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
查看更多
不美不萌又怎样
5楼-- · 2019-02-04 02:00

If you're using the dotnet CLI

For newer visitors using the new dotnet build tooling to build Entity Framework 6.x based projects, know that it currently does NOT embed any metadata into the final build. So if you run from within VS it'll run, but if your CI scripts use dotnet then they will fail on the server until you switch back to msbuild. IMHO, this is a bug and the tools should handle this. You can chime on the GitHub thread if needed.

查看更多
登录 后发表回答