Saturday, March 19, 2011

The type or namespace name 'xxxx' does not exist in the namespace 'yyyy' (are you missing an assembly reference?)

Problem:
Error    1          The type or namespace name 'xxxx' does not exist in the namespace 'yyyy' (are you missing an assembly reference?)
Screenshot:

My environment: Visual Studio 2010, .Net 4.0.   Two projects involved, 1 is a dll, other is a console app.

You know your reference is correct, but you still get that reference error.  Your using clause fails, too.
Screenshot:
 

Solution:
In this case, my console app had the Target Framework in the project properties set to .NET Framework 4 Client Profile, the dll project had it set to .NET Framework 4.  I changed the console app to use .NET Framework 4, and everything built fine.

Console App Project properties before:

Console App Project properties after:


Thursday, March 17, 2011

Building Visual Studio Solutions Out of the Box

It is terrible when you are a developer at a new place and you open Visual Studio the first time, connect to your favorite source control like TFS or SVN, and open the desired solution, click build only to see many compile errors like invalid references.

Avoid creating this situation now by organizing your solutions so that they can easily be opened and built by new people.  You need to take into consideration how your solution is layed out, where external dependencies are, and how you present external tools.

First thing you need to do is make sure you solution file is at the root of all your projects.  If your all your projects are under c:/source, like in c:/source/MovieApp, then your solution should reside in c:/source.  You want to do this because it is not good practice to have a project reach up to a parent directory of the solution file into another branch for a referenced file or project.

Your structure should look like this:
C:/source
            MyMovieSolution.sln
C:/source/MovieApp
            MovieApp.csproj
C:/source/MvcMovie
            MvcMovie.csproj

Your next consideration needs to be references to external dependencies.  It is best if you have one location for this, right off the solution folder.  I usually call mine “External Dependencies”.  Then what you need to do is create an External Dependencies folder in the Visual Studio Solution and add your files from your “External Dependences” folder.  Now, whenever you reference a dll that is external, you use those files, and it will be gotten when you have a new developer get latest!  Easy enough.


















Next thing is to provide all your external tools in your solution.  I cannot tell you the number of times I had to go find an exact version of a tool because of some quirk that version had but no others did.  Check it in with your source, don’t store it on a shared network drive.  Update it?  Great, update it in your source control.
 









Last tip is do not set your output directories to the same folder!  Never do this, please.  Ever.  Leave them in bin.  If you are doing this, you most likely have an external dependency problem in one of your projects.  Fix that.

Saturday, March 5, 2011

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Problem:

Server Error in '/' Application.


The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Source Error: 
 
Line 32:         /// Initializes a new xxxxEntities object using the connection string found in the 'xxxxEntities' section of the application configuration file.
Line 33:         /// 
Line 34:         public xxxxEntities() : base("name=xxxxEntities", "xxxxEntities")
Line 35:         {
Line 36:             this.ContextOptions.LazyLoadingEnabled = true;

Source File: C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxx.Designer.cs    Line: 34 

Stack Trace: 
 
[ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.]
   System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +8080056
   System.Data.EntityClient.EntityConnection..ctor(String connectionString) +81
   System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) +42
   System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +16
   xxxx..ctor() in C:\Users\xxxxx.cs:34
   xxxx(Int32 id) in C:\Users\xxx.cs:25
   xxxx() in C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxxDal.cs:36
   xxxx() in C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxx.cs:13
   xxxx(Object sender, EventArgs e) in C:\Users\xxxxaspx.cs:145
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


Solution:
Add the entity connection string to the web.config file in the appropriate project.