-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
AnyCPU vs x86 running on x64
|
I just tried to run a project I've not used for a few weeks on my nice new x64 box and I was quite surprised to see it throwing BadImageFormat exceptions.
After some research I have come to the conclusion that the problem is that my application has 2 entry points. The normal one is a x86 GSE project. The 'editor' app is a normal WinForms app which has a setting of "Any CPU". When I set the normal entry point everything works fine. When I set the winforms app i get a BadImageFormat exception.
After a little research I found this http://blogs.msdn.com/joshwil/archive/2005/04/08/406567.aspx. Basically "any CPU" on an x64 can't call x86 dlls.
So is there a way to switch the ANY CPU project to be x86... I'm sure there is and I'm sure its staring me right in the face but I just can't seem to work out how to do it. So its time to help 'the old guy' who can't see the right option in VS
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
-
- (7)
-
premium membership
MVP
-
Posts
1,205
|
Re: AnyCPU vs x86 running on x64
|
You can just go into the project properties. In the Build tab, there is a Platform target option.
Make sure you apply this to all configurations.
Microsoft DirectX/XNA MVP
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
Unfortunatly that option isn't availalbe in C# express. After some hunting around I realised it was in full Visual Studio and so I loaded up the winforms project in VS Pro, swtiched it to x86 and then reopened in in C# express.
Seems to have fixed the problem for now.
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
-
- (1862)
-
premium membership
Team XNA
-
Posts
1,263
|
Re: AnyCPU vs x86 running on x64
|
In VC# Express, this property is missing, but you can still create an x86 configuration if you know where to look.
It looks like a long list of steps, but once you know where these things are it's a lot easier. Anyone who only has VC# Express will probably find this useful. Once you know about Configuration Manager, it'll be much more intuitive the next time.
- In VC# Express 2005, go to Tools -> Options.
- In the bottom-left corner of the Options dialog, check the box that says, "Show all settings".
- In the tree-view on the left hand side, select "Projects and Solutions".
- In the options on the right, check the box that says, "Show advanced build configuraions."
- Click OK.
- Go to Build -> Configuration Manager...
- In the Platform column next to your project, click the combobox and select "<New...>".
- In the "New platform" setting, choose "x86".
- Click OK.
- Click Close.
There, now you have an x86 configuration! Easy as pie! :-)
I also recommend using Configuration Manager to delete the Any CPU platform. You really don't want that if you ever have depedencies on 32-bit native DLLs (even indirect dependencies).
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
Sadly that doesn't work - (at least not in my scenario). Sorry I didn't list all the things I tried before I found the way that works.
Quick Repro steps:
- Start c# express - make a new Windows Game project
- Right click solution and select add new project
- Choose Windows Application
- Save everything...
- Follow your instructions above for the Windows application
Expected: Windows application becomes x86
Actual: Error message at step #9 saying "This platform could not be created because a solution platform of the same name already exists.".
So its telling me x86 already exists but its not in the drop down box to select... very odd.
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
-
- (1862)
-
premium membership
Team XNA
-
Posts
1,263
|
Re: AnyCPU vs x86 running on x64
|
This is the confusing part about configurations -- there are two kinds: project configurations and solution configurations.
A project configuration is a group of settings that your project uses when it builds. This lets you specify things like defines and platform target and output path.
A solution configuration is a group of settings that determines which project configurations will build when the solution is built. For example, you could have a solution configuration that builds a Release|x86 processor project and a Release|Xbox 360 game project in a solution configuration called Release|Xbox 360.
In the standard toolbar, you'll find the Solution Configurations combo controls. This allows you to quickly switch between solution configurations, which determines which project configurations become active.
So the error message you got is saying the solution configuration already exists. That just means you need step 8.5...
8.5) Uncheck the box that says, "Create new solution platforms".
In your case, you have a solution configuration for x86 already because of another project in that solution. Skip step 8.5 for new solutions.
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
Stephen Styrchak:
The Zman is cool:
So its time to help 'the old guy' who can't see the right option in VS
So the error message you got is saying the solution configuration already exists. That just means you need step 8.5...
8.5) Uncheck the box that says, "Create new solution platforms".
Aha, thanks that was indeed the magic option that I was not fully understanding what it did...
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
Any idea if the 360 JIT looks at the platform? I have a bunch of helper assemblies which are not dependant on any XNA or .Net CF specific stuff. I was keeping things simple by not having dual win/360 projects for these assemblies. It seemed to work fine before by having them as AnyCpu
But to get rid of AnyCPU I had to switch those projects over to x86. In config manager I checked the box for them to be built even on the 360 config.
(Right now my 360 build isn't working so I can't try it but I though I would ask in case you knew)
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
-
- (1862)
-
premium membership
Team XNA
-
Posts
1,263
|
Re: AnyCPU vs x86 running on x64
|
The ZMan:
Any idea if the 360 JIT looks at the platform?
It does not. The CLR on Xbox 360 will always JIT compile to PowerPC. :-)
The ZMan:
I have a bunch of helper assemblies which are not dependant on any XNA or .Net CF specific stuff. I was keeping things simple by not having dual win/360 projects for these assemblies. It seemed to work fine before by having them as AnyCpu
But to get rid of AnyCPU I had to switch those projects over to x86. In config manager I checked the box for them to be built even on the 360 config.
(Right now my 360 build isn't working so I can't try it but I though I would ask in case you knew)
I recommend that you create projects specifically for the target platform. The problem isn't the target platform, it is with the referenced assemblies. When you reference, say, "System" in an Xbox 360 game project, the compiler references a different file than it does when you reference "System" in a Windows game project. You can verify this by selecting the assembly reference in Solution Explorer and examining its Path property in the Properties Window.
If you compare an Xbox 360 project against a Windows project, you'll notice that the assembly versions are different for the BCL assemblies. System is version 3.0.0.0 on Xbox 360, but only version 2.0.0.0 on Windows. Another difference that you don't see is that the assemblies are signed with different keys.
Since the version and public key are part of the assembly's strong name, it means that on one platform, you are guaranteed to not have the right one available. There are some shenanigans going on in the CLR that allows substitutions to occur on some assemblies, but it's not guaranteed to stay that way forever (in future versions -- it won't change in this one).
You should avoid creating a bad habit of relying on this behavior, because it will be hard to figure out what went wrong if it fails for some reason in the future. In this version, for example, you could get a MissingMethodException if you accidentally call a method that isn't in the BCL on the other platform.
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
The ZMan:
(Right now my 360 build isn't working so I can't try it but I though I would ask in case you knew)
You should avoid creating a bad habit of relying on this behavior, because it will be hard to figure out what went wrong if it fails for some reason in the future. In this version, for example, you could get a MissingMethodException if you accidentally call a method that isn't in the BCL on the other platform.
You will love this... I just fixed up my build to run on the 360 and I will give you one guess which error I got when it deployed and ran.... you win todays 'I guessed the bug in advance' award. Please go claim it from Shawns desk where its been for many many months ;-)
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
|
|
Re: AnyCPU vs x86 running on x64
|
|
|
-
-
- (24094)
-
premium membership
MVP
-
Posts
13,670
|
Re: AnyCPU vs x86 running on x64
|
Yes that was the problem, and I found similar references but I've been burned editing project files direct in the past so I prefer to find the 'official' way if there is one before resorting to that.
*** Should The Zman write a book? #1, #2 ***NOTE: Due to current employment, The ZMan is unable to review/playtest or deal with threads in those forums. Normal service will return in a few weeks. Follow The Zman on twitter, Email me Please read the forum FAQs - Bug/Feature reporting
|
|
-
|
|
Re: AnyCPU vs x86 running on x64
|
|
|
-
|
|
Re: AnyCPU vs x86 running on x64
|
Thanks , thanks , thanks , thanks , thanks , thanks , thanks , thanks , thanks MAN you are the best :-)
|
|
|