-1

In a specific project (meant for web-services) in my .net solution (Visual Studio), I have added a using directive:

using ourSystem.Common.WPF and I also added the corresponding reference (pointing to the DLL) to the project file.

The web-services project compiles, builds, and works just fine until I try to add the WPF project.

When I add the WPF project, I get the error message:

Error   CS0234  The type or namespace name 'WPF' does not exist in the namespace 'ourSystem.Common' (are you missing an assembly reference?)

I have looked at similar questions on stack overflow and web posts elsewhere, but nothing seems to work.

It appears that the problem must be some sort of incompatibility between files.

NOTE: The Visual Studio Solution (VS2019) I am working on has several projects, and this DLL/namespace works in many of the other projects, just not the project that I am trying to add it to.

Both the WPF project and the project I am trying to reference it in are v4.5.2 Thus, at least for that attribute, they should be compatible.

For what it's worth, I have also tried unloading projects, and reloading them. This often changes the error count from about 4 (all the same message) to well over 100, and it seems to lose all references to everything.

Edit added: It turns out the relative structure of the many projects within the solution (which I didn't describe in the original post of this question) was key in finding an answer. See my own answer below for details, if interested.

Any suggestions on how to fix this problem?

JosephDoggie
  • 1,514
  • 4
  • 27
  • 57
  • 1
    Seems to be either: WPF namespace does not exist or the reference is not compatible. You could use the assembly browser to see if the WPF namespace is in there. – Stefan Aug 16 '22 at 18:14
  • 1
    Also look under dependencies to see if the dll is correctly referenced. If this all is the case it will work - if it doesn't work, than one of these errors is causing it. – Stefan Aug 16 '22 at 18:15
  • 1
    Can you provide more evidence of the assembly containing the namespace and it is referred to correctly? – Stefan Aug 16 '22 at 18:16
  • 1
    Also please make sure it is not a typo. – Stefan Aug 16 '22 at 18:16
  • 1
    @Stefan, thanks for the suggestions. As I edited into the comments, it turns out the directory structure was key in my case. Please also see my own answer, if interested. Thanks – JosephDoggie Aug 17 '22 at 13:58

1 Answers1

1

I was able to fix it essentially as follows:

I refactored the directory structure.

It had been A-> Top Level GUI project that had called B & C

B-> Folder with the projects used by A including WPF, but not Web Service Project.

C-> Folder with Web Service Project

I then moved all of C to the same layer as B. Having them in the same folder seemed to 'placate' the compiler.

I am not claiming that this was absolutely needed, nor that it should always be done, however it worked in my case.

I had to also redo some code within the C project to account for different layering within C's own folders (especially packages folder), as it still had legacy code as if it were the top-level project. The following link was useful in that: (especially the answer by Nikita R.)

How to fix re-layering problem

JosephDoggie
  • 1,514
  • 4
  • 27
  • 57