InternalsVisibleTo 属性不起作用 [英] InternalsVisibleTo attribute isn't working

查看:28
本文介绍了InternalsVisibleTo 属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 InternalsVisibleTo 程序集属性使 .NET 类库中的内部类对我的单元测试项目可见.出于某种原因,我不断收到一条错误消息,内容为:

I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reason, I keep getting an error message that says:

'MyClassName' 由于其保护级别而无法访问

'MyClassName' is inaccessible due to its protection level

两个程序集都已签名,并且我在属性声明中列出了正确的密钥.有什么想法吗?

Both assemblies are signed and I have the correct key listed in the attribute declaration. Any ideas?

推荐答案

您确定您在属性中指定了正确的公钥吗?请注意,您需要指定完整的公钥,而不仅仅是公钥令牌.它看起来像:

Are you absolutely sure you have the correct public key specified in the attribute? Note that you need to specify the full public key, not just the public key token. It looks something like:

[assembly: InternalsVisibleTo("MyFriendAssembly,
PublicKey=0024000004800000940000000602000000240000525341310004000001000100F73
F4DDC11F0CA6209BC63EFCBBAC3DACB04B612E04FA07F01D919FB5A1579D20283DC12901C8B66
A08FB8A9CB6A5E81989007B3AA43CD7442BED6D21F4D33FB590A46420FB75265C889D536A9519
674440C3C2FB06C5924360243CACD4B641BE574C31A434CE845323395842FAAF106B234C2C140
6E2F553073FF557D2DB6C5")]

它是 320 个左右的十六进制数字.不确定为什么需要指定完整的公钥 - 可能只使用在其他程序集引用中使用的公钥令牌,这样有人会更容易欺骗朋友程序集的身份.

It's 320 or so hex digits. Not sure why you need to specify the full public key - possibly with just the public key token that is used in other assembly references it would be easier for someone to spoof the friend assembly's identity.

这篇关于InternalsVisibleTo 属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆