• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

内部可见不工作吗?

用户头像
it1352
帮助1

问题说明

我正在尝试使用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.

正确答案

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

好友程序集(即可以访问当前程序集的内部类型和成员的程序集)由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[^]

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcffihb
系列文章
更多 icon
同类精品
更多 icon
继续加载