I'm loading a plugin assembly using Activator.CreateInstanceFrom, and
inside this assembly is a settings class which gets serialized to XML.
The general code flow is as follows:
ObjectHandle pluginHandle = Activator.CreateInstanceFrom(assemblyName,
type);
object plugin = pluginHandle.Unwrap();
....
// Settings is from the plugin Assembly loaded by the Activator
XmlSerializer x = new XmlSerializer(typeof(Settings));
x.Serialize(settingsFile, _settings);
// blows up here with this exception:
System.InvalidOperationException: There was an error generating the
XML document. ---System.InvalidCastException: Unable to cast object
of type '*.Settings' to type '*.Settings'.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterSettings.Write3_Settings(Object
o)
Which is confusing considering the types are identical. However, when
I add the following XML to App.Config, the error goes away:
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>
What am I missing w.r.t. Activator.CreateInstanceFrom and
XmlSerializer?
Thanks.