Hi everyone,
Trying to write a Windows Forms app that connects to SimConnect to track times and fuel burns. I’m using C# and Visual Studio 2019. I’ve got a form with a button, and when the button is clicked, the code in the SDK for creating a SimConnect object is executed. I’m getting the following error:
System.BadImageFormatException
HResult=0x8007000B
Message=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.
Source=DTracker
StackTrace:
at DTracker.frmDtracker.btnConnect_Click(Object sender, EventArgs e) in C:\Users\markl\source\repos\DTracker\frmDtracker.cs:line 46
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at DTracker.Program.Main() in C:\Users\markl\source\repos\DTracker\Program.cs:line 21
The code that’s trying to execute (pure copy/paste from the SDK):
private void btnConnect_Click(object sender, EventArgs e)
{
SimConnect simconnect = null;
const int WM_USER_SIMCONNECT = 0x0402;
try
{
simconnect = new SimConnect("Managed Data Request", this.Handle, WM_USER_SIMCONNECT, null, 0);
}
catch (COMException ex)
{
}
if (simconnect != null)
{
simconnect.Dispose();
simconnect = null;
}
else
{
lblConnection.Text = "Connected!";
}
}
Any ideas? This happens if the sim is running or not. Help appreciated - thanks!
Mark