Problem about the "Using a Singleton Pattern with Eclipse Scripting API "

Oct 20, 2014 at 2:19 PM
Edited Oct 20, 2014 at 2:19 PM
I used the method mentioned in the article "Using a Singleton Pattern with Eclipse Scripting API" to create the instance of Eclipse API application. It works perfectly in API Version11.0. But when I ran the same code in API Version 13.5, it throws the error message "BadImageFormatException was unhandled". Could you please help me to determine what's wrong with it and how to solve the problem?

Note: the code is shown below:

___using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VMS.TPS.Common.Model.API;

namespace Cardan.ESAPI
public class ESAPIApplication
    private static readonly Lazy<ESAPIApplication> _instance = new Lazy<ESAPIApplication>(() => new ESAPIApplication());

    // private to prevent direct instantiation.
    private ESAPIApplication()
        Context = Application.CreateApplication(null, null);

     public Application Context { get; private set; }
    public static bool IsLoaded { get; set; }

     // accessor for instance
    public static ESAPIApplication Instance
            IsLoaded = true;
            return _instance.Value;

    public static void Dispose()
        if (IsLoaded) { Instance.Context.Dispose(); }

public partial class Form1 : Form
    VMS.TPS.Common.Model.API.Application app;
    public Form1()
        app = ESAPIApplication.Instance.Context;

Oct 20, 2014 at 2:59 PM
I have run this in the 13.1 framework (not 13.5) with no issues. It looks like your DLLs are not being loaded correctly. The tutorial I posted on Youtube used the 13.1 ESAPI framework. Just so we are on the same page, when you start a fresh console app, switch the build to x64 and hookup the Varian dlls, then add the singleton pattern, you are having the issue? Definitely odd if that is true.
Marked as answer by rexcardan on 10/22/2014 at 8:50 AM
Oct 20, 2014 at 4:27 PM
Thank you very much for your quick response. The tutorial on Youtube is very helpful. The problem I have is the CPU is not set to X64 in the build configuration. The problem is solved now.
Thanks again for your help.