none
FileNotFoundException on constructor for ADO.NET Entity Model RRS feed

  • Question

  • Hi guys,

    I'm using EF for the first time in a project, and it worked ok until now... We had a change in our database, so I regenerated the model. Now I'm getting the following error when I try to intialize the model:

    Could not load file or assembly 'System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

    This is the StackTrace:
       at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.ReflectionOnlyLoad(String assemblyString)
       at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetAllDiscoverableAssemblies()
       at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetWildcardAssemblies()
       at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry)
       at System.Data.EntityClient.EntityConnection.SplitPaths(String paths)
       at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
       at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
       at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
       at System.Data.Objects.ObjectContext..ctor(String connectionString)
       at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
       at BR_Prestatiemodule.Data.PrestationEntities..ctor()

    I have no idea what might cause this kind of exception right now. I've even tried throwing away the whole model and making a new one... Nothing.

    Any ideas?

    Thanks in advance!
    Thursday, September 25, 2008 2:53 PM

Answers

  • Please see this article on MSDN:

     

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

     

    About half-way down you will see a section about how the metadata= part of the entity connection string is built.  

     

    I assume that you have chosen to have the runtime artifacts embedded as resources (right click on a blank area in the designer, choose properties, look at the property window).

     

    There is a note in the above MSDN page that outlines the effect of keeping the default "res://*" value that the designer writes out.  In your case, you should change this so that it uses explicit paths.  I suspect that because you have "res://*", the EF runtime is scanning your DLL and all referenced DLLs for any EF runtime artifacts.

    Friday, September 26, 2008 9:29 PM

All replies

    • Could you add more details on the exact steps that you took that led to this error. When you say you regenrated the model, did you do an "update Model From Database" on your "Edmx" file in the project ?
    • "I've even tried throwing away the whole model and making a new one... Nothing. "
      Does this mean that any time you go to the "Add New Item" menu and select "ADO.NET Entity Data Model" template you get this error ?

     

    Thursday, September 25, 2008 5:33 PM
  • hello, i m having the same problem..

    everything was working ok until i have installed vs 2008 sp1..

    after that, this error occur..

    "Could not load file or assembly 'System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies"

    I have not done any code modification..

    Someone knows what happen ?

     

    Thanks.. Lucas

     

    Friday, September 26, 2008 2:48 AM
  • hello Laila, after several probing thing, finally i have solved my problem.. i tell you the solution, in my project i used Infragistics controls (UI).. when removed this references, everything work fine..

    so, i think is a problem with some reference in your project.. but, .. this worked for me, now you may try and then you'll tell me...

     

    saludos.

     

     

    Friday, September 26, 2008 3:48 AM
  • Wel, it's true I'm using an external API, Aspose.

    About my model, i did try to regenerate it in both way you specified.

    I just tried out to throw out the Aspose DLL and everything is working again.
    But it just can't be possible that I can't use EF in combination with an external API!!!!?

    What do you think?
    Friday, September 26, 2008 1:06 PM
  • I'm having trouble repro'ing your scenario.

    Could you clarify the following

    1) What kind of project were you using ?

    2) Are you running against VS 2008 SP1 RTM ?

    3) Are you running the correct version of Aspose (You will need to run with Aspose version for .NET Fx 3.5). I'm curious about what kind of Aspose dll you are running with?

    Friday, September 26, 2008 8:00 PM
  • Please see this article on MSDN:

     

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

     

    About half-way down you will see a section about how the metadata= part of the entity connection string is built.  

     

    I assume that you have chosen to have the runtime artifacts embedded as resources (right click on a blank area in the designer, choose properties, look at the property window).

     

    There is a note in the above MSDN page that outlines the effect of keeping the default "res://*" value that the designer writes out.  In your case, you should change this so that it uses explicit paths.  I suspect that because you have "res://*", the EF runtime is scanning your DLL and all referenced DLLs for any EF runtime artifacts.

    Friday, September 26, 2008 9:29 PM
  • hello Craig,
    i think there is something to review because this behavior cause problem when i use thrid party components.. maybe them (Infragistics) have have a new version of the component, but in several cases i need to pay for those releases ..

     

    thanks. Lucas

    Friday, September 26, 2008 10:48 PM
  • Well, Aspose is an earlier version, but I don't consider that a reason.
    This version of Aspose works fine in all .NET 3.5 SP1 applications, except when I'm using EF and have a model I instantiate in my code.

    On the other side, it doesn't seem completly right you have to upgrade all your third-party libraries (with the necessary costs) because you want to upgrade to a newer version of the .NET framework?

    Thanks for your feedback!
    Wednesday, October 1, 2008 3:13 PM
  • This not resolve my case...
    I have this situation: Two Projects(two DLLs); In the first the Model, The second call the first. And that have the some problem with you.

    After hours and hours, the simple...

    Solution:

    I remove the reference of the connection string in my Model and stay the reference of base in caller project. This work.


    Project 1: 

    File: Externo.Context.cs

        
     //(...)
        namespace Framework.Model
        {
            public partial class ExternoContainer : ObjectContext,  IExternoContainer
            {
                public const string ConnectionString = "name=ExternoContainer";
                public const string ContainerName = "ExternoContainer";
            
            #region Constructors
        
            public ExternoContainer()
                : base(ConnectionString, ContainerName)
            {
                this.ContextOptions.LazyLoadingEnabled = true;
       
    
             }
        //(...)



    File: App.settings

         
    <!--<?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <connectionStrings>
            <add name="ExternoContainer" connectionString="metadata=res://*/Externo.csdl|res://*/Externo.ssdl|res://*/Externo.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESENV;initial catalog=Desenv;persist security info=True;user id=YOUR_USER;password=****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
          </connectionStrings>
        </configuration>-->



    Project 2:
    The WebConfig.Settings

         
    <configuration>
        <!--
        
        (...)
        
        -->
         <connectionStrings>
            <add name="ExternoContainer" connectionString="metadata=res://*/Externo.csdl|res://*/Externo.ssdl|res://*/Externo.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MDESENV;initial catalog=Desenv;persist security info=True;user id=YOUR_USER;password=*****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
          </connectionStrings>
        </configuration>




    Good luck! =)

    • Edited by Felipe Zani Tuesday, September 24, 2013 2:17 PM
    Tuesday, September 24, 2013 2:11 PM
  • <copied>

    The system cannot find the file specified.":"System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

    <end>

    It's not an EF issue per say. It's more like you have a .NET DLL issue with the System.Drawing.dll, which may be a different version on the machine  than the one .NET is looking for above. It seems that is what you need to figure out is why is there a DLL issue.

    Tuesday, September 24, 2013 4:54 PM