开发者

How to diagnose an issue with csproj references?

开发者 https://www.devze.com 2023-04-06 11:00 出处:网络
I have an issue with a class being used in another project. Visual studio is able to add a using statement using Resolve (Ctrl+.), but:

I have an issue with a class being used in another project.

Visual studio is able to add a using statement using Resolve (Ctrl+.), but:

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

Resolving this again fully qualifies the type but the namespace in the type path is highlighted as not being found.

The namespace appears also in intellisense and the target class is visible in the Object Browser.

Removing unused namespaces removes the added using statement.

I've tried:

  1. Rebuild.
  2. Confirm project dependency in solution options.
  3. Delete reference and re-add.
  4. Confirm class accessibility (despite namespace not being found).
  5. Checked build mode (Debug/Release).
  6. Restart Visual Studio.
  7. Cleared bin folders in both projects.
  8. Restart machine.

What is the next开发者_Go百科 step to diagnosing this baffling issue?


This is likely to be a .Net framework versioning issue. The class being referenced was probably built using a higher version of the framework.

Try checking your framework versions all align in properties, build settings. A project cannot reference an assembly of a higher framework version.


Last time I had this problem my class was not marked public. Just an idea.


This issue was caused by similar namespaces e.g. Company.Product.Project and Product.Project with:

namespace Company.Product.Project
{
        using Product.Project;

The class was in Product.Project, but the compiler was searching for Company.Product.Project.

See: Should 'using' statements be inside or outside the namespace? for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号