• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS [SOLVED] Dll error when trying to create a SimConnect

Messages
8
Country
italy
Hi guys,

I'm new to this kind of thingsand I would like to receive some information/help.

The Problem:
I downlaod the sdk from MSFS20 and installed
I 've made a c# project within vs2019 and I've add the reference to the Microsoft.FlightSimulator.SimConnect.dll located in MSFS SDK\SimConnect SDK\lib\managed.

I've wrote a simple script and I've compiled it:
When I press a button it create SimConnection() as follow:
Code:
            Handle = new IntPtr();
            simConnect = new SimConnect("Teleporter", Handle, CONSTANTS.USER_SIMCONNECT, null, 0);

as soon as I press the button and as soon it loads the dll to invoke the function call I get this error:

System.BadImageFormatException: 'Could not load file or assembly 'Microsoft.FlightSimulator.SimConnect, Version=11.0.62651.3, Culture=neutral, PublicKeyToken=baf445ffb3a06b5c' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

How could I resolve this problem? Am I missing something or importing the wrong dll?
 
Last edited:
Messages
11
Country
brazil
Hi guys,

I'm new to this kind of thingsand I would like to receive some information/help.

The Problem:
I downlaod the sdk from MSFS20 and installed
I 've made a c# project within vs2019 and I've add the reference to the Microsoft.FlightSimulator.SimConnect.dll located in MSFS SDK\SimConnect SDK\lib\managed.

I've wrote a simple script and I've compiled it:
When I press a button it create SimConnection() as follow:
Code:
            Handle = new IntPtr();
            simConnect = new SimConnect("Teleporter", Handle, CONSTANTS.USER_SIMCONNECT, null, 0);

as soon as I press the button and as soon it loads the dll to invoke the function call I get this error:

System.BadImageFormatException: 'Could not load file or assembly 'Microsoft.FlightSimulator.SimConnect, Version=11.0.62651.3, Culture=neutral, PublicKeyToken=baf445ffb3a06b5c' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

How could I resolve this problem? Am I missing something or importing the wrong dll?

i may be wrong but i believe you can put the dll inside the executable folder (debug or release)
 
Messages
8
Country
italy
i may be wrong but i believe you can put the dll inside the executable folder (debug or release)
Thanks for the answer,

yes I have that dll inside the executable folder.. maybe I've pick up the wrong dll? did you managed to make it work?
 
Messages
11
Country
brazil
Thanks for the answer,

yes I have that dll inside the executable folder.. maybe I've pick up the wrong dll? did you managed to make it work?
in fact i'm still starting with simconnect, still with a lot of difficulty, i wanted to do a simple project with just one button and a label to send and receive a parameter.
but i am having a hard time understanding even reading the sdk manual.
 
Messages
523
Country
england
Are you compiling 64-bit (or "Any CPU"?) SimConnect is a 32-bit dll, and requires you to compile x86 (note: I haven't actually tried to build the 2020 library, but that's been the case with all the legacy SimConnects).

Incorrect Format quite often means you're trying to load a 32bit dll in a 64bit exe, or vice versa.
 
Messages
8
Country
italy
One things come to my mind:
I've download the SDK from msfs20 in game dev menu, installed and I've found abunch of files and folders inside the SimConnect SDK folder.
DoI have to do somethings with those?
 
Messages
8
Country
italy
Quick Update: I've managed to solve the problem as follow:
on post build i copy this 2 files:


Code:
xcopy "PATH_TO\SimConnect.cfg" "." /Y
xcopy "PATH_TO\SimConnect.dll" "." /Y


SimConnect.dll is the ddl inside "SimConnect SDK\lib\"

Also TargetPlatform set to x64 and .NET Framework 4+
 
Messages
1
Country
australia
Hi levenlol

I have been trying to learn the sdk and create a simple program like you but i have not been successful. I get the same error and I've not been able to resolve it as you have suggested. Appreciate any clues to where I am going wrong?

Regards

Quick Update: I've managed to solve the problem as follow:
on post build i copy this 2 files:


Code:
xcopy "PATH_TO\SimConnect.cfg" "." /Y
xcopy "PATH_TO\SimConnect.dll" "." /Y


SimConnect.dll is the ddl inside "SimConnect SDK\lib\"

Also TargetPlatform set to x64 and .NET Framework 4+
 
Messages
2
Country
italy
Hi levenlol

I have been trying to learn the sdk and create a simple program like you but i have not been successful. I get the same error and I've not been able to resolve it as you have suggested. Appreciate any clues to where I am going wrong?

Regards
Hi befitphoneix,
if you use Post-build -> try "build Solution" and after push Start button. The next time you run your project the files have already been copied
or if you prefer, use Pre-Build and not Post-build.

And.. at to day, I use this commands line:
xcopy "C:\MSFS SDK\SimConnect SDK\lib\SimConnect.dll" "$(TargetDir)" /y
xcopy "C:\MSFS SDK\Documentation\html\assets\Files\SimConnect\SimConnect.cfg" "$(TargetDir)" /y

Hope help you.
 
Top