我有一个对XmlSerializer类型有效的:
public class MyItem
{
public MyItem() {
Values = new List<string>();
}
public List<string> Values { get; private set; }
}它成功地序列化和反序列化(完整的代码示例在这里http://ideone.com/s2PvSB)。但是,我无法为此类型生成.XmlSerializers.dll,SGen失败,错误代码为:
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.33440]
Copyright (C) Microsoft Corporation. All rights reserved.
EXEC : error : Unable to generate a temporary class (result=1).
EXEC : error CS0200: Property or indexer 'TestSGen.MyItem.Values' cannot be assigned to -- it is read only从PostBuild事件调用的SGen为
"$(TargetFrameworkSDKToolsDirectory)SGen.exe" /Assembly:"$(TargetFileName)" /Type:"TestSGen.MyItem" /Force是SGen中的错误还是记录在案的行为?
发布于 2013-11-13 03:09:05
这似乎很奇怪,因为代码链接确实对我有效。如果您将List<string>更改为string[],它将不起作用。VS对collection initializers做了什么奇怪的事情吗?也许这可以让你的代码正常运行,但是SGen不能使用同样的技巧?
https://stackoverflow.com/questions/19936961
复制相似问题