Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.NET 4.0 WinForms应用程序中使用POS.NET失败_C#_.net - Fatal编程技术网

C# 在.NET 4.0 WinForms应用程序中使用POS.NET失败

C# 在.NET 4.0 WinForms应用程序中使用POS.NET失败,c#,.net,C#,.net,我正在尝试在我的winforms应用程序中实现POS.NET。我想做的是从我的爱普生TM-T20收据打印机打印收据。我已成功构建了一个用于打印的测试应用程序: try { var posExplorer = new PosExplorer(); DeviceCollection devices = posExplorer.GetDevices((DeviceCompatibilities)Enum.Parse(typeof(DeviceCompat

我正在尝试在我的winforms应用程序中实现POS.NET。我想做的是从我的爱普生TM-T20收据打印机打印收据。我已成功构建了一个用于打印的测试应用程序:

    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);
    }
这在.NET2.0应用程序中运行良好。但是当我将代码复制到我的4.0项目时,它会在printer.Open()上抛出一个异常

异常:捕获:“方法Open引发异常。无法创建服务对象实例,或无法获取其IDispatch接口。”(Microsoft.PointOfService.PosControlException) 捕获到Microsoft.PointOfService.PosControlException:“方法Open引发异常。无法创建服务对象实例,或无法获取其IDispatch接口。” 时间:05.08.2013 23:21:17 线程:主线程[6284]

即使我从testproject中构建了一个dll并在主应用程序中引用它,或者将它放在解决方案中运行2.0的单独项目中,也会发生这种情况。一位网络专家只想到这可能与.NET版本有关


我已经在应用程序配置中将supportedRuntime设置为2.0.50727,但没有任何作用。这里的错误建议是非常受欢迎的

我在自己添加时确实发现了这一点:

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


我的app.config成功了

我也有同样的错误。Windows7Framework3.5和I这一行没有帮助。甚至不知道该怎么办:(