title: Can't Find Entity Framework Connection String in app.config
body: <p>I have a catch for exceptions that writes the exception to a message box. The exception I keep running into says "System.InvalidOperationException: No connection string named 'NameOfEntities' could be found in the application config file. at..."</p>
  
  <p>Following that, it notes that I'm trying to use LINQ to Entities on the entity on three specific lines in my code and that's where the error is originating from. </p>
  
  <p>On these lines, there is pretty simple LINQ statements like:</p>
  
  <pre><code>IEnumerable&lt;EntityObject&gt; item = (from d in entityVariable.EntityObjects select d).AsEnumerable&lt;EntityObject&gt;();
  </code></pre>
  
  <p>I have tried it as an enumerable, as a list, it doesn't matter...still the error appears. The error can occur when I'm running it, when I'm building it, and when I'm just editing code.</p>
  
  <p>I have the connection string named "NameOfEntities" in my config file, between the <code>&lt;connectionStrings&gt;</code> tags, which <a href="https://stackoverflow.com/questions/12622408/no-connection-string-named-myentities-could-be-found-in-the-application-config">this post suggests</a>.</p>
  
  <p>The .edmx lives in another project (a class library) in the solution. As the example linked to above illustrates, this shouldn't be a problem, and I've been developing with this system long before the error starting coming up.</p>
  
  <p>For as much info as possible, here's the full error. The formatting of the message is for legibility:</p>
  
  <blockquote>
    <p>"System.InvalidOperationException: No connection string named 'CnmcEntities' could be found in the application config file. 
    at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() 
    at system.Data.Entity.Internal.LazyInternalContext.InitializeContext() 
    at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 
    at System.Data.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 
    at System.Data.Entity.Internal.Linq.Set`.get_InternalContext() 
    at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() 
    at System.LInq.Queryable.Select[TSource,TResult](IQueryable` source, Expression`1 selector) 
    at NameOfProject.Model.LiveData..ctor() in c:\PlaceOfTheProject\NameOfProject\Model\LiveData.cs:line 19 
    at NameOfProject.ViewModel.ChildViewModels.DataPointsViewModel..ctor(LiveDataViewModel thisMainView) in c:\PlaceOfTheProject\NameOfProject\ViewModel\LiveData\LiveDataViewModel\ChildViewModels\DataPointsViewModel.cs:line45 at NameOfProject.ViewModel.LiveDataViewModel.InitializeData() in c:\PlaceOfProject\NameOfProject\ViewModel\LiveDataViewModel\LiveDataViewModel.cs:line 103"</p>
  </blockquote>
  
  <p>Here's what I have (sans sensitive info) in the app.config:</p>
  
  <p><code>&lt;connectionStrings&gt;
  &lt;add name="NameOfEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=SERVERSOURCE;initial catalog=NameOfInitialCatalog;persist security info=True;user id=UserId;password=Password;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
  &lt;/connectionStrings&gt;</code></p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>As a "hot fix," instead of writing the exception to a message box, I am just swallowing the exception. There has been no ill effects on the application - it still accesses the data from the database. I hate this "solution," but as there seem to be no problems so far from swallowing the exception, I will keep it for now. </p>
  
  <p>Interestingly, I put a break point in the catch for the offending code, and it has not been hit yet after running the application several times. It seems like the exception was occurring most often on release of resources after closing the app, so maybe the debugger is no longer running when it hits this code. Either way, this has been a strange occurrence indeed.</p>
  
  <p>I'm still open to any concrete ideas on how to fix the problem without swallowing the exception, or course.</p>