Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. WCF over TCPIP Serialization Exception while sending dictionary in a dictionary

WCF over TCPIP Serialization Exception while sending dictionary in a dictionary

Scheduled Pinned Locked Moved WCF and WF
wcfhelpcsharpwpfcom
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naeemnimi
    wrote on last edited by
    #1

    Hi, I have created two programs to test WCF using TCPIP binding. One program is acting as a client and other is acting as a server. Server has one function which is something like /////////////////////////////////////////////////////////// public bool Func(out Dictionary > response,Dictionary > request) { return true; } /////////////////////////////////////////////////////////// The client on the other hand has following code for using this function /////////////////////////////////////////////////////////// InstanceContext ct = new InstanceContext(new Program()); //generated proxy KineticServiceClient client = new KineticServiceClient(ct); Dictionary> response = null; Dictionary> request = new Dictionary>(); List lst= new List(); lst.Add("hello"); lst.Add(23); /* Dictionary dict = new Dictionary(); dict.Add("1", "10"); dict.Add("2", "10"); dict.Add("3", "10"); lst.Add(dict); */ request.Add("test1",lst); client.Func(out response, request); //////////////////////////////////////////////////////////////////// Everything works fine until I uncomment above commented code in client program. Then I start getting following exception "There was an error while trying to serialize parameter Avanza.Kinetic.Terminal.Communication:request. The InnerException message was 'Type 'System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfKeyValueOfstringstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details." I've got no idea why it is happening. Can any body help??

    M Z 2 Replies Last reply
    0
    • N naeemnimi

      Hi, I have created two programs to test WCF using TCPIP binding. One program is acting as a client and other is acting as a server. Server has one function which is something like /////////////////////////////////////////////////////////// public bool Func(out Dictionary > response,Dictionary > request) { return true; } /////////////////////////////////////////////////////////// The client on the other hand has following code for using this function /////////////////////////////////////////////////////////// InstanceContext ct = new InstanceContext(new Program()); //generated proxy KineticServiceClient client = new KineticServiceClient(ct); Dictionary> response = null; Dictionary> request = new Dictionary>(); List lst= new List(); lst.Add("hello"); lst.Add(23); /* Dictionary dict = new Dictionary(); dict.Add("1", "10"); dict.Add("2", "10"); dict.Add("3", "10"); lst.Add(dict); */ request.Add("test1",lst); client.Func(out response, request); //////////////////////////////////////////////////////////////////// Everything works fine until I uncomment above commented code in client program. Then I start getting following exception "There was an error while trying to serialize parameter Avanza.Kinetic.Terminal.Communication:request. The InnerException message was 'Type 'System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfKeyValueOfstringstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details." I've got no idea why it is happening. Can any body help??

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Are you using the Dictionary<(Of <(TKey, TValue>)>) Class? If so, I'm not seeing that in your code posted - can you fix that?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      N 1 Reply Last reply
      0
      • M Mark Salsbery

        Are you using the Dictionary<(Of <(TKey, TValue>)>) Class? If so, I'm not seeing that in your code posted - can you fix that?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        N Offline
        N Offline
        naeemnimi
        wrote on last edited by
        #3

        Sorry please find the correct client code which gives exception /////////////////////////////////////////////////////////// InstanceContext ct = new InstanceContext(new Program()); //generated proxy KineticServiceClient client = new KineticServiceClient(ct); Dictionary response = null; Dictionary> request = new Dictionary>(); List lst= new List(); lst.Add("hello"); lst.Add(23); /* Dictionary dict = new Dictionary(string,string>); dict.Add("1", "10"); dict.Add("2", "10"); dict.Add("3", "10"); lst.Add(dict); */ request.Add("test1",lst); client.Func(out response, request);

        1 Reply Last reply
        0
        • N naeemnimi

          Hi, I have created two programs to test WCF using TCPIP binding. One program is acting as a client and other is acting as a server. Server has one function which is something like /////////////////////////////////////////////////////////// public bool Func(out Dictionary > response,Dictionary > request) { return true; } /////////////////////////////////////////////////////////// The client on the other hand has following code for using this function /////////////////////////////////////////////////////////// InstanceContext ct = new InstanceContext(new Program()); //generated proxy KineticServiceClient client = new KineticServiceClient(ct); Dictionary> response = null; Dictionary> request = new Dictionary>(); List lst= new List(); lst.Add("hello"); lst.Add(23); /* Dictionary dict = new Dictionary(); dict.Add("1", "10"); dict.Add("2", "10"); dict.Add("3", "10"); lst.Add(dict); */ request.Add("test1",lst); client.Func(out response, request); //////////////////////////////////////////////////////////////////// Everything works fine until I uncomment above commented code in client program. Then I start getting following exception "There was an error while trying to serialize parameter Avanza.Kinetic.Terminal.Communication:request. The InnerException message was 'Type 'System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfKeyValueOfstringstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details." I've got no idea why it is happening. Can any body help??

          Z Offline
          Z Offline
          ZaoWuYa
          wrote on last edited by
          #4

          Hi, It looks like you've run across exactly the same problem (although the objects are different) that I encountered earlier this week. Hopefully I can help you out, or point you in the right direction at least. As the error shows, the problem happens when DataContractSerializer tries to serialize the Dictionary object. It does also point you in the right direction as to how to fix this. There are two ways (that I know of to fix this issue). The one is to apply the KnownTypeAttribute to the DataContract with the type you want the DataContractSerializer to know about, in normally it would look something like this: [KnownType(typeof(MyType))]. Sadly, in your case as you are working with generic types, you will probably have a bit more work than that by the looks of the documentation (See the MSDN page for the KnownTypeAttribute). The other way around it (the method I used), is to put the known type in your application config file. Basically what you will do is something like this (haven't tried it with your generic types, but this should point you in the right direction):

          <system.runtime.serialization>
          <dataContractSerializer>
          <declaredTypes>
          <add type = "Reporting.Contracts.Data.ReportData, Reporting.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=312e149fdc68a08f">
          <knownType type = "Reporting.Contracts.Data.NewTest,Reporting.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=312e149fdc68a08f"/>
          </add>
          </declaredTypes>
          </dataContractSerializer>
          </system.runtime.serialization>

          Your dictionary would go in the line <knownType type = "Reporting.Contracts.Data.NewTest,Reporting.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=312e149fdc68a08f"/> I think (not 100% sure on this though), that your List'1 would go on the line that looks like: <add type = "Reporting.Contracts.Data.ReportData, Reporting.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=312e149fdc68a08f">

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups