内部可见不工作吗? [英] InternalsVisibleTo not working?

查看:72
本文介绍了内部可见不工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Newtonsofts的JSON反序列化器反序列化对象.它反序列化的对象需要在属性上具有私有设置器.为此,我尝试将内部属性公开给AssemblyInfo.cs中的Newtonsoft.Json程序集,但这失败了.这是代码行:

Im trying to deserialize an object using Newtonsofts''s JSON deserializer. The object it deserilizes to needs to have private setters on the properties. To achieve this, I tried exposing internal properties to the Newtonsoft.Json assembly in AssemblyInfo.cs but this failed. Here is the line of code:

[assembly: InternalsVisibleTo("Newtonsoft.Json, PublicKey=0024{ shortened }4002c7")]



缩短了公钥的可读性.



The public key is shortened for readability.

推荐答案

要检查的地方是两个程序集是否都具有强名称,或者两者都是未签名的.

好友程序集(即可以访问当前程序集的内部类型和成员的程序集)由InternalsVisibleToAttribute构造函数标识.当前程序集和目标程序集都必须未签名,或者都必须使用强名称签名.如果使用强名签名,则InternalsVisibleToAttribute构造函数的参数必须包含完整的公钥以及程序集的名称.

http://msdn.microsoft.com/en-us/library/system. runtime.compilerservices.internalsvisibletoattribute.aspx [ ^ ]
One area to check out is whether both assemblies have a strong name, or both are unsigned.

The friend assembly (that is, the assembly that can access the current assembly''s internal types and members) is identified by the InternalsVisibleToAttribute constructor. Both the current and the target assembly must be unsigned, or both must be signed with a strong name. If they are signed with a strong name, the argument to the InternalsVisibleToAttribute constructor must include the full public key as well as the name of the assembly.

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx[^]


这篇关于内部可见不工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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