none
Type or namespace could not be found - missing directive /assembly reference?

    Question

  • Hi,

    I am trying an example from a book and I am getting errors.  The main error I am getting is 

    Error 2 The type or namespace name 'Entitykey' could not be found (are you missing a using directive or an assembly reference?) C:\MyCode\InventoryEDMConsoleApp\InventoryEDMConsoleApp\Program.cs 60 17 InventoryEDMConsoleApp

    I have copied the example identically but it throws up a number of errors about missing assembly or reference.  The example is an console application  where i create a ADO.NET entity data model and follow through the Wizard.  Its a pretty straightforward operation and everything is done before I start editing the code so I can't figure out why it would be throwing up missing a using directive / ssembly reference errors ?

    Any ideas ?

    Saturday, August 31, 2013 9:53 AM

Answers

All replies

  • When you create a new project and select a console project (or any of the other project) there is a box at the bottom of the form wher you enter the project name.  Usually with a console project it will default to ConsoleApplication1.  ConsoleApplication1 will become the default namespace. You can change the default namespace inside the project properties after the project is created.

    In your case you should of typed 'Entitykey' in the box at the bottom of the form (or the namespace where the main() function is located).


    jdweng

    Saturday, August 31, 2013 2:19 PM
  • well I did copy the example in the book and I do have the right project name and namespace.  I don't think that is causing the error?

    I'm getting 8 errors in total, broken into two groups.  The first is above and the second is here :

    Error 1 'System.Data.Entity.DbSet<InventoryEDMConsoleApp.Car>' does not contain a definition for 'AddObject' and no extension method 'AddObject' accepting a first argument of type 'System.Data.Entity.DbSet<InventoryEDMConsoleApp.Car>' could be found (are you missing a using directive or an assembly reference?) C:\MyCode\InventoryEDMConsoleApp\InventoryEDMConsoleApp\Program.cs 32 34 InventoryEDMConsoleApp

    Maybe its a missing reference but I did put them in.

    Saturday, August 31, 2013 3:08 PM
  • What .NET framework is the example code of that book of yours expecting and does it comply with your coding environment. Check also, if your program is expecting a 32-bit assembly, whereas you've loaded the 64-bit version?

    Usually, if a using directive is missing a reference that directive should be underscored by Intellisense with a curled red line. I guess you didn't see such a highlighting in your code?

    wizend

    Saturday, August 31, 2013 3:51 PM
  • I'm running .NET 4.5.  I have an 64bit operating system and everything other example has been running fine to date.

    I think its a straightforward missing reference or something like that but I'm not exactly sure what. There is a red line in the code, one error is the following :

     context.Cars.AddObject(new Car() { CarID = 2222,.............

    .AddObject is underlined in red.  AddObject does not exist, there is AddObject.Cars.Add but not .AddObject

    Saturday, August 31, 2013 4:19 PM
  • AddObject() is a member of the ObjectSet<TEntity> class of the System.Data.Objects namespace in System.Data.Entity.dll.

    You should check that, too.


    Saturday, August 31, 2013 6:17 PM
  • Make sure you also add the "using" statement for each reference ou add as well as adding it in the menu.  A project has a default namespace which is set when you enter the project name when you create a new project.  If you don't enter the correct name in the form then you have to go to the project properties and change the default namespace, otherwise, you will get errors.

    jdweng

    Sunday, September 01, 2013 12:12 AM