Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF issues with KnownType for Dictionary
    text
    copied!<p>I have a service that implements the following DataMember:</p> <pre><code>[DataMember] public Dictionary&lt;string, List&lt;IOptionQueryResult&gt;&gt; QueryResultItems { get; set; } </code></pre> <p>I have the class "OptionQuerySingleResult" which inherits from IOptionQueryResult. Now, I understand that I need to make the OptionQueryResult type "known" to the Service and thus tried to add the KnownType in various ways:</p> <pre><code>[KnownType(typeof(Dictionary&lt;string, OptionQuerySingleResult[]&gt;))] [KnownType(typeof(Dictionary&lt;string, List&lt;OptionQuerySingleResult&gt;&gt;))] [KnownType(typeof(OptionQuerySingleResult)] </code></pre> <p>However, none of those approaches worked and on the client side I'm either getting that deserialization failed or the server simply aborted the request, causing a connection aborted error.</p> <p>Does anyone have an idea on what's the proper way to get this to work? I'd like to add that if I change the QueryResultItems definition to use the concrete type, instead of the interface, everything works just fine.</p> <p>Thanks,</p> <p>Tom</p> <p>Edit: The exception that I am getting is:</p> <p>Error in line 1 position 524. Element '<a href="http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType" rel="nofollow noreferrer">http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType</a>' contains data from a type that maps to the name ':OptionQuerySingleResult'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'OptionQuerySingleResult' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.</p> <p>However, when I look at the client proxy that svcutil generates, "OptionQuerySingleResult" is definitely defined in it:</p> <pre><code>[System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] [System.Runtime.Serialization.DataContractAttribute(Name="OptionQuerySingleResult", Namespace="")] [System.SerializableAttribute()] public partial class OptionQuerySingleResult : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload