VS 2022 wrongly reports error CS0246

Frank Hindle 0 Reputation points
2025-01-19T22:11:58.6866667+00:00

Visual Studio 2022 (version 17.12.4) is reporting error CS0246 'type or namespace could not be found...' for a class EposNowReportsDataSnapshot in a declaration:

EposNowReportsDataSnapshot dataSnap = new EposNowReportsDataSnapshot();

The error report is incorrect - the class is declared in a referenced shared project, and the project successfully compiles and runs.

Restarting VS and cleaning and rebuilding the project makes no difference. Is there any way of clearing this report?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,368 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,217 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 32,421 Reputation points Microsoft Vendor
    2025-01-20T10:23:02.6533333+00:00

    Hello @Frank Hindle ,

    Welcome to Microsoft Q&A forum.

    Is there any warning icon displayed in the referenced assemblies or NuGet packages, like:User's image

    If so, perhaps, try to re-add/re-install the assemblies and NuGet packages, then check again. Also, could you confirm that the class/namespace/type is indeed from the added assemblies/NuGet packages(in case there are multiple same-name assembly files, but with the different content/version/path…)?


    Update1:

    I notice that you have cleaned the project, please kindly double check that following folders: "bin", "obj", .vs(hidden folder), have been cleared manually and then rebuild your project(some files might not be cleared if you just click Build => Clean Solution to clean the solution).

    User's image

    User's image

    I think you can also try to re-reference the shared project.

    There must be some small points that we missed. Could you share(Note: avoid the privacy information) us some corresponding screenshots to check further? Such as project structures, VS Error List/Output Window, the reference manager, the corresponding definition and the code like:

    User's image

    User's image

    Please feel free to let us know the results.

    Best Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.