我已经实现了Generating an Xml Serialization assembly as part of my build接受的答案中提到的更改
<Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
<!-- Delete the file because I can't figure out how to force the SGen task. -->
<Delete Files="$(TargetDir)$(TargetName).XmlSerializers.dll" ContinueOnError="true" />
<SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)" Platform="$(Platform)">
<Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
</SGen>
</Target>生成exe项目时的错误消息:
错误14反映类型'myNamespace.myAssembly.myForm.MicroContact‘的错误。C:\dev\src\ myClient \myClient\SGEN myClient
下面是MicroContact的代码(这里没有什么是唯一的):
Public Class MicroContact
Implements IComparable
Private _id As Long
Private _name As String
Public Property Id() As Long
Get
Return _id
End Get
Set(ByVal value As Long)
_id = value
End Set
End Property
Public Property NoTitleFullName() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Sub New()
_name = ""
End Sub
Public Sub New(ByVal id As Long, ByVal name As String)
_id = id
_name = name
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Return String.Compare(Me.NoTitleFullName, CType(obj, MicroContact).NoTitleFullName, True)
End Function
End Class是否有任何方法可以获得构建错误的内部异常?
发布于 2011-11-07 07:14:24
正如Marc所指出的,在bin目录中运行sgen /v MyClient.exe会产生更多信息。
这个问题是由多个共享相同名称的类造成的,在这种情况下,两个表单都实现了相同的MicroContact类,一个是从另一个中复制的。
发布于 2016-07-21 10:00:06
正如前面的答案所提到的,最常见的问题是重复的类型名称。然而,解决这一问题的办法是多种多样的:
[XmlType("NewTypeName")]
[System.Xml.Serialization.XmlType(AnonymousType = true)]属性更改其xml序列化名称。[XmlElement(Namespace="http://example.com")]如果你用另一种方式解决这个问题--我想知道。
https://stackoverflow.com/questions/8033429
复制相似问题