I am writing a plugin for an application (Autodesk Revit Architecture 2011, if you need to know).
During debugging, I would like to recompile my plugin and reload it in the host. My particular host even provides an add-on manager that simplifies this process using Assembly.Load . For Windows.Forms plugins, this works like a charm.
When I use WPF, it breaks. At first, I got an error in these lines (I added some formatting to make it easier for you to read:
System.Windows.Markup.XamlParseException: [A]MyApp.Controls.MyControl cannot be cast to [B]MyApp.Controls.MyControl. Type A originates from 'MyApp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location '%PATHA%'. Type B originates from 'MyApp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location '%PATHB'. Error at object 'MyApp.Controls.MyControl' in markup file 'MyApp;component/controls/mydialog.xaml'.
I also took the liberty of renaming the controls, namespaces, and ways to protect the innocent and me, the culprit.
I assume this is because the XAML parser stores the cache memory of already loaded types.
My first step was to change the assembly versions by setting AssemblyInfo.cs/[assembly: AssemblyVersion("2.0.*") . It just pushes the error further:
System.Windows.Markup.XamlParseException: Unable to cast object of type 'MyApp.Controls.MyControl' to type 'MyApp.Controls.MyControl'. Error at object 'MyApp.Controls.MyControl' in markup file 'MyApp;component/controls/mydialog.xaml'. ---> System.InvalidCastException: Unable to cast object of type 'MyApp.Controls.MyControl' to type 'MyApp.Controls.MyControl'.
source share