InternalsVisibleTo causes CS0246 error: The Type o

2019-05-04 18:21发布

问题:

I am trying to enable one assembly to access another assembly's internal classes by adding

[assembly:InternalsVisibleTo("assembly-name")]

to the second assembly. However, this causes the following error:

error CS0246: The type or namespace name 'InternalsVisibleTo' could not be found (are you missing a using directive or an assembly reference?)

I am following the examples here: MSDN Reference

What am I doing wrong?

回答1:

Make sure you import System.Runtime.CompilerServices. Or use a fully qualified name.

[assembly:System.Runtime.CompilerServices.InternalsVisibleTo("assembly-name")]