2013-08-05 42 views
2

我試圖在我的winforms應用程序中實現POS.NET。我想要做的是從我的EPSON TM-T20收據打印機打印收據。我已經成功地構建了一個打印測試應用程序:在.NET 4.0中使用POS.NET WinForms應用程序失敗

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); 
    } 

這在.NET 2.0應用程序中正常工作。但是當我將代碼複製到我的4.0項目時,它會在printer.Open()引發異常。

異常:捕獲:「方法打開拋出異常,無法創建服務對象實例,或無法獲得其IDispatch接口。 (Microsoft.PointOfService.PosControlException) Microsoft.PointOfService.PosControlException被捕獲:「方法打開引發異常,無法創建服務對象實例,或無法獲得其IDispatch接口。」 時間:2013年5月8日23點21分17秒 主題:主線程[6284]

出現這種情況,即使我從我的testproject建立一個DLL,並引用它在我的主要應用,以及當我把它在我的解決方案中運行2.0的單獨項目中。一個webserch只是想出了這可能與.NET版本有關。

我已經在應用程序配置中將supportedRuntime設置爲2.0.50727,但沒有做任何事情。對這裏出了什麼問題的建議非常受歡迎。

回答

2

我也沒搞清楚,這是我的自我補充說:

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

到我的app.config的伎倆!

+0

我有同樣的錯誤。 Windows 7框架3.5和我這一行沒有幫助。即使不知道該怎麼辦:( – Evgeny

相關問題