Search code examples
c#asp.net-mvcsdkcom-interopcomexception

How to use Brother bPac3 SDK in asp.net mvc


I am developing an asp.net mvc application and I want to utilize brother's SDK (Brother bPAC3 SDK) to create a label (.bmp image) for printout. Here is my code:

        string templatePath = Server.MapPath("~/Content/Labels/nameplate1.lbx");

        bpac.DocumentClass doc = new bpac.DocumentClass();
        if (doc.Open(templatePath) != false)
        {
            doc.GetObject("due").Text = "Due: 18-Oct-2019";

            doc.GetObject("cal").Text = "Cal'd: 18-Apr-2017";
            doc.GetObject("by").Text = "By: TF";
            doc.GetObject("type").Text = "Type: CAL-1";
            doc.GetObject("asset").Text = "Asset: test 6";
            doc.GetObject("dept").Text = "Dept: 14211 - N/A";

            // doc.SetMediaById(doc.Printer.GetMediaId(), true);
            //doc.StartPrint("", PrintOptionConstants.bpoDefault);
            doc.Export(ExportType.bexBmp, templatePath + "CalibrationCertficate.bmp",0);
           // doc.PrintOut(1, PrintOptionConstants.bpoDefault);
            //doc.EndPrint();
            doc.Close();
        }
       

I am able to run the sample downloaded from the SDK as a Windows Application with the same .Net framework (4.5.2) and environment (Any CPU or x86) without error.

With the asp.net application I am getting the following error (with Any CPU or x86):

An exception of type 'System.Runtime.InteropServices.COMException' occurred in MeasurementAssetManagement.dll but was not handled in user code

Additional information: Retrieving the COM class factory for component with CLSID {B940C105-7F01-46FE-BF41-E040B9BDA83D} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

I have looked at the difference between the references and I noticed that the asp.net application (not working) is showing the Interop.bpac version 1.3.0.0 and the windows form application is using the Interop.bpac version 1.0.0.0. I am not sure why this version would be different since I have tried both the following: referencing the dll file, and referencing the installed sdk COM type library.


Solution

  • I fixed the error by installing the bpac client found in C:\Program Files\Brother bPAC3 SDK\Redist, I no longer get the error but I am still not able to print the label. If you are able to find a solution let me know.