0

I am trying to send an int array over a WCF connection using a method call that takes an object. But i am receiving this error

'System.ServiceModel.CommunicationException' in mscorlib.dll ("There was an error while trying to serialize parameter http://tempuri.org/:Data. The InnerException message was 'Type 'System.Object[]' with data contract name 'ArrayOfanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types.

Here is my interface

<ServiceContract()>
Public Interface myServiceContract
    <OperationContract(IsOneWay:=True)>
    Sub DoStuff(ByVal str As String, ByVal Data As Object)
End Interface

Here is how I'm using the interface

Dim data(2) As Object
data(0) = 20
data(1) = 22
data(2) = 255
remoteContext.DoStuff("Hello", data) ' this line throws the exception

How do i get the data array to be sent over the wcf connection without it throwing an exception?

This is com exposed so changing the parameter type would cause me a lot of trouble.

Newguy75
  • 3
  • 4
  • Use an int[] array instead of object – live2 Feb 20 '19 at 19:31
  • unfortunately I am using a com exposed object and changing that parameter type would break the com comparability. It should be possible to send anything over an object variable since an object array is no different than an object. – Newguy75 Feb 20 '19 at 19:36
  • 1
    The nature of WCF is that it has to know what it's serializing and deserializing. Working with untyped data goes completely against the grain. – Scott Hannen Feb 20 '19 at 20:24
  • That explains why Im having such a hard time. I guess ill have to bite the bullet and make some breaking changes. – Newguy75 Feb 20 '19 at 20:37

0 Answers0