Answered System.RuntimeType with data contract name is not expected!!

  • Thursday, May 08, 2008 2:43 PM
     
     

    Hi guys,

     

    I'm invoking WCF service method with following signature

     

    Code Snippet

    [ServiceContract]

    [ServiceKnownType(typeof(DataScenario))]

    [ServiceKnownType(typeof(PropertyDataCollection))]

    [ServiceKnownType(typeof(IPDUnitDataTables))]

    [ServiceKnownType(typeof(IPDDataItem))]

    [ServiceKnownType(typeof(IPDDataEnumeration))]

    public interface IService

    {

    [OperationContract]

    void InvokePLC(string PlcAssemblyName, string Plc, string PlcMethod, object[] Params, out object ReturnValue);

    }

     

     

    I call the method as below

     

    Code Snippet

    proxy.InvokePLC("IPD.ProcessLogic.PLC.ExpressionEngine",

    "PLCValidation",

    "EvaluateExpressionSingle",

    new object[] { _dataScenario, _propertyData, _expression, tp.FocusedDataRowView });

     

     

    I have added _dataScenario, _propertyData, _expression classes as knowntype shown in the code above. But when I invoke this method I get following exception

     

    System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/Params. The InnerException message was 'Type 'System.RuntimeType' with data contract name 'RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected.

     

    I just stuck and don't know what to do. Does any have the solution? Am I missing something?

All Replies

  • Thursday, May 08, 2008 3:04 PM
    Moderator
     
     
    I suspect this as to do with the out parameter.  Since this operation returns void anyway, why not just have it return the ReturnValue instead of using an out parameter?

     

  • Thursday, May 08, 2008 3:13 PM
     
     

    I get the same exception even if I return value rather using out param. However I get no error if I just send null as param value.

     

    But still not clear why it gives me exception if I pass param values.

  • Thursday, May 15, 2008 1:23 AM
    Moderator
     
     Answered

     

    When passing a collection as a DataContract it needs to be decorated with the CollectionDataContract attribute

    More here: http://msdn.microsoft.com/en-us/library/aa347850.aspx