Search Unity

Bug CS0246 Namespace could not been found

Discussion in 'Scripting' started by c_koenig, Apr 22, 2023.

  1. c_koenig

    c_koenig

    Joined:
    Feb 12, 2021
    Posts:
    3
    Hi,

    I am receiving the CS0246 error message which says that a namespace cannot be found. The folder structure is as follows:

    Assets{
    Scripts{
    scriptA - namespace: Hololens.Communication
    QR{
    scriptB - namespace: Microsoft.MixedReality.SampleQRCodes​
    }​
    }​
    }
    Packages{
    Folders{
    scriptC - namepsace: Microsoft.MixedReality.Toolkit.UI​
    }​
    }

    The behavior and occurrence of errors are as follows:
    scriptB is unable to find the Hololens namespace, but it can access the namespace of scriptC.


    I have tried moving scriptB into the parent folder (where scriptA resides) but doing so causes scriptA somehow throwing the CS0246 error with respect to scriptC, thus making it unable to find Microsoft.MixedReality.Toolkit.UI.

    I assume this error happens because the Microsoft.MixedReality... namespace is in the same folder as well as in another folder in packages?
    Thus, I also tried moving the QR scripts to their own folder in Assets, but the files in Scripts still couldn't be found like in the first error.

    I have tried to regenerate the files, as suggested in https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/, but it didn't help. I also tried deleting the .csproj file, as recommended in this blog entry: https://blog.terresquall.com/2020/11/fixing-visual-studios-intellisense-autocomplete-in-unity/.

    Do you have any ideas what could be causing this?


    Unity Version: 2021.3.18f
    Visual Studio: 2022 17.5.2
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Yes. You have a compiler error.

    Moving files or posting to the forum generally doesn't fix compiler errors.

    Here's what does:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
    c_koenig likes this.
  3. c_koenig

    c_koenig

    Joined:
    Feb 12, 2021
    Posts:
    3
    Kurt-Dekker likes this.