views:

154

answers:

3

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.

+1  A: 

If you provide me the project or a snippet that you believe is the issue, I will recreate it on my Win 7 x64 machine and test it on my machine and my Win 7x86.

I would be interested to see what is causing this as well as I have the same config as you :)

halfevil
Actually the application is empty, just a StackPanel or a WrapPanel. And it works fine on the machine of a coworker who has the sameconfiguration...
Jalfp
+4  A: 

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

cplotts
+3  A: 

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.

Mark Synowiec