在我的 x64 笔记本电脑上将平台目标设置为 x86 会阻止某些 WPF 类型正确加载 [英] Setting platform target to x86 on my x64 laptop prevent some WPF types to load properly

查看:50
本文介绍了在我的 x64 笔记本电脑上将平台目标设置为 x86 会阻止某些 WPF 类型正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台运行 Windows 7 64 位的 x64 机器.从本周开始,我的情况似乎很奇怪.

I have a x64 machine running Windows 7 64 bits. It seems I have a very weird situation since the beginning of the week.

如果我构建并运行一个平台目标设置为 x86 的 WPF 应用程序,我在尝试创建网格时会遇到 MissingMethodException:

If I build and run a WPF application with platform target set as x86, I got a MissingMethodException when trying to create a Grid:

var g = new Grid();

但是,创建 StackPanel 工作正常:

However, creating a StackPanel works fine:

var s = new StackPanel();

如果我将平台目标切换到 x64 或 AnyCpu,两个代码都可以正常工作.我在想框架中有一个损坏的程序集,但它看起来非常奇怪......知道吗?

If I switch the platform target to x64 or AnyCpu, both code works fine. I was thinking about a corrupted assembly in the framework but it looks definitively strange... Any idea ?

更新:

我一直与 Microsoft 内部 WPF 团队的人员保持联系.但是,他们没有时间查看我的机器以了解出了什么问题.与此同时,我不得不重新安装我的机器才能继续正常工作.谢谢大家的帮助.我认为问题与 WOW64 功能有关,但很难更准确.如果我找到更多信息,我会更新这个问题.

I've been in contact with people within the WPF team inside Microsoft. However, they didn't had time to look at my machine to understand what was wrong. In the meantime, I had to reinstall my machine in order to keep working properly. Thank you all for your help. I think the problem was related to the WOW64 functionality, but it's hard to be more precise. I'll update this question if I found more info.

推荐答案

将平台目标设置为 x86 将导致您的应用程序在非托管程序集上调用 x86 版本并在 WOW64 模式下运行.请参阅这篇关于平台目标的文章WOW64 上的此 msdn 页面.如果在 Reflector 中跟踪静态 Grid 构造函数,它看起来像一些线程初始化代码调用可能导致问题的外部非托管函数RuntimeHelpers.PrepareConstrainedRegions()"(StackPanel 不调用此代码).这背后有一些猜测,但您可以尝试运行 Windows Update 以确保您拥有与您的同事相同的更新,并确保您也拥有所有 VS/.NET 更新.

Setting the platform target to x86 is going to cause your application to call x86 versions on unmanaged assemblies and run in WOW64 mode. See this article on platform target and this msdn page on WOW64. If you trace the static Grid constructor in Reflector, it looks like some thread initialization code calls an externed unmanaged function "RuntimeHelpers.PrepareConstrainedRegions()" which could be causing the problem (the StackPanel doesn't call this code). There's a bit of speculation behind this, but you might try running Windows Update to make sure you have the same updates as your coworker, and make sure you have all the VS/.NET updates out there as well.

最终,除非您从代码中调用某些仅可作为 x86 程序集使用的第三方非托管 dll,否则您应该将平台目标保留为 Any CPU,以便它可以在 x86 和 x64 平台上本地运行.

Ultimately, unless you're calling some 3rd party unmanaged dll's from your code that are only available as x86 assemblies, you should probably leave the platform target as Any CPU so it'll run native on x86 and x64 platforms.

最后,如果在运行 windows update 后您仍然看到问题,如果可能,也更新您同事的 PC,看看问题是否出现.如果是,则 WOW64 层中可能存在错误,最好向 Microsoft 提交错误报告.

Lastly, if after running windows update you're still seeing the problem, if possible, update your coworker's PC as well and see if the problem crops up. If it does, there could be a bug in the WOW64 layer, and it'd be good to file a bug report with Microsoft.

这篇关于在我的 x64 笔记本电脑上将平台目标设置为 x86 会阻止某些 WPF 类型正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆