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

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

问题描述

我有一些严重的问题,实体框架和我似乎无法弄清楚怎么回事。

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

我试过提供了多种选择:<一href=\"http://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource\">MetadataException:无法加载指定的元数据资源并位于著名的克雷格斯顿茨的博客发帖:<一href=\"http://blogs.teamb.com/craigstuntz/2010/08/13/38628/\">http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

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/

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

I have 3 projects for the sake of brevity:

Funscribe.Data(位于此EDMX文件)

Funscribe.Data (EDMX file located here)

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

Funscribe.Console (Console app)

Funscribe.Web(MVC 3应用程序)

Funscribe.Web (MVC 3 app)

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

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

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

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" />

我的MVC应用程序继续工作,但是当我运行控制台应用程序,我得到了可怕的:

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

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

我试图改变连接字符串通配符设置:

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" />

我得到:
指定的默认​​EntityContainer相关名称'FundirectoryEntities无法在映射和元数​​据信息中发现。

我试图改变它来指定程序集:

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" />

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

我失去了我应该做的这里。我刚刚升级这个项目到Visual Studio 2012(我转换为VS 2012年之后推出这个新的控制台应用程序)。

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).

我也注意到,Funscribe.Data.dll位于控制台项目的bin文件夹中,我手动删除这些文件,看它得到重建。 而令我百思不解的是Web应用程序将继续正常工作

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!

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

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

在这个问题上的任何帮助是极大的AP preciated。

Any help on this matter is greatly appreciated.

推荐答案

与名为 Model.edmx 在装配称为简单的实体框架模型的应用程序元数据参数 Mvc.Data.dll 可能是这样的:

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= <!-- ... -->

所以,你可以看到有每个我们需要在运行时EDMX的三个部分中的一个参考。他们以同样的方式,所有的工作,所以让我们来看看刚刚在第一更为密切。该CSDL参考如下:

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

它指定了三件事情:


  • 我们正在从资源加载CSDL。这就是RES://。部分

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

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.

资源本身,Model.csdl的名称。不要与EDMX或型号名称混淆。在这种情况下,他们恰好是相同的,除了为扩展名,但是这并非总是如此!

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

我希望这会帮助你。

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

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