微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net – 反映类型的SGEN错误

我已经实现了 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项目时出现错误信息:

Error 14 There was an error reflecting type ‘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

有没有办法可以获得构建错误的内部异常?

解决方法

正如marc Gravell所指出的,在bin目录中运行sgen / v MyClient.exe会产生更多信息.

问题是由多个共享相同名称的类引起的,在这种情况下,两个表单都实现了相同的microcontact类,而另一个类是从另一个中复制的.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。