WinForms Designer 在托管嵌套 WPF UserControls 时失败

发布于 2024-11-04 17:16:40 字数 1161 浏览 1 评论 0 原文

我正在使用 VS2008 SP1 和 WPFToolKit v3.5.50211.1。

我已将 WPF UserControls 嵌套在类库项目中,如下所示:

  • MainWpfUserControl
  • 包含 NestedUserControl 的实例
  • ,其中包含来自 WPF 的 DataGrid 的实例工具包。

同一个类库项目包含一个 WinForms UserControl 和一个托管 MainWpfUserControl 的 ElementHost。

在设计器中打开 WinForms UserControl 时,我遇到了奇怪的错误。经过一番挖掘(捕获并记录 NestedUserControl 构造函数中抛出的异常),似乎抛出了一个异常,如下所示:

[A]Microsoft.Windows.Controls.DataGrid 无法转换为 [B]Microsoft.Windows.Controls.DataGrid。类型 A 源自位置“C:\Program Files\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll”的上下文“LoadFrom”中的“WPFToolkit,Version=3.5.40128.1,Culture=neutral,PublicKeyToken=31bf3856ad364e35”。类型 B 源自位置“C:\Documents and Settings\...\Local Settings\Application Data\Microsoft\VisualStudio”上下文“LoadNeither”中的“WPFToolkit,Version=3.5.40128.1,Culture=neutral,PublicKeyToken=31bf3856ad364e35” \9.0\ProjectAssemblies\zfh65-u101\WPFToolkit.dll'

有没有人经历过类似的事情?

更新

我似乎已经通过将 WPFToolkit.dll 放入 GAC 中成功解决了该问题。但由于其他原因这是不可取的(例如 CopyLocal 现在默认为 false)。所以看来问题与加载上下文有关。有什么办法可以控制这个吗?

I'm using VS2008 SP1 with the WPFToolKit v3.5.50211.1.

I have nested WPF UserControls in a Class Library project as follows:

  • MainWpfUserControl
  • Contains an instance of NestedUserControl
  • Which contains an instance of a DataGrid from the WPF Toolkit.

The same Class Library project contains a WinForms UserControl with an ElementHost that hosts MainWpfUserControl.

I've been getting strange errors when opening the WinForms UserControl in the designer. After a bit of digging around (catching and logging the exception thrown in the NestedUserControl constructor), it seems that an exception is thrown as follows:

[A]Microsoft.Windows.Controls.DataGrid cannot be cast to [B]Microsoft.Windows.Controls.DataGrid. Type A originates from 'WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Program Files\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll'. Type B originates from 'WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadNeither' at location 'C:\Documents and Settings\...\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies\zfh65-u101\WPFToolkit.dll'

Has anyone experienced anything similar?

UPDATE

I seem to have successfully worked around the problem by putting WPFToolkit.dll in the GAC. But that's undesirable for other reasons (e.g. CopyLocal now defaults to false). So it seems the problem is related to Load Context. Is there any way to control this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2024-11-11 17:16:40

经过一番研究,我遇到的问题似乎是由 VS 设计器加载错误版本的程序集引起的。看起来与此处描述的问题类似:

http://blogs.telerik.com/blogs/posts/08-12-23/visual_studio_ldquo_error_creating_control_rdquo.aspx

http://connect.microsoft.com/VisualStudio/feedback/details/361826/error-creating-control-text-could-not-be-set-on-property-with-custom-asp- net-server-controls-in-vs-2008-sp1

我可以通过执行以下操作来解决该问题:

  • 关闭 Visual Studio 2008

  • 清除程序集下载缓存 (gacutil /cdl)

  • 删除 VS2008 ProjectAssemblies 文件夹:

    %USERPROFILE%\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies

  • 重新启动 Visual Studio

After a bit of research, the problems I'm having seem to be call caused by the VS designer loading the wrong version of an assembly. Looks similar to the issues described here:

http://blogs.telerik.com/blogs/posts/08-12-23/visual_studio_ldquo_error_creating_control_rdquo.aspx

http://connect.microsoft.com/VisualStudio/feedback/details/361826/error-creating-control-text-could-not-be-set-on-property-with-custom-asp-net-server-controls-in-vs-2008-sp1

I can work around the problem by doing the following:

  • Close Visual Studio 2008

  • Clear the Assembly download cache (gacutil /cdl)

  • Delete the VS2008 ProjectAssemblies folder:

    %USERPROFILE%\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies

  • Restart Visual Studio

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文