我正在为应用程序编写插件(Autodesk Revit Architecture 2011,如果您需要知道的话)。
在调试期间,我想重新编译我的插件并将其重新加载到主机中。我的特定主机甚至提供了一个插件管理器来简化这个过程,使用Assembly.Load
. 对于 Windows.Forms 插件,这就像一个魅力。
当我使用 WPF 时,这会发生故障。起初,我在这些方面遇到了错误(我添加了一些格式以使您更容易阅读:
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'.
我还冒昧地重命名了控件、命名空间和路径,以保护无辜者和罪魁祸首我。
我认为这是因为 XAML 解析器保留了它已经加载的类型的缓存。
我的第一步是更改程序集版本,通过设置AssemblyInfo.cs/[assembly: AssemblyVersion("2.0.*")
. 这只是将错误更进一步:
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'.