无法加载指定的元数据资源 [英] Unable to load the specified metadata resource

查看:112
本文介绍了无法加载指定的元数据资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试了许多提供的选项: MetadataException:无法加载指定的元数据资源和着名的Craig Stuntz的博客发布位于: http://blogs.teamb.com/craigstuntz/2010 / 08/13/38628 /



为简洁起见,我有3个项目:



Funscribe.Data(位于这里的EDMX文件)



Funscribe.Console(控制台应用程序)



Funscribe.Web (MVC 3应用程序)



最初只是MVC应用程序,我最近添加了这个新的控制台项目。



我复制了web.config中的连接字符串并将其应用到我的app.config:

 < add na me =FundirectoryEntitiesconnectionString =metadata = res://*/Fundirectory.csdl | res://*/Fundirectory.ssdl | res://*/Fundirectory.msl; provider = System.Data.SqlClient; provider connection string =& quot; data source = localhost\sqlexpress; initial catalog = Funscribe; user id = sys_Funscribe; password = blah; multipleactiveresultsets = True; application name = EntityFramework& quot; providerName =System.Data.EntityClient/> 

我的mvc应用程序继续工作,但是当我运行控制台应用程序时,我感到恐惧: / p>

无法加载指定的元数据资源。



我尝试更改连接字符串到通配符设置:

 < add name =FundirectoryEntitiesconnectionString =metadata = res:// * /;provider=System.Data.SqlClient;provider connection string =& quot; data source = localhost\sqlexpress; initial catalog = Funscribe; user id = sys_Funscribe; password = blah; multipleactiveresultsets = True; application name = EntityFramework& quot ; providerName =System.Data.EntityClient/> 

我得到:
指定的默认EntityContainer名称FundirectoryEntities不能



我尝试更改它以指定程序集:

 < add name =FundirectoryEntitiesconnectionString =metadata = res://Funscribe.Data.dll/Fundirectory.csdl | res://Funscribe.Data.dll/Fundirectory.ssdl | res://Funscribe.Data.dll/Fundirectory.msl; provider = System.Data.SqlClient; provider connection string =& quot; data source = localhost\sqlexpress; initial catalog = Funscribe; user id = sys_Funscribe; password = blah; multipleactiveresultsets = True;应用程序名称= EntityFramework& quot; providerName =System.Data.EntityClient/> 

我得到:
无法解析程序集Funscribe.Data.dll



我在这里应该做的事情迷路了我刚刚将该项目升级到Visual Studio 2012(在转换为VS 2012之后,我介绍了这个新的控制台应用程序)。



我还注意到Funscribe.Data.dll位于在控制台项目的bin文件夹中,我手动删除这些文件,并看到它被重新创建。 这是什么困惑我的网页应用程序继续正常工作



所有项目都在.NET 4.0上。控制台应用程序使用.NET 4.0而不是客户端配置文件verison。



非常感谢任何有关此事的帮助。

解决方案

在名为Simple Model.edmx > Mvc.Data.dll 可能如下所示:

 < connectionStrings> 
< add name =MyEntitiesconnectionString =metadata =
res:// Simple Mvc.Data.dll / Model.csdl |
res:// Simple Mvc.Data.dll /Model.ssdl |
res:// Simple Mvc.Data.dll / Model.msl; provider =<! - ... - >
/ pre>

所以你可以看到,在运行时我们需要的EDMX的三个部分都有一个参考,它们都以相同的方式工作,所以让我们CSDL参考看起来像这样:

  res:// Simple Mvc.Data.dll / Model .csdl 

它指定了三件事:




  • 我们正在从资源加载CSDL,这就是res://part。


  • 包含资源的程序集的名称Simple Mvc.Data.dll如果你的程序集是强命名的,你可以在这里指定一个强大的名字,其所有的冗长的荣耀。


  • 资源本身的名称Model.csdl。不要将其与EDMX或型号名称混淆。在这种情况下,它们恰好是一样的,除了扩展,但这并不总是如此!





如果您的资源没有与您的模型发生相同的
名称,或者程序集不会被加载,则可能会失败。


有关更多信息,请查看 实体框架连接字符串疑难解答



我希望这将有助于您。


I am having some serious problems with Entity Framework and I can't seem to figure out whats going on.

I tried many options provided on: MetadataException: Unable to load the specified metadata resource and the famous Craig Stuntz's blog posting located at: http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

I have 3 projects for the sake of brevity:

Funscribe.Data (EDMX file located here)

Funscribe.Console (Console app)

Funscribe.Web (MVC 3 app)

Originally it was just the MVC app and I recently added this new console project.

I copied the connection string from web.config and applied it to my app.config:

<add name="FundirectoryEntities" connectionString="metadata=res://*/Fundirectory.csdl|res://*/Fundirectory.ssdl|res://*/Fundirectory.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\sqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

My mvc app continues to work, but when I run the console app, i get the dreaded:

"Unable to load the specified metadata resource."

I tried changing the connection string to the wild card setting:

<add name="FundirectoryEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\sqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I get: The specified default EntityContainer name 'FundirectoryEntities' could not be found in the mapping and metadata information.

I tried changing it to specify the assembly:

<add name="FundirectoryEntities" connectionString="metadata=res://Funscribe.Data.dll/Fundirectory.csdl|res://Funscribe.Data.dll/Fundirectory.ssdl|res://Funscribe.Data.dll/Fundirectory.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\sqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I get: Unable to resolve assembly 'Funscribe.Data.dll'.

I am lost on what I should do here. I just upgraded this project to Visual Studio 2012 (I introduce this new console app after converting to VS 2012).

I also noticed that the Funscribe.Data.dll is located within the console project's bin folder, i manually deleted these files and watch it get recreated. And what puzzles me is the web app continues to work properly!

All projects are on .NET 4.0. The console app uses .NET 4.0 not the client profile verison.

Any help on this matter is greatly appreciated.

解决方案

The metadata parameter for an application with an Entity Framework model called Model.edmx in an assembly called Simple Mvc.Data.dll might look like this:

<connectionStrings>
    <add name="MyEntities" connectionString="metadata=
            res://Simple Mvc.Data.dll/Model.csdl|
            res://Simple Mvc.Data.dll/Model.ssdl|
            res://Simple Mvc.Data.dll/Model.msl;provider= <!-- ... -->

So you can see there is one reference for each of the three parts of the EDMX that we need at runtime. They all work in the same way, so let’s examine just the first more closely. The CSDL reference looks like this:

        res://Simple Mvc.Data.dll/Model.csdl

It specifies three things:

  • We’re loading the CSDL from a resource. That’s the "res://" part.

  • The name of the assembly which contains the resource, "Simple Mvc.Data.dll". If your assembly is strong named, you can specify a strong name, in all its verbose glory, here.

  • The name of the resource itself, "Model.csdl". Do not confuse this with the EDMX or model name. In this case they happen to be the same, except for the extension, but that’s not always true!

It will probably fail if your resources don’t happen to have the same name as your model, or if the assembly doesn’t happen to be loaded.

For more information check this out Troubleshooting Entity Framework Connection Strings

I hope this will help to you.

这篇关于无法加载指定的元数据资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆