Type or Namespace could not be found. But references are there
Asked Answered
H

6

5

Currently I am using 2 references in my C# project:

using Czm.Perimetry.Analysis.Core;
using Czm.Perimetry.Analysis.IO;

And when I look at my project in Visual Studio no errors come up. However when I run the project I get:

Error   CS0246  The type or namespace name 'Czm' could not be found
(are you missing a using directive or an assembly reference?)       

I don't understand what's going on, and nothing else with the project comes up with an error.

Hulda answered 17/10, 2019 at 17:15 Comment(0)
D
6

Check if the assemblies referenced (Czm) are running against the same framework your project is.

If not, VS might false-positive the reference, while being unable to load the assemblies correctly in runtime.

Disturbed answered 17/10, 2019 at 17:17 Comment(0)
N
6

In my case just now, these errors showed up for no discernable reason while refactoring and moving around namespaces in a library being referenced by another library in the project. The fix was to unload and reload the library projects.

Nickelsen answered 1/1, 2021 at 16:54 Comment(1)
You're my hero, I wish I could upvote this more.Slump
S
1

If you have the same project referenced in more than one other project or solution, double-check those. I had to remove and re-add the project reference after I recreated the referenced project from another solution and I supposed the GUID changed.

Spoliation answered 4/12, 2020 at 21:48 Comment(0)
H
0

I updated some references to a new Version of a software's SDK. they needed a higher version of .net than I was using. But I did not get an error about the version of .net. I just got a "could not find reference" like listed in OP. I had to update the project's .net version to match the assemblies referenced and it fixed the problem.

Harveyharvie answered 24/1, 2023 at 22:51 Comment(0)
K
0

It was because of dependencies in the solution not getting linked properly in my case. Below steps resolved my issue:

  1. Go to dependencies in the project
  2. right click on the project then select add project reference.
  3. select the required project references.
  4. Rebuild the solution
Khiva answered 21/7, 2023 at 5:41 Comment(0)
B
0

For me it was the fact that I accidentally changed the version of the framework I was working under, which was different from when I created the classes that could no longer be referenced. When I changed the target framework to match, everything was fine.

Bonacci answered 29/2, 2024 at 0:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.