tags:

views:

21

answers:

1

Hi guys,

I am having problem using [DataContract(IsReference = true)] on base/derive classess. I have the following base class and child class. I have no control (can't modify it) over baseclass

public class BaseDto
{
}

[DataContract(IsReference = true)]
public class NodeTypeDto : BaseDto
{
 ....
}

When I add service reference in wcftestclient, I get the following error:

System.Runtime.Serialization.InvalidDataContractException:

The IsReference setting for type 'Dtos.NodeTypeDto' is 'True', but the same setting for its parent class 'Dtos.BaseDto' is 'False'. Derived types must have the same value for IsReference as the base type. Change the setting on type 'Dtos.NodeTypeDto' to 'False', or on type 'Dtos.BaseDto' to 'True', or do not set IsReference explicitly

I can't modify the BaseDto because I have not got access to the source code. Any ideas?

Here is the full service trace

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"&gt;

  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"&gt;

    <EventID>131076</EventID>
    <Type>3</Type>
    <SubType Name="Error">0</SubType>
    <Level>2</Level>
    <TimeCreated SystemTime="2010-06-30T16:11:10.6108465Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{e34f66f4-5992-475c-b57d-05ad21cd238e}" />
    <Execution ProcessName="WebDev.WebServer20" ProcessID="2348"
    ThreadID="14" />
    <Channel />
    <Computer>PC-008915</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
        Severity="Error">
          <TraceIdentifier>
          http://msdn.microsoft.com/en-GB/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx&lt;/TraceIdentifier&gt;
          <Description>Handling an exception.</Description>
          <AppDomain>5ab4f443-9-129223871739836383</AppDomain>
          <Exception>
            <ExceptionType>System.InvalidOperationException,
            mscorlib, Version=2.0.0.0, Culture=neutral,
            PublicKeyToken=b77a5c561934e089</ExceptionType>
            <Message>An exception was thrown in a call to a WSDL
            export extension:
            System.ServiceModel.Description.DataContractSerializerOperationBehavior
            contract: http://tempuri.org/:IWcfService&lt;/Message&gt;
            <StackTrace>at
            System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension
            extension) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message
            httpGetRequest, String[] queries, Message&amp;
            replyMessage) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message
            httpGetRequest) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message
            message) at SyncInvokeGet(Object , Object[] , Object[]
            ) at
            System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
            instance, Object[] inputs, Object[]&amp; outputs) at
            System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
            isOperationContextSet)</StackTrace>
            <ExceptionString>System.InvalidOperationException: An
            exception was thrown in a call to a WSDL export
            extension:
            System.ServiceModel.Description.DataContractSerializerOperationBehavior
            contract: http://tempuri.org/:IWcfService ---&gt;
            System.Runtime.Serialization.InvalidDataContractException:
            The IsReference setting for type
            'Dtos.NodeTypeDto' is 'True', but the same
            setting for its parent class 'Dtos.BaseDto'
            is 'False'. Derived types must have the same value for
            IsReference as the base type. Change the setting on
            type 'Dtos.NodeTypeDto' to 'False', or on
            type 'Dtos.BaseDto' to 'True', or do not set
            IsReference explicitly. at
            System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String
            message, Type type) at
            System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.EnsureIsReferenceImported(Type
            type) at
            System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.ImportDataMembers()
            at
            System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper..ctor(Type
            type) at
            System.Runtime.Serialization.ClassDataContract..ctor(Type
            type) at
            System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32
            id, RuntimeTypeHandle typeHandle, Type type) at
            System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32
            id, RuntimeTypeHandle typeHandle, Type type) at
            System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle
            typeHandle, Type type, SerializationMode mode) at
            System.Runtime.Serialization.DataContractSet.GetDataContract(Type
            clrType) at
            System.Runtime.Serialization.DataContractSet.GetItemTypeDataContract(CollectionDataContract
            collectionContract) at
            System.Runtime.Serialization.DataContractSet.AddCollectionDataContract(CollectionDataContract
            collectionDataContract) at
            System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName
            name, DataContract dataContract) at
            System.Runtime.Serialization.DataContractSet.Add(Type
            type) at
            System.Runtime.Serialization.XsdDataContractExporter.Export(Type
            type) at
            System.ServiceModel.Description.MessageContractExporter.ExportType(Type
            type, String partName, String operationName,
            XmlSchemaType&amp; xsdType) at
            System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32
            messageIndex, Object state) at
            System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32
            messageIndex, Object state) at
            System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
            at
            System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter
            exporter, WsdlContractConversionContext
            contractContext) at
            System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext
            contractContext, IWsdlExportExtension extension) ---
            End of inner exception stack trace --- at
            System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension
            extension) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
            at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message
            httpGetRequest, String[] queries, Message&amp;
            replyMessage) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message
            httpGetRequest) at
            System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message
            message) at SyncInvokeGet(Object , Object[] , Object[]
            ) at
            System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
            instance, Object[] inputs, Object[]&amp; outputs) at
            System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;
            rpc) at
            System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
            isOperationContextSet)</ExceptionString>
            <InnerException>
              <ExceptionType>
              System.Runtime.Serialization.InvalidDataContractException,
              System.Runtime.Serialization, Version=3.0.0.0,
              Culture=neutral,
              PublicKeyToken=b77a5c561934e089</ExceptionType>
              <Message>The IsReference setting for type
              'Dtos.NodeTypeDto' is 'True', but the same
              setting for its parent class
              'Dtos.BaseDto' is 'False'. Derived types
              must have the same value for IsReference as the base
              type. Change the setting on type
              'Dtos.NodeTypeDto' to 'False', or on type
              'Dtos.BaseDto' to 'True', or do not set
              IsReference explicitly.</Message>
              <StackTrace>at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String
              message, Type type) at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.EnsureIsReferenceImported(Type
              type) at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.ImportDataMembers()
              at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper..ctor(Type
              type) at
              System.Runtime.Serialization.ClassDataContract..ctor(Type
              type) at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32
              id, RuntimeTypeHandle typeHandle, Type type) at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32
              id, RuntimeTypeHandle typeHandle, Type type) at
              System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle
              typeHandle, Type type, SerializationMode mode) at
              System.Runtime.Serialization.DataContractSet.GetDataContract(Type
              clrType) at
              System.Runtime.Serialization.DataContractSet.GetItemTypeDataContract(CollectionDataContract
              collectionContract) at
              System.Runtime.Serialization.DataContractSet.AddCollectionDataContract(CollectionDataContract
              collectionDataContract) at
              System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName
              name, DataContract dataContract) at
              System.Runtime.Serialization.DataContractSet.Add(Type
              type) at
              System.Runtime.Serialization.XsdDataContractExporter.Export(Type
              type) at
              System.ServiceModel.Description.MessageContractExporter.ExportType(Type
              type, String partName, String operationName,
              XmlSchemaType&amp; xsdType) at
              System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32
              messageIndex, Object state) at
              System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32
              messageIndex, Object state) at
              System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
              at
              System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter
              exporter, WsdlContractConversionContext
              contractContext) at
              System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext
              contractContext, IWsdlExportExtension
              extension)</StackTrace>
              <ExceptionString>
              System.Runtime.Serialization.InvalidDataContractException:
              The IsReference setting for type
              'Dtos.NodeTypeDto' is 'True', but the same
              setting for its parent class
              'Dtos.BaseDto' is 'False'. Derived types
              must have the same value for IsReference as the base
              type. Change the setting on type
              'Dtos.NodeTypeDto' to 'False', or on type
              'Dtos.BaseDto' to 'True', or do not set
              IsReference explicitly. at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String
              message, Type type) at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.EnsureIsReferenceImported(Type
              type) at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.ImportDataMembers()
              at
              System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper..ctor(Type
              type) at
              System.Runtime.Serialization.ClassDataContract..ctor(Type
              type) at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32
              id, RuntimeTypeHandle typeHandle, Type type) at
              System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32
              id, RuntimeTypeHandle typeHandle, Type type) at
              System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle
              typeHandle, Type type, SerializationMode mode) at
              System.Runtime.Serialization.DataContractSet.GetDataContract(Type
              clrType) at
              System.Runtime.Serialization.DataContractSet.GetItemTypeDataContract(CollectionDataContract
              collectionContract) at
              System.Runtime.Serialization.DataContractSet.AddCollectionDataContract(CollectionDataContract
              collectionDataContract) at
              System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName
              name, DataContract dataContract) at
              System.Runtime.Serialization.DataContractSet.Add(Type
              type) at
              System.Runtime.Serialization.XsdDataContractExporter.Export(Type
              type) at
              System.ServiceModel.Description.MessageContractExporter.ExportType(Type
              type, String partName, String operationName,
              XmlSchemaType&amp; xsdType) at
              System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32
              messageIndex, Object state) at
              System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32
              messageIndex, Object state) at
              System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
              at
              System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter
              exporter, WsdlContractConversionContext
              contractContext) at
              System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext
              contractContext, IWsdlExportExtension
              extension)</ExceptionString>
            </InnerException>
          </Exception>
        </TraceRecord>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>