Geeks With Blogs

News Bob Taco Industries is an ISV focused on game and app development for Microsoft platforms headed up by Michael B. McLaughlin. Mike is a Microsoft Visual C++ MVP (previously an XNA/DirectX MVP from 2011-2013), a developer, a writer, a consultant, and a retired lawyer. If you're a developer who is just getting started, consider checking out the BTI website's section for developers for links to code samples and other helpful sites.
Bob Taco Industries Blogging Division

One of my hobbies seems to be creating map editors for XNA games. With the new XNA 4.0 Beta(yes, it’s called Windows Phone Developer Tools – don’t worry, it’s the full XNA and builds Windows and Xbox 360 games too, though the current beta doesn’t deploy to the Xbox 360 yet so stick with XNA 3.1 for Xbox games for now)… anyway, with the new XNA 4.0, I thought I’d take the stock WinForms 2 sample (the one that includes building content on the fly using MSBuild) and build it to see how much conversion work it would take. I was expecting that it would take a lot, with all of the changes that scrapped the old mish-mash of RenderState and individual settings on the GraphicsDevice etc., but surprisingly it just took one and I thought I’d share it with anyone who might be interested. Download the sample, open it up using Visual Studio 2010 Express for Windows Phone, and go through the normal conversion process. At this point, it will build with a couple of warning messages but no errors. However, try to run it and you will get:

FileLoadException was unhandled

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

When the converter migrates the project, it switches it to the .NET 4.0 Framework. However, the XNA Framework is built against .NET 2.0 (presumably since that’s the version of the Compact Framework built for the 360 and the time and money it’d take to update it to 3.5 or 4.0 wouldn’t be worth whatever small benefits might accrue – it is the Compact Framework after all). I tried a complicated solution a few months back after the April CTP was released, but this time I was clever and realized the easy fix. And here it is.

In the Solution Explorer (accessible from the View menu if you closed it for some reason), right click on the project (not the solution) and choose “Properties”. In the window/tab that opens up, you should be in the “Application” tab. In there you will see “Target Framework:” and it will be set to “.NET Framework 4”. Use the drop-down menu and change this to “.NET Framework 2.0”. You’ll get a confirmation message box, click “Yes”. Then simply build the solution and run it.

If you don’t have the 2.0 version of the .NET Framework installed on your computer, you can get it here. (Presumably it’s installed with XNA 4, but I ended up installing the SDK before I realized that since I was trying to manually change the references at first until I realized the simpler, better way of fixing it). Anyway, this is likely a bug and should hopefully disappear in the next beta or with the RTM at the latest, but for now, this should do it. Good luck!

Posted on Thursday, July 29, 2010 2:31 AM xna | Back to top

Comments on this post: WinForms Content Loading Sample with XNA 4.0 Beta

# re: WinForms Content Loading Sample with XNA 4.0 Beta
Requesting Gravatar...
After converting the project you'll need to remove the references to the 2.0 runtime DLLs and use the 4.0 DLLs instead. There are 4.0 versions of the assemblies for sure.
Left by Zachary Snow on Aug 17, 2010 12:49 PM

# re: WinForms Content Loading Sample with XNA 4.0 Beta
Requesting Gravatar...
Most of the conversion is the same (along with changing the dll for 3.1 to 4.0 but the you need to set the handle in the present parameters because during instatiation of the GraphicsDevice you will not find a the IntPtr handle in the constructor's parameters and dont forget to set the pp to IsFullScreen to false.
Left by Robert on Aug 19, 2010 11:12 PM

# re: WinForms Content Loading Sample with XNA 4.0 Beta
Requesting Gravatar...
Actually, you can create a display window for winform using XNA 4 without having to go to legacy2 in the app.config. You have to read on the new device contructor which I dont really like but oh well and read on the new PresentParameters Properties, most are the same but some are not and some are depreciate which you will not find anymore.

The only issue I have is with the Microsoft.Xna.Framework.Game base class for users with lower end graphics cards because by default if you use the ContentManager for your graphics, the GraphicDisplay will go to using HiDef and since the GraphicsDevice property is only a getter there is no way to override this unless you build outside of Game.
Left by Robert on Aug 23, 2010 4:50 PM

Comments have been closed on this topic.
Copyright © Michael B. McLaughlin | Powered by: