question

RodAtWork avatar image
0 Votes"
RodAtWork asked CaleSweeney-8946 answered

Getting error CS0246 in a unit test, but I'm certain I've included the correct references

I have a Shared Project, which at the moment is a part of a bare bones WPF project. It builds and runs fine. Next I'm trying to add a unit test (MSTest) project to the solution, to test the Shared Project. I've made a reference to the shared project. The shared project has some methods which are used for doing conversion of hex string values to Color data type, that is used in WPF. I've included references to both the WindowsBase and System.Windows assemblies in the unit test project. However, when I try to build the solution now, it fails with the following error:

Error CS0246 The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) EmptyWPF.Tests D:\Src\CoreShared\CoreShared\Common\ColorHelper.cs 10 Active

I really thought I'd included all references that are needed for building the solution, even with a unit test that references the shared project. I'm not sure why I'm getting this error.

I'm using VS 2019.

windows-wpf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you clean the solution and rebuild it?

Does the reference shows correctly in Visual Studio Editor?

0 Votes 0 ·

I hadn't cleaned and rebuilt the solution. Just did that. It didn't get rid of the error.

I think it's showing the unit test project correctly in the Visual Studio Editor. Here's a screen shot of the unit test project:

7188-unit-test-in-solution-explorer.jpg

The reference to CoreShared is the shared project.

FWIW, I just added a reference to the EmptyWPF project, which also references CoreShared. It didn't prevent the CS0246 errors complaining about the Color object. So, I'm removing EmptyWPF.


0 Votes 0 ·
RodAtWork avatar image
0 Votes"
RodAtWork answered

Never mind, I found the problem. I hadn't included the PresentationCore assembly.

My bad.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CaleSweeney-8946 avatar image
0 Votes"
CaleSweeney-8946 answered

For me and my separate xunit test, I had this problem. Stranger still everything was building and running fine.

  1. In visual studio 2019, right click on the unit test project in the solution explorer.

  2. Add > References

  3. Uncheck the main projects that your unit test project references.

  4. Click OK.

  5. Go back in, re-add those projects.

  6. Click OK.

You should be all set.

I think somehow the configuration settings for project references get corrupted somehow.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.