espvar
espvar

Reputation: 1065

Use of POS.NET in .NET 4.0 WinForms application fails

I'am trying to implement POS.NET in my winforms application. What I'am trying to do is printing receipt from my EPSON TM-T20 receipt printer. I have successfully built an test application for printing:

    try
    {
        var posExplorer = new PosExplorer();
        DeviceCollection devices = posExplorer.GetDevices((DeviceCompatibilities)Enum.Parse(typeof(DeviceCompatibilities), "Opos", false));
        DeviceInfo deviceInfo = devices[0];

        var posCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo);
        Console.WriteLine("Created instance of device: " + deviceInfo.ServiceObjectName + "\r\n");
        posCommon.Open();
        Console.WriteLine("Opened device: " + deviceInfo.ServiceObjectName + "\r\n");
        var printer = (Microsoft.PointOfService.PosPrinter)posCommon;
        printer.Claim(1000);
        printer.DeviceEnabled = true;
        printer.PrintNormal(PrinterStation.Receipt, text + "\x1B|1lF");
        printer.CutPaper(90);
        printer.Release();
        printer.Close();
    }
    catch (Exception ae)
    {
        Console.WriteLine(ae.Message);
    }

This works fine in an .NET 2.0 application. But when i copy the code to my 4.0 project it throws an exception at printer.Open();

Exception:Caught: "Method Open threw an exception. Could not create a service object instance, or could not get its IDispatch interface." (Microsoft.PointOfService.PosControlException) A Microsoft.PointOfService.PosControlException was caught: "Method Open threw an exception. Could not create a service object instance, or could not get its IDispatch interface." Time: 05.08.2013 23:21:17 Thread:Main Thread[6284]

This happens even if i build a dll from my testproject and reference it in my main application as well as when i put it in a separate project running 2.0 in my solution. A webserch only came up with that this might have somthing to do with the .NET versions.

I have set supportedRuntime to 2.0.50727 in the app config, but that did nothing. Suggestions to what is wrong here is very welcome.

Upvotes: 2

Views: 2955

Answers (1)

espvar
espvar

Reputation: 1065

I did figure out this my self adding:

<runtime>
    <NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>

to my app.config did the trick!

Upvotes: 2

Related Questions