2012-07-17 1 views
0

해당하지 않습니다, 그러나 그것은 나에게 오류를 제공합니다datacontracts 내가 내 로컬 호스트 및 디버그에서 작동하는 웹 서비스를 얻기 위해 노력 해왔다

System.InvalidOperationException: DataContract for type 'ParticipantDataService.Participant+OutsideAccountDetails+FundCollection' cannot be added to DataContractSet since type 'ParticipantDataService.Participant+FundCollection' with the same data contract name 'ArrayOfFundDetails' in namespace 'http://schemas.datacontract.org/2004/07/ParticipantDataService' is already present and the contracts are not equivalent.

밖에 전에이 오류를 가지고 사람을 했습니까?

감사합니다.

아래의 요약 코드 (참고 : 내 코드는 아닙니다. 이전 개발자의 코드를 수정하고 있습니다. 더 이상 여기에없는 사람도 있습니다. 아래 코드 블록에서이 문제는 기금은 지금, 나는 다른 사람보다 모든 '자금'참조가 더 눈에 보이는했습니다. 감사합니다.)

Namespace COMParticipantNameSpace 
<DataContract(Namespace:="XYZ", Name:="COMParticipant"),       
KnownType(GetType(COMParticipant))> _ 
Public Class COMParticipant 
    Inherits COMResponse 

    Private _FullName As FullName 
    (Other initialized variables...) 

    Protected Friend Sub New... 

    #Region "Properties" 
    <DataMember(Name:="Name", Order:=0)>... 
    <Other DataMembers...> 
    #End Region 

    #Region "Structures" 
    Public Structure FullName... 
      (Other Public Structures) 
    #End Region 
    #Region "Classes" 
    <DataContract(Name:="ParticipantPortfolio")>.... 

    Public Class GroupCollection... 
    End Class 

    <DataContract(Name:="Group")>... 
      <DataMember(Name:="Funds", Order:=6)> _ 
      Public Property Funds() As COMFundCollection 
       Get 
        Return _Funds 
       End Get 
       Set(ByVal value As COMFundCollection) 
        _Funds = value 
       End Set 
      End Property 
    End Class 

    Public Class COMAccountCollection 
     Inherits System.Collections.ObjectModel.Collection(Of COMAccountDetails) 
    End Class 

    <DataContract(Name:="COMAccountDetails")> _ 
    Public Class COMAccountDetails 

     (Other initialized variables...) 
     Private _Funds As COMFundCollection 

     <DataMember Order 0,1,2,3,etc...)>... 

     <DataMember(Name:="Funds", Order:=7)> _ 
     Public Property Funds() As COMFundCollection 
      Get 
       Return _Funds 
      End Get 
      Set(ByVal value As COMFundCollection) 
       _Funds = value 
      End Set 
     End Property 

    End Class 

    Public Class COMFundCollection 
     Inherits System.Collections.ObjectModel.Collection(Of COMFundDetails) 
    End Class 

    Public Class OutsideAccountCollection 
    End Class 

    <DataContract(Name:="OutsideAccountDetails")> _ 
     Public Class OutsideAccountDetails 

     (Other initialized variables...) 
     Private _Funds As FundCollection 

     <Order 1, 2, 3, etc...> 

     <DataMember(Name:="Funds", Order:=15)> _ 
     Public Property Funds() As FundCollection 
      Get 
       Return _Funds 
      End Get 
      Set(ByVal value As FundCollection) 
       _Funds = value 
      End Set 
     End Property 

     Public Class FundCollection 
      Inherits System.Collections.ObjectModel.Collection(Of FundDetails) 
     End Class 

     <DataContract(Name:="FundDetails")>... 

    End Class 

    Public Class TransactionTypeCollection 
     Inherits System.Collections.ObjectModel.Collection(Of TransactionTypeDetail) 
    End Class 
    Public Class TransactionTypeDetail... 
    Public Class TransactionCollection... 

    <DataContract(Name:="Transaction")> _ 
    Public Class Transaction 

     (Other initialized variables...) 
     Private _Funds As TransactionFundCollection 

     <DataMember Order 1,2,3,etc ...> 

     <DataMember(Name:="Funds", Order:=7)> _ 
     Public Property Funds() As TransactionFundCollection 
      Get 
       Return _Funds 
      End Get 
      Set(ByVal value As TransactionFundCollection) 
       _Funds = value 
      End Set 
     End Property 

    End Class 
    Public Class TransactionFundCollection 
     Inherits System.Collections.ObjectModel.Collection(Of TransactionFundDetails) 
    End Class 

    #End Region 
    End Class 

    End Namespace} 
+1

"Fund"라는 두 개의 다른 클래스가 있습니까? –

+0

코드를 게시 할 수 있습니까? –

+0

위의 편집을 참조하십시오. 감사. – user1333792

답변

0

을 문제의 해결책이되지 않는, 내가 같은 오류 메시지가 있었지만. 그래서 다른 사람들이 여기에 게시하는 것이 유용하다고 생각합니다. 제 경우에는 사슬 유전과 관련이 있습니다.

나는 상속을 결정하기 위해 확장 메서드를 호출하는 DerivedTypes라는 기본 클래스 (여기에 설명 된 것과 같습니다 : Generally accepted way to avoid KnownType attribute for every derived class)에 정적 메서드를 가졌습니다. 당신이있는 경우

: 그것은 typeof(C).GetDerivedTypes()를 호출로, (잘못) 너무 많은 종류를 얻을 것이다)

[DataContract] 
[KnownType("DerivedTypes")] 
public class C { 
    internal static Type[] DerivedTypes() { 
    typeof(C).GetDerivedTypes(); 
    } 
} 

(B.DerivedTypes 호출 : B를, B : C는, 다음 C는 다음과 같이해야한다 . 이 경우에도 동일한 오류가 발생했습니다.

B가 아닌 다음 '**'자연스럽게없이

[DataContract] 
[KnownType("DerivedTypes")] 
public class B : C { 
    internal **new** static Type[] DerivedTypes() { 
    typeof(B).GetDerivedTypes(); 
    } 
} 

. 이제 유형 B가 발생하면 B.DerivedTypes()는 해당 부모를 호출하지 않습니다. A에는 하위 클래스가 없으므로 KnownType 특성이 필요하지 않습니다.

Btw, 확장 메서드에 대한 변경 사항은 확장 메서드가 형식 (예 : Assembly.GetAssembly(baseType))의 어셈블리를 사용하고 테스트 목적으로 정적 메서드를 내부적으로 만들었습니다. 개인도 괜찮을 것입니다.

관련 문제