4

我正在为应用程序编写插件(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'.
4

2 回答 2

3

在我看来,您最好在单独的AppDomain. AppDomain编译完成后,您可以将其丢弃。

AppDomain您的 main和 compilation之间的确切接口AppDomain并不是我可以评论的,因为您没有在问题中提供详细信息。

于 2011-02-16T19:08:22.380 回答
2

不知道如何清理缓存,但作为解决方法,我会尝试使用 XamlReader.Load 直接加载 XAML 并查看它是否有效。检查http://msdn.microsoft.com/en-us/library/ms590388.aspx#Y309

于 2011-02-11T20:12:28.960 回答