Programing

MetadataException : 지정된 메타 데이터 리소스를로드 할 수 없습니다.

lottogame 2020. 10. 2. 21:22
반응형

MetadataException : 지정된 메타 데이터 리소스를로드 할 수 없습니다.


갑자기 나는 MetadataException생성 된 ObjectContext클래스 를 인스턴스화 하는 데 계속 됩니다 . App.Config의 연결 문자열이 정확 해 보이며 마지막으로 작동 한 이후로 변경되지 않았으며 변경없이 기본 데이터베이스에서 새 모델 (edmx 파일)을 다시 생성 해 보았습니다.

누구나 아이디어가 있습니까?

추가 세부 정보 : 속성을 변경하지 않았으며 출력 어셈블리의 이름을 변경하지 않았으며 어셈블리에 EDMX를 포함하려고 시도하지 않았습니다. 퇴근 후 돌아올 때까지 10 시간을 기다렸습니다. 그리고 더 이상 작동하지 않았습니다.

EDMX를 다시 만들어 보았습니다. 프로젝트를 다시 만들어 보았습니다. 나는 심지어 처음부터 데이터베이스를 다시 만들어 보았습니다. 운이 없습니다.


이는 애플리케이션이 EDMX를로드 할 수 없음을 의미합니다. 이를 유발할 수있는 몇 가지 사항이 있습니다.

  • 모델의 MetadataArtifactProcessing 속성을 출력 디렉터리에 복사로 변경했을 수 있습니다.
  • 연결 문자열이 잘못되었을 수 있습니다. 나는 당신이 그것을 변경하지 않았다고 말하는 것을 알고 있지만, 다른 것 (예 : 어셈블리 이름)을 변경했다면 여전히 틀릴 수 있습니다.
  • 어떤 이유로 더 이상 작동하지 않는 어셈블리에 EDMX를 포함하기 위해 컴파일 후 작업을 사용할 수 있습니다.

요컨대, 질문에 정확한 답변을 제공하기에 충분한 세부 사항이 없지만 이러한 아이디어가 올바른 방향으로 나아가기를 바랍니다.

업데이트 : 문제 해결을위한보다 완전한 단계 가 포함 된 블로그 게시물을 작성 했습니다 .


이 작은 변화는이 문제에 도움이됩니다.

3 프로젝트에 솔루션이 있습니다.

connectionString="metadata=res://*/Model.Project.csdl|res://*/Model.Project.ssdl|res://*/Model.Project.msl;

로 변경

connectionString="metadata=res://*/;

Edmx가 한 프로젝트에 있고 다른 프로젝트에서 사용중인 경우이 예외가 발생할 수 있습니다.

그 이유는 Res://*/CURRENT 어셈블리의 리소스를 가리키는 URI 때문입니다 . Edm이 사용중인 코드와 다른 어셈블리에 정의되어 있으면 리소스를 찾을 수 없기 때문에 res : // * /가 작동하지 않습니다.

'*'를 지정하는 대신 어셈블리의 전체 이름을 제공해야합니다 (공개 키 토큰 포함). 예 :

res://YourDataAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcdefabcedf/YourEdmxFileName.csdl|res://...

연결 문자열을 생성하는 더 좋은 방법은 EntityConnectionStringBuilder를 사용하는 것입니다.

public static string GetSqlCeConnectionString(string fileName)
{
    var csBuilder = new EntityConnectionStringBuilder();

    csBuilder.Provider = "System.Data.SqlServerCe.3.5";
    csBuilder.ProviderConnectionString = string.Format("Data Source={0};", fileName);

    csBuilder.Metadata = string.Format("res://{0}/YourEdmxFileName.csdl|res://{0}/YourEdmxFileName.ssdl|res://{0}/YourEdmxFileName.msl", 
        typeof(YourObjectContextType).Assembly.FullName);

    return csBuilder.ToString();
}

public static string GetSqlConnectionString(string serverName, string databaseName)
{
    SqlConnectionStringBuilder providerCs = new SqlConnectionStringBuilder();

    providerCs.DataSource = serverName;
    providerCs.InitialCatalog = databaseName;
    providerCs.IntegratedSecurity = true;

    var csBuilder = new EntityConnectionStringBuilder();

    csBuilder.Provider = "System.Data.SqlClient";
    csBuilder.ProviderConnectionString = providerCs.ToString();

    csBuilder.Metadata = string.Format("res://{0}/YourEdmxFileName.csdl|res://{0}/YourEdmxFileName.ssdl|res://{0}/YourEdmxFileName.msl",
        typeof(YourObjectContextType).Assembly.FullName);

    return csBuilder.ToString();
}

여전히 예외가 발생하면 리플렉터에서 어셈블리를 열고 .csdl, .ssdl 및 .msl 파일의 파일 이름을 확인하십시오. 리소스의 이름이 메타 데이터 값에 지정된 이름과 다른 경우 작동하지 않습니다.


비슷한 오류가 발생했습니다. 나는 프로젝트 (긴 이야기)를 재창조하고 이전 프로젝트에서 모든 것을 가져 왔습니다. 나는 내 모델이 이전에 'Model'이라는 디렉토리에 있었다는 것을 몰랐고 지금은 'Models'라는 디렉토리에 있었다. Web.Config의 연결을 다음과 같이 변경하면 :

<add name="RecipeManagerEntities" connectionString="metadata=res://*/Model.Recipe.csdl 

이에:

<add name="RecipeManagerEntities" connectionString="metadata=res://*/Models.Recipe.csdl

모든 (변경 일 ModelModels). 이 문자열에서이 세 자리를 변경해야했습니다.


그리고 Reflector없이 모델 이름을 확인하는 빠른 방법 .... 디렉토리를 찾으십시오.

... obj / {config output} / edmxResourcesToEmbed

.csdl, .msl 및 .ssdl 리소스 파일이 있는지 확인합니다. 하위 디렉토리에있는 경우 하위 디렉토리의 이름을 모델 이름 앞에 추가해야합니다.

예를 들어, 세 개의 리소스 파일이 Data 하위 디렉터리 에 있으므로 연결 문자열은

metadata = res : // * / 데이터 .MyModel.csdl | res : // * / 데이터 .MyModel.ssdl | res : // * / 데이터 .MyModel.msl;

(metadata = res : //*/MyModel.csdl | res : //*/MyModel.ssdl | res : //*/MyModel.msl;).


나는 또한이 문제가 있었고 내 web.config의 연결 문자열이 EDMX가있는 어셈블리의 app.config에있는 연결 문자열과 약간 다르기 때문입니다. 왜 변경되었는지 모르겠지만 여기에 두 가지 버전이 있습니다.

App.config :

<add name="SCMSEntities" connectionString="metadata=res://*/Model.SMCSModel.csdl|res://*/Model.SMCSModel.ssdl|res://*/Model.SMCSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SANDIEGO\sql2008;initial catalog=SCMS;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Web.config :

<add name="SCMSEntities" connectionString="metadata=res://*/Model.SCMSModel.csdl|res://*/Model.SCMSModel.ssdl|res://*/Model.SCMSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SANDIEGO\sql2008;initial catalog=SCMS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

수정 된 것은 단순히 app.config 문자열을 web.config에 복사하는 것이 었습니다 (마지막에 작은 차이가 있음- " App=EntityFramework" 대신 필요함 " application name=EntityFramework"). 문제가 해결되었습니다. :)


실수로 edmx 파일의 빌드 작업 (IDE의 속성 아래에 표시됨)을 'EntityDeploy'에서 'None'으로 전환했을 때 이런 일이 발생했습니다. EntityDeploy는 메타 데이터를 채우는 것입니다. http://msdn.microsoft.com/en-us/library/cc982037.aspx 참조


이걸로 30 분 동안 행복한 시간을 보냈습니다. 엔티티 객체의 이름을 변경하고 구성 파일의 항목 이름을 변경했지만 더 많은 것이 있습니다 ... csdl에 대한 참조도 변경해야합니다.

놓치기 쉬움-이름을 바꾸는 경우 모든 정보를 확인하십시오 ....


이것은 새로운 .edmx 디자이너를 빌드하기 전에 솔루션을 정리하지 않을 때 발생합니다. 따라서 새로운 .edmx 디자이너를 빌드하기 전에 솔루션을 정리하는 것을 잊지 마십시오. 이렇게하면이 문제로 더 많은 문제를 건너 뛸 수 있습니다. Visual Studio를 처음 사용하는 경우 제공된 탐색 세부 정보를 벨로우합니다.

클릭-> 빌드-> 솔루션 정리

그런 다음 클릭-> 빌드-> 솔루션 다시 빌드

도움이 되었기를 바랍니다. 모두 감사합니다


나는 같은 문제가 있었다. 리플렉터를 사용하여 컴파일 된 dll을 살펴본 결과 리소스 이름이 올바르지 않음을 확인했습니다. 이름이 바뀌었고 이제 괜찮아 보입니다.


제 경우에는 edmx 파일의 속성을 변경하여 해결됩니다.

  1. edmx 파일 열기
  2. EDMX 디자이너의 아무 곳이나 오른쪽 클릭
  3. 속성 선택
  4. "메타 데이터 아티팩트 처리"라는 속성을 "출력 어셈블리에 포함"으로 업데이트

이것은 나를 위해 문제를 해결했습니다. 문제는 컨테이너가 메타 데이터를 찾으려고 할 때 찾을 수 없다는 것입니다. 그래서 단순히 동일한 어셈블리로 만드십시오. 이 솔루션은 다른 어셈블리에 edmx 파일이있는 경우 작동하지 않습니다.


이 오류에 하루 종일 보냈습니다.

당신이 함께 일한다면 n-tear architecture

또는 DataAccessLayer에서 separate Models생성 EDMX하여DomainModelLayer

아마도 당신은이 오류를 얻을 것입니다

  1. 첫 번째 문제 해결 단계에서 반드시 연결 문자열을 만드는 것입니다 webconfig (UILayer)appconfig (DataAccessLayer)동일
  2. 두 번째는 매우 중요합니다. connection string

    connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provid.....
    

    그게 문제 야

도대체 어디서 얻었 Model는지 또는 연결 문자열의 .csdl 어디에서나

여기 우리의 솔루션은 그림을 봅니다

enter image description here

당신의 도움을 바랍니다


Visual Studio 2010, VB.net (ASP.NET) 4.0에서이 문제를 해결할 수있었습니다.

During the entity model wizard, you will be able to see the entity connection string. From there you can copy and paste into your connection string.

The only thing I was missing was the "App_Code." in the connections string.

entityBuilder.Metadata = "res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl"

The ultimate solution (even after recreating the database on two other machines, as well as the EDMX and other sundries) was to not use the first edition of Entity Framework. Looking forward to evaluating it again in .NET 4.0.

After running into the same problem again and searching all over for an answer, I finally found someone who'd had the same problem. It appears that the connection string wasn't correctly generated by Visual Studio's wizard, and the link to the metadata resources was missing an important path.

v1.0 BUG?: Unable to load the specified metadata resource. Scripts != Models

Update 2013-01-16: Having transitioned to almost exclusively using EF Code First practices (even with existing databases) this problem is no longer an issue. For me, that was a viable solution to reducing the clutter from auto-generated code and configuration and increasing my own control over the product.


My issue and solution, the symptoms were the same "Unable to load the specified metadata resource" but the root cause was different. I had 2 projects in solution one was the EntityModel and the other the solution. I actually deleted and recreated the EDMX file in the EntityModel.

The solution was that I had to go back to the Web Application project and add this line into the config file. The new model had changed a few items which had to be duplicated in the "other" project's Web.Config file. The old configuration was no longer good.

     <add name="MyEntities"
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;
                    provider=System.Data.SqlClient;
                    provider connection string=&quot;
                    data source=Q\DEV15;initial catalog=whatever;
                    user id=myuserid;password=mypassword;
                    multipleactiveresultsets=True;
                    application name=EntityFramework&quot;"
     providerName="System.Data.EntityClient" />

After hours of googling and trying to solve none of the solutions suggested worked. I have listed several solution here. I have also noted the one that worked for me. (I was using EF version 6.1.1, and SQL server 2014 - but an older DB)

  1. Rebuilding the project and try again.
  2. Close and open VS - I don't know how this works
  3. make sure if you have placed the .EDMX file inside a Directory, make sure you include the Directories in your ConnectionString. for example mine is inside DAL folder. SO it looks like this: connectionString="metadata=res://*/DAL.nameModel.csdl|res://*/DAL.nameModel.ssdl|res://*/DAL.nameModel.msl;(these are files. to see them you can toggle Show All Files in solution explorer, under ~/obj/.. directory)

...and many more which I had tried [like: reverting the EntityFramework version to a later version(not sure about it)]


what worked for me:

from this article here, it helped me solve my problem. I just changed my ProviderManifestToken="2012" to ProviderManifestToken="2008" in the EDMX file. To do this:

Solution Explorer

  1. Right click over file .edmx
  2. Open with..
  3. Editor XML
  4. Change ProviderManifestToken="XXXX" with 2008

I hope that helps.


In my case, this issue was related to renaming my model's edmx file... correcting the app.config connection string for the csdl/ssdl/msl files fixed my issue.

If you're using the EF 4.0 designer to generate your csdl/ssdl/msl, these 3 "files" will actually be stored within the model's main edmx file. In this case, the post by Waqas is pretty much on the mark. It's important to understand that "Model_Name" in his example will need to be changed to whatever the current name of your model's .edmx file (without the .edmx).

Also, if your edmx file is not at the root level of your project, you need to preface Model_Name with the relative path, e.g.

res://*/MyModel.WidgetModel.csdl|res://*/MyModel.WidgetModel.ssdl|res://*/MyModel.WidgetModel.msl

would specify the csdl/ssdl/msl xml is stored in the model file 'WidgetModel.edmx' which is stored in a folder named 'MyModel'.


I have written this helper class to create instances of ObjectContext objects when they are defined in a different project than the project using it. I parse the connection string in the config file and replace '*' by the full assembly name.

It is not perfect because it uses reflection to build the object, but it is the most generic way of doing it that I could find.

Hope it helps someone.

public static class EntityHelper<T> where T : ObjectContext
{
    public static T CreateInstance()
    {
        // get the connection string from config file
        string connectionString = ConfigurationManager.ConnectionStrings[typeof(T).Name].ConnectionString;

        // parse the connection string
        var csBuilder = new EntityConnectionStringBuilder(connectionString);

        // replace * by the full name of the containing assembly
        csBuilder.Metadata = csBuilder.Metadata.Replace(
            "res://*/",
            string.Format("res://{0}/", typeof(T).Assembly.FullName));

        // return the object
        return Activator.CreateInstance(typeof(T), csBuilder.ToString()) as T;
    }
}

For all of you SelftrackingEntities Users , if you have followed the Microsoft Walk-through and separated the Object context class into the wcf service project (by linking to the context .tt) so this answer is for you :

part of the shown answers in this post that includes code like :

... = string.Format("res://{0}/YourEdmxFileName.csdl|res://{0}/YourEdmxFileName.ssdl|res://{0}/YourEdmxFileName.msl", 
        typeof(YourObjectContextType).Assembly.FullName); 

WILL NOT WORK FOR YOU !! the reason is that YourObjectContextType.Assembly now resides in a different Assembley (inside the wcf project assembly) ,

So you should replace YourObjectContextType.Assembly.FullName with -->

ClassTypeThatResidesInEdmProject.Assembly.FullName 

have fun.


If you are using the edmx from a different project, then in the connection string, change...

metadata=res://*/Data.DataModel.csdl

...to...

metadata=res://*/DataModel.csdl

I was having problems with this same error message. My issue was resolved by closing and re-opening Visual Studio 2010.


Had same issue because I renamed an assembly.

I had to also rename it in AssemblyTitle and AssemblyProduct attributes in project Properties/AssemblyInfo.cs, and also deleting and re adding the reference to the edmx file.

Then it worked just fine.


With having same problem I re-created edmx from Database. Solves my problem.


Exception is because compiler pointing to non existing Metadata so just Copy app.config connectionstring to Web.config ConnectionString


Sometimes i see this error in my project. I solve that by

1 - Right click on EDMX file

2 - Select Run Custom Tool option

3 - Rebuild project


I also had the same problem and solution as per Rick, except that I was importing an existing .edmx to a new project, and while the base namespace didn't matter it was imported into a different subdirectory so I also had to update the connection string inside Web.Config in three places, to include the different subdirectory naming:


I had the same problem with a solution which contained projects in a Solution Folder, when they were moved to the Solution Root (in order to overcome a suspected bug with the Mvc3AppConverter due to project locations).

Although the solution compiled after all* project references were re-added as needed, the error was thrown when the website was fired up.

The EDMX is in one of the projects which was moved (the 'Data' project), but of course the lack of a reference to the Data project didn't cause a compile error, just a run-time error.

Simply adding the missing reference to the primary project resolved this problem, no need to edit the connection at all.

I hope this helps someone else.


A poor app.config or web.config file can do this.. I had copied the app.config connection string to my web.config in my UI and ended up entering:

<connectionStrings>
    <connectionStrings>
          <add name="name" connectionString="normalDetails"/>
    </connectionStrings>
</connectionStrings>

I simply hadn't referenced my class library that contained the EDMX file.


My theory is that if you have more than one edmx file with same name (Model1 for example), it will give that exception. I've got same problem when I decided to name all my edmx files (sitting in different projects) as Model1 because I thought they should be independent.

참고URL : https://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource

반응형