4

I want to know if it is possible to configure known types the way described in this answer when we are using a Silverlight 4 client?

Only thing that seems to work is using the KnownType attribute, and we'd like to avoid that solution since the classes are in different assemblies and we don't want dependencies between them.

Here's a sample of the configuration:

<?xml version="1.0"?>
<configuration>
  <!-- *snip* -->
  <system.runtime.serialization>
    <dataContractSerializer>
      <declaredTypes>
        <add type="Foo.Dto.FooDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL">
          <knownType type="Foo.Dto.BarDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
          <knownType type="Foo.Dto.BizDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
        </add>
      </declaredTypes>
    </dataContractSerializer>
  </system.runtime.serialization>
  <!-- *snip* -->
</configuration>
Community
  • 1
  • 1
chlb
  • 213
  • 2
  • 8

1 Answers1

1

Check out the MSDN docs on the topic - basically, this is what you need:

<configuration>
   <system.runtime.serialization>
       <dataContractSerializer>
           <declaredTypes>
             <add type="MyCompany.Library.Shape, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL">
                 <knownType type="MyCompany.Library.Circle, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL"/>
             </add>
           </declaredTypes>
       </dataContractSerializer>
   </system.runtime.serialization>
</configuration> 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I might be doing something wrong, but I just cannot get the known types specified in a configuration file. Configuring them that way always results in error in the Silverlight end. – chlb Mar 08 '11 at 08:30
  • @chlb: can you **show us** your config file?? Please update your original question by editing it... thanks! – marc_s Mar 08 '11 at 14:30
  • I've edited my question to include a sample of the configuration. – chlb Mar 09 '11 at 13:03
  • 1
    We took another tackle at this issue and eventually found out that the Reference.cs file generated by Microsoft.Silverlight.ServiceReference does not include the known type configuration for some reason. I'll mark your answer as the correct one since that is how the config file should look. – chlb Apr 01 '11 at 10:34