2

I have class B that extends A, and because it is located in another assembly I cannot simply add [KnownType(typeof(B))] to A to get it to serialize because this requires a circular dependency. I tried doing this in the config but it doesn't work for some reason.

Now I am trying the method described here

Generally accepted way to avoid KnownType attribute for every derived class

(I load B's assembly instead of GetExecutingAssembly) When I try to update service references I get The URI prefix is not recognized. Metadata contains a reference that cannot be resolved..." What might be the problem here?

j doe
  • 51
  • 5

1 Answers1

0

This might help you:

Assume that ClassA is in assembly A and ClassB in assembly B, and A is referenced in B. Consider the following:

[KnownType("GetDerivedTypes")]
[DataContract]
public abstract class ClassA         \\This is referenced in B
{
    static Type[] GetDerivedTypes()
    { 
        return DerivedTypes.ToArray();  
    }
    public static List<Type> DerivedTypes = new List<Type>();
}

You cannot add typeof(ClassB) in the preceding. However,

[DataContract]
public class ClassB : ClassA
{
    static ClassB()
    {
        ClassA.DerivedTypes.Add(typeof(ClassB));
    }

    public ClassB()
    {
    }
}
rmojab63
  • 3,513
  • 1
  • 15
  • 28