0

In our WPF application, code that was written weeks ago and did not exhibit the error now shows the IntelliSense error:

The name "foo" does not exist in the namespace "clr-namespace:bar"

where "foo" is any object defined in the default project namespace. The project builds and runs without issue, but IntelliSense insists that there is an error, and therefore none of the visual tools work (designer shows "Build the Project to update the Design view", no properties are shown for elements selected in the XAML code.

The main application is a WPF/C# project, but we link with unmanaged C++ code (image processing with OpenCV 64-bit) through a managed C++ wrapper.

Both Visual Studio 2017 and 2015 exhibit the issue (didn't try anything older).

There are a number of similar questions about this error, and even some answers that come close, but I was not able to resolve the issue with any of the answers I found previously.

Some of the things I tried:

  • Rebuild solution (both using "Rebuild" as well as "Clean" and "Build")
  • Restart Visual Studio
  • Comment out offending code, rebuild, uncomment and rebuild
  • Rebuild solution and projects (both by adding existing projects and copy / pasting code into new files)
  • Deleting the .suo file
  • Changing platform type and rebuilding*

*: as I'm posting this in order to save someone else from wasting 3 days of productivity, I can say that the solution turned out to be related to the platform type. Due our linking to a 64-bit library, the platform type of the C# project was set to x64. Several answers (here, here) suggest switching to x86, rebuilding, and then back to x64, which did work, but only until the solution was closed. Upon reopening the solution or restarting VS, the issue returned.

Community
  • 1
  • 1

1 Answers1

0

The solution turned out to be:

  • setting the Platform target to 'Any CPU'

and crucially

  • unchecking 'Prefer 32-bit'

in the Build section of the C# project properties, and then rebuilding.

Setting to x86 resulted in runtime errors due to linking with the 64-bit library, and 'Any CPU' has 'Prefer 32-bit' checked by default, which results in the same behavior.

Hope this saves others from wasting as much time as I did!

Update: Unfortunately, it seems selecting 'Any CPU' even with 'Prefer 32-bit' unchecked results in the warning:

warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "X.dll", "AMD64". This mismatch may cause runtime failures.

So the only solution is to switch to 'Any CPU', rebuild to make the IntelliSense error go away, then switch back to x64 so that the code can actually run. This needs to be done each time the solution is opened.

  • Hi MetalWanderer, thank you for your sharing, could you please mark it as answer when you are free? It will help others to easier search this reply, it just a reminder :) – Sara Liu - MSFT Apr 26 '17 at 05:56