none
The Old Namespace Not Found Error RRS feed

  • Question

  • I've seen this error on numerous forums and posts and none of the solutions are working.

    Here's everything in one screenshot:

    I've created a new Class Library (TacticalAILib) I've added it to the project and... there it is: The type or namespace name cannot be found.

    I've tried everything. I've removed it from the project and then added it again. I've cleaned and rebuilt the project. I've double-checked the spelling. I've double-checked that everybody is using Net Framework 4.7:

    I've tried every solution I've found on various forums.

    Does anybody have ANY IDEAS?

    • Edited by Zetar Friday, April 19, 2019 4:55 PM
    Friday, April 19, 2019 4:54 PM

Answers

  • How did you add a reference to TacticalAILib in your GSBPSandBox project? Simply adding a project to a solution isn't sufficient.

    If you put a line referencing a type in that library into your other project and then quick action on it do you get the option of adding a reference and/or adding a using statement?

    //Quick action on type name
    var obj = new MATEUnit();

    Did you restart VS after adding a reference and see if the problem goes away? 

    Try deleting the `.vs` folder in the solution to see if it is a caching issue.

    The library does compile correctly before trying to add a reference to it in another project right?

    Can you replicate this on another machine?


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Zetar Friday, April 19, 2019 7:13 PM
    Friday, April 19, 2019 5:54 PM
    Moderator
  • From the caller project, right-click on "References", "Add Reference", tab "Projects", and place an X in the checkbox for the project that you are trying to call.
    • Marked as answer by Zetar Friday, April 19, 2019 8:26 PM
    Friday, April 19, 2019 7:09 PM
    Moderator

All replies

  • How did you add a reference to TacticalAILib in your GSBPSandBox project? Simply adding a project to a solution isn't sufficient.

    If you put a line referencing a type in that library into your other project and then quick action on it do you get the option of adding a reference and/or adding a using statement?

    //Quick action on type name
    var obj = new MATEUnit();

    Did you restart VS after adding a reference and see if the problem goes away? 

    Try deleting the `.vs` folder in the solution to see if it is a caching issue.

    The library does compile correctly before trying to add a reference to it in another project right?

    Can you replicate this on another machine?


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Zetar Friday, April 19, 2019 7:13 PM
    Friday, April 19, 2019 5:54 PM
    Moderator
  • I've done most of those things: deleting .vs, restarting Visual Studio, etc. If simply adding a project to a solution isn't sufficient, what is the correct method?

    Thanks for responding!

    Friday, April 19, 2019 6:33 PM
  • From the caller project, right-click on "References", "Add Reference", tab "Projects", and place an X in the checkbox for the project that you are trying to call.
    • Marked as answer by Zetar Friday, April 19, 2019 8:26 PM
    Friday, April 19, 2019 7:09 PM
    Moderator
  • Thanks to you I figured it out. I forgot to add a reference to it. Thanks!
    Friday, April 19, 2019 7:13 PM
  • To use a project A (TacticalALib in your example) in another project B (GSBPSandBox in your example) you have to add a reference to it. 

    Background: A solution is nothing but a set of (probably related) projects. The compiler/IDE makes no assumptions about how the projects relate to each other (if any). In order to use functionality from project A in project B you have to add a reference to A inside B. This tells the build system that before B can be compiled A must first be compiled. This sets up the dependency tree that projects have.  For projects in the same solution you use a project reference. For projects in other solutions or for which you don't have a project then you have to use a binary reference.

    Adding a reference the long way

    1) In Solution Explorer select the project that has the dependency (project B - GSBPSandbox). Right click and select `Add\Reference` or select the References node and then right click and select `Add Reference`.

    2) In the Reference Manager dialog select the appropriate category of reference on the left side. For framework assemblies you'll use `Assemblies`. For projects in the current solution select `Projects`. For binary references you'd use `Browse` to find the assembly. 

    3) For a project reference (in the same solution) select `Projects` and then click the box next to the other project(s) the current project will depend on (project A - TacticalALib).

    4) Click OK to add the reference. If there are compatibility issue then errors should occur.

    Note that you cannot have circular dependencies (e.g. project A relies on project B which relies on project A).

    Adding a reference the more automatic way:

    1) In the project that has a dependency (project B - GBPSandbox) put in some code that references a type contained in the other project (project A - TacticalALib) such as `new MATEUnit()`.

    2) The compiler will report an unrecognized identifier after a second or two.

    3) Mouse over the identifier and quick action should pop up on that line or near the cursor (depends).

    4) Alternatively right click the identifier and select Quick Actions from the context menu.

    5) A list of codefixes will appear based upon what the compiler sees as wrong with the code.

    6) For an unknown identifier you'll generally get a couple of options.

       a) `Using xyz` where xyz is a namespace name. This means the project already has a reference to the assembly in this project but you haven't added a using statement for the namespace yet. Clicking this option generates a using statement in the current code and the error should go away.

       b) `Add a reference to asm` where asm is a project or assembly name. This means the project does not currently reference the correct assembly but the identifier is defined in a project in the current solution. It will also be an option if the needed assembly is a framework assembly. Clicking this option adds a reference to the dependent assembly and then adds the appropriate using statement, if needed. After this the error should go away.

       c) `Install package pkg` where pkg is a package name. This means the project does not currently reference the correct assembly and no other project in the solution has the identifier but previously a NuGet package was installed that did have a matching type so the IDE is providing the option of adding a NuGet reference to that package again and adding the appropriate using statement, if needed. After this the error should go away as well.

       d) `Find and install pkg` where pkg is a package name. This is the same as the previous but the IDE doesn't necessarily know the package and so it'll provide the option to try to find it in NuGet. This will require manual effort.

    For your case I'd put the code I posted in your GBPSandbox project. Then right click the `MATEUnit` type and use quick action to autoadd a reference to the TacticalALib project that is already in your solution. Once the project has a reference then trying to reference a type in that assembly in other source files of this same project will then be able to resolve by simply adding the appropriate using statement.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, April 19, 2019 7:20 PM
    Moderator