Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (15 posts)

AnyCPU vs x86 running on x64

Last post 2/13/2014 11:47 PM by Bryan1821. 14 replies.
  • 8/25/2007 6:17 PM

    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

  • 8/25/2007 8:09 PM In reply to

    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.

     

  • 8/27/2007 3:50 PM In reply to

    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.

  • 8/27/2007 6:49 PM In reply to

    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.

    1. In VC# Express 2005, go to Tools -> Options.
    2. In the bottom-left corner of the Options dialog, check the box that says, "Show all settings".
    3. In the tree-view on the left hand side, select "Projects and Solutions".
    4. In the options on the right, check the box that says, "Show advanced build configuraions."
    5. Click OK.
    6. Go to Build -> Configuration Manager...
    7. In the Platform column next to your project, click the combobox and select "<New...>".
    8. In the "New platform" setting, choose "x86".
    9. Click OK.
    10. 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).

     

  • 8/27/2007 6:57 PM In reply to

    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:

    1. Start c# express - make a new Windows Game project
    2. Right click solution and select add new project
    3. Choose Windows Application
    4. Save everything...
    5. 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.

     

  • 8/27/2007 7:16 PM In reply to

    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.

     

  • 8/27/2007 7:56 PM In reply to

    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...

  • 8/27/2007 10:23 PM In reply to

    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)

  • 8/28/2007 1:13 AM In reply to

    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.

     

  • 8/28/2007 1:28 AM In reply to

    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 ;-)

  • 8/28/2007 12:11 PM In reply to

    Re: AnyCPU vs x86 running on x64

    If I understand well the problem you're getting, maybe this also helps for Vista 64-bit OS: http://amapplease.blogspot.com/2006/09/managed-directx-and-windows-xp-pro-64.html
  • 8/28/2007 1:01 PM In reply to

    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.
  • 8/28/2007 1:12 PM In reply to

    Re: AnyCPU vs x86 running on x64

    I see. In the meantime you can use the "second option".
  • 5/16/2010 8:49 PM In reply to

    Re: AnyCPU vs x86 running on x64

    Thanks , thanks , thanks , thanks , thanks , thanks , thanks , thanks , thanks MAN you are the best :-)
  • 2/13/2014 11:47 PM In reply to

    Re: AnyCPU vs x86 running on x64

    I'm working in VB 2008 express and had this problem when trying to run a database program.  I used the solution from Stephen and it work perfectly.  So if you're using VS2008 give this solution a try if you get the "'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine" message.
Page 1 of 1 (15 posts) Previous Discussion Next Discussion