locked
"Unable to load the specified metadata resource" RRS feed

  • Question

  • I wish there would be some more information about this error. In searching around it seems like its quite common but i have yet to find a post that has been able to help me out. I'm using the Self-Tracking entities.  Anyways without further adieu:

    Details:
    1) One Assembly with just the model portion of the entity framework
    2) Another assembly just for the types created from the Project.tt file *linked from the model directory in 1*
    3) Another assmebly (repository) that has the Project.context.tt file *linked from the model directory in 1*. It also has the CRUD operations

    Created a test WPF app to consume the repository service and created an app.config to hold the connection string. Copied the connection string from the model app.config exactly. App blows in the Project.Context.cs that the Project.Context.tt created:
    public const string ConnectionString = "name=ProjectEntities";
            public const string ContainerName = "ProjctEntities";
       
            #region Constructors
       
            public CookBookEntities()
                : base(ConnectionString, ContainerName) <---line where the error happens.
            {
                this.ContextOptions.LazyLoadingEnabled = true;
            }

    Connection String in App.config:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="ProjectDBContainer" connectionString="metadata=res://*/ProjectModel.csdl|res://*/ProjectModel.ssdl|res://*/ProjectModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Project.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

        <add name="ProjectEntities" connectionString="metadata=res://*/ProjectModel.csdl|res://*/ProjectModel.ssdl|res://*/ProjectModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Project.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    </configuration>

    It appears the person in the following thread was having the same problem as me:
    http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/63f017bf-d637-4709-828e-5a0f07c677f4

    but i don't understand exactly what he wants you to do. .csdl .ssdl? In my build directory i just have ProjectModel.dll, ProjectModel.dll.config, ProjectModel.pdb, Project.mdf, Project_log.ldf.
    Monday, March 15, 2010 11:28 PM

Answers

  • Are you doing anything in your application that would cause the assembly with the EDMX model to be loaded into the process? If you're not accessing it in any way (because it sounds as though that assembly has only the model in it), then you'll need to (1) manually load that assembly using something like Assembly.Load before calling EF, (2) move the model to a project that will be loaded when the application is run, or (3) change the designer property Metadata Artifact Processing from "Embed in Output Assembly" to "Copy to Output Directory", change the metadata portion of the connection string to say "metadata=.\ProjectModel.csdl|.\ProjectModel.ssdl|.\ProjectModel.msl" and ensure those files are in the same directory as your executable.
    Blog - http://blogs.rev-net.com/ddewinter/ Twitter - @ddewinter
    Thursday, March 18, 2010 3:55 PM
    Answerer

All replies

  • Are you doing anything in your application that would cause the assembly with the EDMX model to be loaded into the process? If you're not accessing it in any way (because it sounds as though that assembly has only the model in it), then you'll need to (1) manually load that assembly using something like Assembly.Load before calling EF, (2) move the model to a project that will be loaded when the application is run, or (3) change the designer property Metadata Artifact Processing from "Embed in Output Assembly" to "Copy to Output Directory", change the metadata portion of the connection string to say "metadata=.\ProjectModel.csdl|.\ProjectModel.ssdl|.\ProjectModel.msl" and ensure those files are in the same directory as your executable.
    Blog - http://blogs.rev-net.com/ddewinter/ Twitter - @ddewinter
    Thursday, March 18, 2010 3:55 PM
    Answerer
  • Sorry it took me a couple days to reply. I have been busy as usual but thanks for the answer. I have marked it as unanswered because i have more questions  to go along with my original question.

    Please reference the original sample here:
    http://msdn.microsoft.com/en-us/library/ee789839%28VS.100%29.aspx

    This is almost exactly what i was trying to do the only difference being is they are using WCF and i wasn't. They don't talk anything about the issue i had above and don't do anything to solve the problem. Anyone work with this sample would probably have the same issue. Do you know why or is this probably an omission?  They also doing some other strange things which i have no idea why for example in step 5 under " To create and configure the WCF project."

    In the Add Existing Item dialog, browse to the STEAdventureWorksModel project and click AdventureWorksModel.tt (do not press Enter). In the Add list, select Add as Link

    Why in the world are they referencing the t4 file when they are already referencing STEAdventureWorksTypes? Doesn't make a whole lot of sense. Maybe just there are problems with this sample if thats the case then just let me know and i'll mark the question as answered again.

     

    thanks David

    Saturday, March 20, 2010 8:40 PM
  • It looks like an omission, because if you don't load the assembly it shouldn't work. I haven't tried this walkthrough myself, though.

    To answer your other question, I think that is a typo. It should say "browse to the STEAdventuresWorksModel project and click AdventureWorksModel.Context.tt" instead.

    I'll follow up with our documentation team about this. In future though you can report these kinds of issues directly by clicking a star near the "Click to Rate and Give Feedback" text at the top right of the page.

    Monday, March 22, 2010 2:52 PM
    Answerer
  • Thanks David. I'll make the question as answered. Hopefully the fix the docs fast though because most people doing a walkthrough are going to be stuck since this will probably be their first dive into EF4.
    Tuesday, March 23, 2010 12:42 AM
  • The example on msdn works correctly because they generate the objectcontext in a wcf service. The example you have shown. you generate the model in different assembly, types in different assembly, objectcontex and repository in different assembly and then have wpf have that consumes the repository. What happens is since repository does not uses anything from model assembly, although you have added references the final output in the bin directory of the wpf application does not have Model assembly. Since visual studio sees that Model assembly has an added reference but its referenced any where in the repository/object context aseembly, it does not get emitted out in the final reference. 

     

    You can as suggested copy to output directory the csdl, msl and ssdl files.

     

     

    Tuesday, March 23, 2010 5:29 PM
  • Respected Sir,

    thanks for ur post above so that i could identify similar problem i have faced.

     

    Now, i have built an ADO.NET entity project and i am using that project as a reference in a ASP.NET MVC App. Here the same problem of metdata not found is occurring. Well i tried step no 3 mentioned above in vain, as i could not understand the prior 2. But even then 3rd did not work.

     

    Please guide how to proceed with point 3 above in case of MVC app as i have mentioned above. 

     

    Also i was not able to run a Test Project for my ADO.NET Entity project. There also i am facing the metadata problem.

     

    Thanks, 


    Parth J Joshi http://www.parthjoshi.com
    Sunday, July 4, 2010 11:12 AM
  • Sunday, July 4, 2010 5:42 PM
  • I forgot to mention when i was replying to the thread, I did write a blog posting to articulate what the problem is and how to solve it.

     

    http://weblogs.asp.net/zeeshanhirani/archive/2010/03/23/placing-model-in-separate-assembly.aspx

     


    Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
    http://weblogs.asp.net/zeeshanhirani
    Sunday, July 4, 2010 6:15 PM
  • "Unable to load the specified metadata resource" in Visual Studio 2010 when adding custom controls from toolbox.

    I resolved this error in VS 2010 RC2 by manually adding the offending dlls to GAC cache with " gacutil /i YourDLLPAth". Close VS before you do this or it could have a fit.

    None of the errors ever prevented me from building or runnning the app, just from using the Design window which sucked and being pesky in the Errors List.

     I produced the errors by adding a usercontrol from the tools menu to a window (XAML/WPF) in the same project but subfolder. VS puts the proper reference in your XAML but VS still thinks its missing if you dont add it to the GAC.

     

     

    Friday, July 16, 2010 8:43 PM
  • Solved:

    If the application instancing the context reference a DLL where the context is defined, then the notation //*/ instructs the framework to look for the embedded resources in the application assembly instead that in the referenced dll, where they actually are.

    So I had to change from:

    ........... metadata=res://*/EFPocModel.csdl|res://*/EFPocModel.ssdl|res://*/EFPocModel.msl ...............

    to:

    ........... metadata=res://MyapplicationAssembly/EFPocModel.csdl|res://MyapplicationAssembly/EFPocModel.ssdl|res://MyapplicationAssembly/EFPocModel.msl ...............

    More info:

    http://msdn.microsoft.com/en-us/library/cc716717.aspx



    • Edited by CIGNUM Thursday, September 22, 2011 3:47 PM
    Thursday, September 22, 2011 3:42 PM
  • If using n-tier, make sure your upper layer .config has the right connectionString included!

    • Proposed as answer by Roque Arduengo Monday, October 31, 2011 7:37 PM
    Monday, October 31, 2011 7:37 PM