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

2

2

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 platform target set as x86, I got a MissingMethodException when trying to create a Grid:

var g = new Grid();

However, creating a StackPanel works fine:

var s = new StackPanel();

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 ?

Update:

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.

Hemialgia answered 12/10, 2010 at 6:54 Comment(2)
Document your question better. Post the exact exception message and its StackTrace. Post the trace you get out of fuslogvw.exeSpermaceti
I agree, it would be helpful to see the exact exception message ...Expressive
E
4

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

Expressive answered 15/10, 2010 at 13:30 Comment(0)
N
4

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.

Newspaperman answered 20/10, 2010 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.