C#: type or namespace name 'InternalsVisibleTo' could not be found

Date: 2020-12-26 | csharp | troubleshoot |

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

Overview

I'm trying to make it so my dotnet core test project can test the internals of my source project. To do that I'm using the InternalsVisibleTo attribute. However when I try to compile I'm getting the error:

error CS0246: The type or namespace name 'InternalsVisibleTo' could not be found

How do I fix this?

Solution

Typically errors like this mean you're missing an import of some sort. I was able to fix this by adding this import line at the top of my file:

using System.Runtime.CompilerServices;

Want more like this?

The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.