6

I developed a web application using asp.net C# to place online orders. my app. works fine on SAP server (windows 2008 R2) but when I copied my project to my local machine (runs windows 7) I got an error, can't see the SAPbobsCOM reference. I don't have SAP API DI on my machine
I tried to debug my application in X86 to solve the problem. but no luck.

This is the error I got

Retrieving the COM class factory for component with CLSID {632F4591-AA62-4219-8FB6-22BCF5F60090} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

enter image description here

Thank you.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Sam
  • 406
  • 1
  • 11
  • 24
  • 2
    You need to install the DI-API on this machine. This error occurs when your .Net code tries to use a type defined in the DI-API, but is unable to load it (the DI-API uses COM for interoperability). – Lilshieste Apr 24 '14 at 18:26
  • @Lilshieste why we must install the DI-API, I have add Interop.SAPbobsCOM.dll in my project. I think the program use this dll – John Nguyen Sep 03 '14 at 08:51
  • @JohnNguyen The installation process registers the DI-API with COM. The `Interop.SAPbobsCOM.dll` file is just an [interop assembly](http://stackoverflow.com/questions/1670940/what-is-the-interop-dll), so the COM registration is still necessary. – Lilshieste Sep 03 '14 at 14:14
  • @Lilshieste thank you, but after I reinstall DI-API, I still get this error. in C#, the error raised by code: `SAPbobsCOM.Company vcmp = new SAPbobsCOM.Company()` can you help me – John Nguyen Sep 04 '14 at 01:48
  • @Sam, would you mind checking out my [answer](https://stackoverflow.com/a/40538748/3345644) and see if you could mark it as an accepted one for further readers? – Alexander Abakumov Sep 12 '18 at 21:07
  • @AlexanderAbakumov, your answer is more detailed. I want to mention DI API i have installed is x64. in VS I didn't have to choose `x64`, I choose `Any CPU` as platform target and all seems to be ok. I'm using VS2017. – Sam Sep 13 '18 at 15:18
  • @Sam, thank you. I've added an explanation to my answer. Most likely with your current setup, your process bitness just matches the installed DI API bitness. If you caused them to mismatch, you'd run into this issue with `Any CPU` set instead of explicitly setting it to the actual DI API bitness. – Alexander Abakumov Sep 13 '18 at 17:25
  • @AlexanderAbakumov, makes sense. Thanks for taking the time to explain – Sam Sep 13 '18 at 17:35

3 Answers3

12

The problem is caused by having Any CPU platform target selected for your app.

This means your app could run as both 32x and x64 process depending on a .NET runtime bitness executing your app. If your process runs as x64 and you have 32x DI API installed (or vice versa), you get this issue, since DI API requires loading native DLLs into your process. However, 32x DLLs couldn't be loaded into a x64 process and vice versa.

That's why we have to explicitly allow the exact same bitness for your app as the DI API bitness it would use.

To do this:

  • first, have SAP DI API (c:\Program Files\SAP\SAP Business One DI API\) and SAP Business One SDK (c:\Program Files (x86)\SAP\SAP Business One SDK\) installed
  • next, figure out which version (x86 or x64) of DI API you have. If it's installed in c:\Program Files - you have x64 version and if it's in c:\Program Files (x86)\ - you have x86 one
  • finally, go to your Project properties -> Build tab and set the same Platform target that your DI SDK version is: enter image description here
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • 1
    After spending a decent amount of hours searching for a resolution to this problem, changing my Platform Target from x86 to x64 finally resolved this for me. I originally had changed it from Any CPU to x86 but never tried the x64 option. Thanks! – DLR Oct 16 '18 at 05:42
5

I had the exact same issue. My SAP components was running in a WCF service.

To fix the issue changed the application pool to run under 32-bit.

Ewald
  • 698
  • 7
  • 10
1

I got the same problem. It was because the SAP Business One references SAPbobsCOM and SBODI_Server were missing. I added these references and it worked. You need to add SAP DI API on your machine for using SAPbobsCOM reference.

bluish
  • 26,356
  • 27
  • 122
  • 180