Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Get rid of XmlInclude when using XmlSerializer

0.00/5 (No votes)
17 Nov 2011 1  
The above solution made me grin as it helped me solved my serialization puzzle. However, if you have an extensible format with components spread over multiple assemblies, this solution may not pick up all the types.I brute force it as follows:List knownTypes = new...

The above solution made me grin as it helped me solved my serialization puzzle. However, if you have an extensible format with components spread over multiple assemblies, this solution may not pick up all the types.


I brute force it as follows:


C#
List<type> knownTypes = new List<type>();

foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
    knownTypes.AddRange(Assembly.GetExecutingAssembly().GetTypes().Where(
    t => typeof(XMLBinaryPackageInfo).IsAssignableFrom(t)));
}

My rationale is that this code is unlikely to be called often enough to worry about enumerating such a potentially vast number of types. I don't cache this stuff but you can keep track of assembly loading / unloading if you must. Mileage may vary!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here