sgen.exe 如何决定为哪些类型生成序列化程序?
您可以使用 sgen.exe 提前创建序列化程序集,而不是即时创建它们。
但它如何决定为哪些类型创建序列化器呢?我尝试改用 sgen,但它一直告诉我它找不到任何适用的类型。是否有必须添加的属性?或者我需要手动指定类型?
You can use sgen.exe
to create serialization assemblies ahead of time rather than have them created on the fly.
But how does it decide what types to make serializers for? I've tried to switch to using sgen, but it's been telling me that it can't find any applicable types. Is there an attribute you have to add? Or will I need to manually specify the types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜这是因为类型不是公共的 - XML 序列化仅适用于公共类型。
I'd guess this is because the types weren't public - XML serialisation only works with public types.
VS触发的sgen(即通过属性->构建->生成序列化程序集)实际上没有生成序列化程序集的最常见原因是因为VS中默认的Sgen构建任务默认包含/proxytypes开关,并且有没有办法把它关掉。此开关告诉 sgen 仅生成 Xml Web 服务代理类型的序列化程序,如文档 这里。要生成其他类型的序列化程序,您可以通过添加自己的自定义任务来覆盖默认行为,如 生成 Xml 序列化程序集作为我的构建的一部分。您可以更进一步,仅指定您希望通过 Types 参数生成序列化代码的类型,例如:
The most common reason for VS-triggered sgen (i.e. via Properties->Build->Generate serialization assembly) to not actually produce a serialization assembly is because the default Sgen build task in VS includes the /proxytypes switch by default, and there is no way to turn it off. This switch tells sgen to only generate serializers for Xml Web service proxy types, as documented here. To generate serializers for other types, you can override the default behavior by adding your own custom task as described in Generating an Xml Serialization assembly as part of my build. You can go further and specify only the types you want serialization code generated for via the Types parameter, e.g.: