Setting platform target to x86 on my x64 laptop prevent some WPF types to load properly

前端 未结 2 1216
北荒
北荒 2021-01-06 23:19

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

If I build and run a WPF application with pla

相关标签:
2条回答
  • 2021-01-06 23:47

    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.

    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.

    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.

    0 讨论(0)
  • 2021-01-06 23:56

    I have this configuration as well and have experienced no issues with building an x86 application that uses a Grid.

    I would uninstall the version of .NET Framework you are using (looks like .NET 4.0) and reinstall it. To be thorough, you might also uninstall Visual Studio 2010 and reinstall it (although that is probably overkill).

    The problem has to exist on only the machine you are working on ... otherwise there would be mobs and pitchforks and such ... headed towards Redmond, WA. :-) You might try creating a sample project on another machine ... just for your sanity. :-)

    Update

    I just wanted to add that System.Windows.Controls.Grid lives in the PresentationFramework assembly. It might be interesting to take a look at where this file is stored on your machine ... to see if you notice anything. The solution is still probably reinstalling ... but hey, more information is always better.

    For .NET 4.0, the PresentationFramework assembly lives at: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35

    For .NET 3.0/3.5, the PresentationFramework assembly lives at: C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0

    0 讨论(0)
提交回复
热议问题