Having issues with C# code (New to C# !)

raymac

Member
Joined
Jan 27, 2023
Messages
5
Programming Experience
5-10
Hi folks,
Please forgive my lack of knowledge in this area, I'm a newbie to Visual Studio 17 C#!

I am trying to run the Execute() function in the Class below from a Windows Form.
See below for code...
C#:
Expand Collapse Copy
using System;

namespace Tobii.Research.CodeExamples
{
    internal static class EyeTrackingOperations_FindAllEyeTrackers
    {
        internal static EyeTrackerCollection Execute()
        {
            // <BeginExample>
            Console.WriteLine("\nSearching for all eye trackers");

            EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers();
            foreach (IEyeTracker eyeTracker in eyeTrackers)
            {
                Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", eyeTracker.Address, eyeTracker.DeviceName, eyeTracker.Model, eyeTracker.SerialNumber, eyeTracker.FirmwareVersion, eyeTracker.RuntimeVersion);
            }
            // <EndExample>

            return eyeTrackers;
        }
    }
}
For some reason, I just can't get it to work.
Would anyone be good enough to give me a clue as to how to do it?

I'm trying to run the function Execute() in the above code from the code below...
C#:
Expand Collapse Copy
public Form1()
        {
            InitializeComponent();
                       ????
        }
I would have thought that one has to create an object from the class by using...
C#:
Expand Collapse Copy
EyeTrackingOperations_FindAllEyeTrackers track1 = new EyeTrackingOperations_FindAllEyeTrackers;
then running...
C#:
Expand Collapse Copy
track1.Execute();
... but that throws errors, like as if the Class wasn't there. Is it something to do with the private/static/public configuration?

Thanks,
Ray
 
Last edited by a moderator:
Think I've cracked it, however I now get the following message...
Code:
Expand Collapse Copy
System.BadImageFormatException
  HResult=0x8007000B
  Message=Could not load file or assembly 'Tobii.Research, Version=1.10.1.1282, Culture=neutral, PublicKeyToken=70326046dcdce6cb' or one of its dependencies. An attempt was made to load a program with an incorrect format.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
... which no doubt Tobii could only answer :/.

Thanks,
Ray
 
Last edited by a moderator:
If you are running as 32-bit and try to load a 64-bit DLL, or vice versa, you can get that error.

Alternatively, but less common, if someone decided to modify the assembly by doing some IL or resource hacking, and the strongly signed assembly can also fail to load with the same type of error.
 
For some reason, I just can't get it to work.
Would anyone be good enough to give me a clue as to how to do it?
Your lines 10-16 look to be code that was meant to be put into a console program, but you are trying to put it into a WinForms program.
 
Back
Top Bottom