WCF proxy exception - "The type cannot be added to the list of known types"

I'm having problems creating a WCF proxy for utility code, as in this example:

// data classes
[KnownType(typeof(ClassA))]
[KnownType(typeof(ClassB))]
public abstract class BaseClass : Dictionary<string, ITest>
{
}

public class ClassA : BaseClass
{
}

public class ClassB : BaseClass
{
}


public interface ITest
{
}

// service
[ServiceContract]
public interface IService1
{
    [OperationContract]
    BaseClass Method();
}

public class Service1 : IService1
{
    public BaseClass Method()
    {
        ...
    }
}

Whenever I try to create a WCF proxy using "Add Service Link" in VS, it fails and the trace log says

"WcfProxyTest.ClassA" , "WcfProxyTest.ClassB" " http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfKeyValueOfstringanyType ' . - , List <Test> Test [], . .

, , - ( ). , , , , , : S

? !

+3
2

, KnownTypes, . 300 . , ...

+1

:

[KnownType(typeof(Dictionary<string, ITest>))]
0

Source: https://habr.com/ru/post/1761084/


All Articles