locked
Pre-generated Views and embedded resources RRS feed

  • Question

  • Hi all.

    I recently followed the instructions on http://msdn.microsoft.com/en-us/library/bb896240.aspx to generate pre-compiled views for my model.

    This worked fine, until I tried to run a secondary project that references the same model. I now get a MetadataException stating that the program was "Unable to load the specified metadata resource" when I try to instantiate my ObjectContext. I'm assuming this is because the CSDL, SSDL and MSL are no longer embedded in the application, because of the Copy to Output Directory option, and therefore all the "res://*/MyModel" references fail.

    Is it possible to use both the "copy to output directory" and "embed to outpt assembly" options? Maybe using some pre/post compile commands?

    Best regards,

    Carlos Jourdan

    Monday, February 7, 2011 7:21 PM

Answers

  • Hi David.

    • You might have changed the MetadataArtifactProcessing property of the model to Copy to Output Directory.

     

    That is precesily what I was doing, as was stated in the original message. The problem is that I wanted to also keep the metadata as embedded resources.

    Eventually I got arround to it, by adding a pre-compile task to copy the files from the output directory to a folder inside the solution, and then adding the existing items with the "Embedded Resource" build action.

    Carlos

    • Marked as answer by Carlos Jourdan Wednesday, February 9, 2011 2:22 PM
    Wednesday, February 9, 2011 2:21 PM

All replies

  • Hi Carlos,

    Welcome to ado.net entity framework and linq to entities.

    The issue "Unable to load the specified metadata resource" which  means that the application is unable to load the EDMX. There are several things which can cause this.

    • You might have changed the MetadataArtifactProcessing property of the model to Copy to Output Directory.
    • The connection string could be wrong. I know you say you haven't changed it, but if you have changed other things (say, the name of an assembly), it could still be wrong.
    • You might be using a post-compile task to embed the EDMX in the assembly, which is no longer working for some reason.

    Base on your description, I found some references for you:

    Embedded EF Metadata in Output Assembly

    http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/86e35058-cd03-480e-9709-dd5d233803bf/

    Troubleshooting Entity Framework Connection Strings

    troubleshooting entity framework connection strings :Unable to load the specified metadata resource

    http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

     with

    I hope that would be help you.

    Have a good day.



    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 9, 2011 4:43 AM
  • Hi David.

    • You might have changed the MetadataArtifactProcessing property of the model to Copy to Output Directory.

     

    That is precesily what I was doing, as was stated in the original message. The problem is that I wanted to also keep the metadata as embedded resources.

    Eventually I got arround to it, by adding a pre-compile task to copy the files from the output directory to a folder inside the solution, and then adding the existing items with the "Embedded Resource" build action.

    Carlos

    • Marked as answer by Carlos Jourdan Wednesday, February 9, 2011 2:22 PM
    Wednesday, February 9, 2011 2:21 PM
  • Hi Carlos,

    I'm very glad to hear that your have fix the issue and appreciate with your sharing.

    Welcom to your regular participate.

    Have a good day.



    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 10, 2011 1:05 AM
  • If it could be useful

    I had the same issue and my problem was the connection string which was not in the correct format.

    I set my files myModel.csdl,myModel.msl,mymodel.ssdl,myModel.Views.cs as EmbededResource in BuildAction

    and I changed the MetadataArtifactProcessing property of the model to Copy to Output Directory and I wrote my conection string in this way:

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

    after having modified in the above way the connection string I didn't receive anymore the error

    "Unable to load the specified metadata resource".

    So in my opinion you don't need any pre-compile task.

    Bye

    Daniele


    • Edited by DanieleRM78 Tuesday, December 16, 2014 10:17 AM
    Tuesday, December 16, 2014 10:16 AM