混淆和 protobuf.net - 异常:未定义默认枚举值
当我尝试序列化混淆项目中包含枚举的类时,出现以下异常:
ProtoBuf.ProtoException:未为可选属性 Y 定义默认枚举值 X
如果我从混淆中排除所有受影响的枚举,则一切运行正常,但是,我切换到 protobuf.net 以便能够混淆更多代码内容,所以我希望有更好的解决方案。
那么,是混淆器给 protobuf.net 带来了太多混乱,还是我声明枚举的方式错误了?
我已经尝试过:
[ProtoContract]
public enum X
{
Y, Z
}
而且
[ProtoContract]
public enum X
{
Y=0, Z=1
}
根本没有合同,还有其他一些不那么明显的事情,但除了排除之外没有任何作用。 顺便说一句:在使用 protobuf.net 时,是否有一个我们必须与枚举相关的示例?
I'm being presented with the following Exception when trying to serialize a class that contains enums in an obfuscated project:
ProtoBuf.ProtoException: The default enum value X is not defined for the optional property Y
If I exclude all affected enums from obfuscation everything runs fine, however, I switched to protobuf.net to be able to obfuscate more code content so I hope there is a better solution.
So is it the obfuscator which messes around to much for protobuf.net or am I declaring my enums the wrong way?
I have tried:
[ProtoContract]
public enum X
{
Y, Z
}
and
[ProtoContract]
public enum X
{
Y=0, Z=1
}
also without a contract at all and several other not so obvious things but nothing except exclusion works. By the way: Is there an example somewhere what we have to do with enums when using protobuf.net?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯……老实说,我不知道枚举的混淆问题; 我必须准备一个测试用例来进行调查。
如果您能告诉我您正在使用什么混淆工具,将会有所帮助。 了解如何指定默认值(即属性定义)也将有所帮助。
请注意,它仅在枚举的情况下真正考虑
[ProtoEnum]
([ProtoContract]
可用于为其指定名称,但除非您正在生成 .proto 文件,这不太可能) - 但我不希望它在这种情况下产生任何影响(这用于将“在线”值更改为与 .NET 中不同的值)。 至于例子; 我承认我在文档上落后了 - 但是我已将此记录为第 59 期; 如果您能让我知道上述详细信息(在此处或给我发送电子邮件 - 查看我的个人资料),我会尝试进行调查。
(如果你不知道,我是 protobuf-net 的作者)
我尝试了以下方法(使用 .NET Reactor)并且运行良好......枚举值的隐式默认值零是最有可能的嫌疑。 您能提供一个显示失败的测试用例吗?
Hmmm.... I'm honestly not aware of obfuscation issues with enums; I will have to prepare a test case to investigate.
It would help if you could tell me what obfuscation tool you are using. It would also help to see how you are specifying the default value (i.e. the property definition).
Note that it only really considers
[ProtoEnum]
in the case of enums (the[ProtoContract]
can be used to give it a name, but this isn't used unless you are generating .proto files, which is very unlikely) - but I don't expect it to impact anything in this case (this is used to change the value "on the wire" to different values than are in .NET). As for examples; I confess I'm behind on the documentation - but the enum test cases here show typical usage.I've logged this as Issue 59; if you could let me know the details above (either here, or e-mail me - see my profile), I'll try to investigate.
(if you didn't know, I'm the author of protobuf-net)
I tried the following (using .NET Reactor) and it worked fine... the implicit default of zero on enum values is the most likely suspect. Can you supply a test-case that shows it failing?