2012-04-18 58 views
0

我有一個程序,它是.net.when我執行程序時得到這個異常。程序應該與財務打印機通信。執行程序時發生異常c#程序

Retrieving the COM class factory for component with CLSID {741F1E1B-0D59-4F59-A775-3E1B13721638} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using FiscPrinter = FiscPrnSys.IFiscPrnIface; 
using System.Runtime.InteropServices; 
public class Class1 
{ 
    public List<String> salesITems = new List<String>(); 
    public String user; 
    public String shop; 
    public double total; 
    public double subtotal; 
    public String tax; 
    public short data = (short) 8; 
    public short parity = (short)0; 
    public short stopbit = (short)1; 

    public void PrintBon() 
    { 
     FiscPrnSys.IFiscPrnIface FiscPrinter = new FiscPrnSys.FiscPrnIface();  (this  where the program is bringing this exemption) 
     FiscPrinter.Connect("COM2", 9600, data, parity, stopbit); 
     FiscPrinter.TestPrinter((short)48, "1,0,1", "HELLO"); 
     FiscPrinter.Sale("TEST ITEM 1", "A", 2, 2, 0); 
     FiscPrinter.Sale("TEST ITEM 1", "A", 2, 2, 0); 
     FiscPrinter.Sale("TEST STOCK ITEMS ZERO VAT", "B", 2, 2, 0); 
     FiscPrinter.Sale("Cooking Fat Always Ultra", "B", 2, 2, 0); 
     FiscPrinter.PrintFiscalText("TEST STOCK ITEMS VATABLE"); 
     FiscPrinter.Sale("001000124", "A", 2, 2, 0); 
     FiscPrinter.PrintFiscalText("Kimbo 1 Kg"); 
     FiscPrinter.Sale("598699484", "A", 5, 5, 0); 
     FiscPrinter.PrintFiscalText("Tily Cooking Fat"); 
     FiscPrinter.Sale("484949404", "A", 2, 2, 0); 
     FiscPrinter.Sale("Always ULtra", "A", 10, 2, 0); 
     FiscPrinter.Disconnect(); 
    } 
    public void setUser(String user) 
    { 
     this.user = user; 
    } 
    public void setShop(String shop) 
    { 
     this.shop = shop; 
    } 
    public void addSaleItem(String item) 
    { 
     salesITems.Add(item); 
    } 
    public void setDouble(double pTotal) 
    { 
     this.total = pTotal; 
    } 
    public void setSubTotal(double sTotal) 
    { 
     this.subtotal = sTotal; 
    } 
    public void setTax(String pTax) 
    { 
     this.tax = pTax; 
    } 
} 

這個類被另一個類,這是所謂的

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using IncortexLibrary; 

class Program 
{ 
    static void Main(string[] args) 
    { 
     Class1 printer = new Class1(); 
     printer.PrintBon(); 
    } 
} 

輸出:

Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the 
COM class factory for component with CLSID {741F1E1B-0D59-4F59-A775-3E1B1372163 
8} failed due to the following error: 80040154 Class not registered (Exception f 
rom HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn 
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo 
    olean& bNeedSecurityCheck) 
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec 
    kThis, Boolean fillCache) 
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s 
kipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) 
    at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
    at System.Activator.CreateInstance(Type type) 
at IncortexLibrary.Class1.PrintBon() in C:\Documents and Settings\woodley-who 
lesalers\My Documents\bst project\Projects\IncortexLibrary\IncortexLibrary\Class 
1.cs:line 29 
    at ConsoleApp.Program.Main(String[] args) in C:\Documents and Settings\woodle 
y-wholesalers\My Documents\bst project\Projects\ConsoleApp\ConsoleApp\Program.cs 
:line 15 

這給headache.i已經在SYSTEM32註冊文件.dll文件但它仍然給我帶來麻煩。這意味着我在錯誤的程序中灌輸程序,打印機顯示爲null.p租賃的幫助,因爲我已經嘗試通過網絡來走,但我沒有得到解決

+1

rgsvr32 COM對象 – Mufaka 2012-04-18 06:54:20

+0

我相信過程中發生的所有異常執行。 :P – albertjan 2012-04-18 06:55:47

+0

完全重複http://stackoverflow.com/q/1036856/55209 – 2012-04-18 06:55:57

回答