Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

Unable to cast COM object of type 'System.__ComObject' to interface type

$
0
0

Hi experts,

I get following error:

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbobsCOM.ReportTypesService'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2DC3C9A3-A237-4DB3-A0BC-AB92D24ED68E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

For following Code :

       public void m_Add_CrLayouts()

        {

 

 

            try

            {

 

 

                //Add New Report Type to Report Type Service

                SAPbobsCOM.ReportTypesService rptTypeService = (SAPbobsCOM.ReportTypesService)(oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService));

                SAPbobsCOM.ReportType newType = (SAPbobsCOM.ReportType)(rptTypeService.GetDataInterface(SAPbobsCOM.ReportTypesServiceDataInterfaces.rtsReportType));

                newType.TypeName = "Calibaration";

                newType.AddonName = "Calibartion Add-On";

                newType.AddonFormType = "Calibaration";

                newType.MenuID = "CalibarationSubMenu01";

 

 

                SAPbobsCOM.ReportTypeParams newTypeParam = (SAPbobsCOM.ReportTypeParams)(rptTypeService.AddReportType(newType));

 

 

                //Add new Report Layout to Report Layout Service

                SAPbobsCOM.ReportLayoutsService rptService = (SAPbobsCOM.ReportLayoutsService)(oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService));

                SAPbobsCOM.ReportLayout newReport = (SAPbobsCOM.ReportLayout)(rptService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayout));

 

 

                //report 1

                newReport.Author = oCompany.UserName;

                newReport.Category = SAPbobsCOM.ReportLayoutCategoryEnum.rlcCrystal;

                newReport.Name = "QC_COA_RM";

                newReport.TypeCode = newTypeParam.TypeCode;

 

 

                SAPbobsCOM.ReportLayoutParams newReportParam = (SAPbobsCOM.ReportLayoutParams)(rptService.AddReportLayout(newReport));

 

 

                //Set the report layout into the report type

                newType = rptTypeService.GetReportType(newTypeParam);

                newType.DefaultReportLayout = newReportParam.LayoutCode;

                rptTypeService.UpdateReportType(newType);

 

 

                // Link the Report layout code to the Crystal Report file

 

 

                SAPbobsCOM.BlobParams oBlobParams = (SAPbobsCOM.BlobParams)(oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService));

                oBlobParams.Table = "RDOC";

                oBlobParams.Field = "Template";

                SAPbobsCOM.BlobTableKeySegment oKeySegment = (SAPbobsCOM.BlobTableKeySegment)(oBlobParams.BlobTableKeySegments.Add());

                oKeySegment.Name = "DocCode";

                oKeySegment.Value = newReportParam.LayoutCode;

 

 

                //Upload the report to SAP B1 DB

 

 

                System.IO.FileStream oFile = (System.IO.FileStream)(new FileStream("C:\\MY IMP FILES\\QC-COA-Raw Material DOcENtry.rpt", System.IO.FileMode.Open));

                int fileSize = (int)oFile.Length;

                byte[] buf = BitConverter.GetBytes(fileSize);

                oFile.Read(buf, 0, fileSize);

                oFile.Dispose();

 

 

                SAPbobsCOM.Blob oBlob = (SAPbobsCOM.Blob)(oCompany.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlob));

                oBlob.Content = Convert.ToBase64String(buf, 0, fileSize);

                oCompany.GetCompanyService().SetBlob(oBlobParams, oBlob);

 

 

 

 

            }

            catch (Exception ex)

            {

 

 

                oSBO_Application.MessageBox("[Layout Event] - " + ex.Message, 1, "Ok", "", "");

            }

            finally

            {

                GC.Collect();

            }

        }

 

 

please help me out of this problem


Viewing all articles
Browse latest Browse all 3316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>