Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: C# SFML Visual Studio - Error on Build  (Read 10150 times)

0 Members and 1 Guest are viewing this topic.

random_canadian

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
C# SFML Visual Studio - Error on Build
« on: June 03, 2013, 03:20:07 am »
Following the steps given on this thread (http://en.sfml-dev.org/forums/index.php?topic=7674.0), I managed to setup SFML.Net 2.0 with Visual Studio C# 2012. However, I get the following error whenever I actually try to build something that references the SFML library...

Quote
An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'sfmlnet-graphics-2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

According to this page (http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx), the file image of the sfmlnet-graphics-2 DLL is "invalid."

Quote
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.

Any ideas about what I may have done wrong?
Thanks!

EDIT: After some more research it appears this is a problem with discrepancies between x64 or x86 builds (http://en.sfml-dev.org/forums/index.php?topic=9917.0). If I change the CPU settings to "prefer x64" (I am using 64-bit SFML), then the build succeeds. So my question is what happens if my user wants to run the game on a x86 system? Do I need to include DLLs of both x64 and x86 versions of SFML? How do I do this?

EDIT #2: Here's yet another thread about this issue (http://en.sfml-dev.org/forums/index.php?topic=2405.0) but, my question remains. What is the permanent solution?
« Last Edit: June 03, 2013, 03:49:28 am by random_canadian »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C# SFML Visual Studio - Error on Build
« Reply #1 on: June 03, 2013, 08:07:50 am »
You must use the x86 DLLs for the x86 build of your application, and the x64 DLLs for the x64 build of your application. Simple.
Laurent Gomila - SFML developer

random_canadian

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: C# SFML Visual Studio - Error on Build
« Reply #2 on: June 03, 2013, 07:50:56 pm »
Fair enough  :)
Thanks Laurent.

chilliboy999

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: C# SFML Visual Studio - Error on Build
« Reply #3 on: June 05, 2013, 10:48:52 am »
Hey, I had the same problems as random_canadian. Then I tried to run a 32Bit and 64Bit sfml project,
but I always get the same Exception:
"BadImageFormatException"
"HRESULT: 0x8007000B"

Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Graphics;

namespace SFML.Net_Test
{
    class Program
    {
        static void Main()
        {
            RenderWindow window = new RenderWindow(new Window.VideoMode(200,200), "test");
            Window.Window win = new Window.Window(new Window.VideoMode(200, 200), "test");
            CircleShape cs = new CircleShape(100.0f);
            cs.FillColor = Color.Green;

            while (win.IsOpen())
            {
               
            }
        }
    }
}
 

Syndog

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: C# SFML Visual Studio - Error on Build
« Reply #4 on: June 08, 2013, 05:09:54 pm »
Phew!  I'm really glad I stumbled across this post.  Same exact problem on my end, and same exact solution.

Thanks so much!
Your Kung Fu is no match for my Feng Shui!

First

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • Email
Re: C# SFML Visual Studio - Error on Build
« Reply #5 on: August 24, 2013, 07:20:14 pm »
I have the same problem was. Thanks for the help

 

anything