question

RodAtWork avatar image
0 Votes"
RodAtWork asked ·

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.

wpf
· 2
10 |1000 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 · ·

1 Answer

RodAtWork avatar image
0 Votes"
RodAtWork answered ·

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

My bad.

· Share
10 |1000 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.