cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problems using SAP DI API in C#/.NET Core

Former Member
4,432

In one project at the company I work with, we have a server application written in C#, targeting .NET Core 2.2. This application now has to access data an existing database which belongs to an existing installation of SAP B1, which used by our customer. The preferred way to do that seems to be via the DI API.
Our customer provided us with installation files for both the DI API and the SAP B1 SDK and has already obtained a license for one program. It would be preferable to run our server application on a different physical server (than the one the B1 and the database are running on). Both servers are running on Windows Server 2012 and are maintained by our customer. I am currently trying to get a development environment working on our own server, running Windows Server 2016.

There are two issues with trying to get this setup working, the second of which may very well be the reason for the first:
* The SDK is installed on our development server and we can reference SAPbobsCOM from the library SAPBusinessOneSDK.dll and access some static properties (for example the enum SAPbobsCOM.BoDurations.du_Days). But as soon as we instantiate the Company object (i.e., SAPbobsCOM.Company c = new SAPbobsCOM.Company(); ) the application crashes at precisely that line. Debugging reveals a System.Runtime.InteropServices.COMException (0x80040154): 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)). The same occurs when running a compiled test program on the customer's target server (the one NOT running SAP B1).
* Installing the DI API on our development server fails altogether. The error message says: "Installation will be terminated; installation of project prerequisites do not exist in their correct location". The last line in the log file created by the setup says: "ERROR: Prerequisites installation failed with return value : 1603"
It seems obvious that something is not installed / set up correctly. As the documentation provided by SAP is net very explicit on how to set up such an application, we are currently stuck on how to get database access working.


A note on the side:
It wouldn't be impossible to get access to the server running the B1 and to run our server application there. Yet (if it can be achieved) we would prefer to have our server application running on dedicated server, as described above.

So the question is: How to set this up correctly?
More precisely: How to install the DI API? How is the first problem presumably related to the second and if it isn't: How to solve the first one? Is it (as documentation and code examples by SAP suggest) even possible to run the an application that uses the DI API on a different physical server than the one the B1 is running on?


Any advice would be appreciated!

Accepted Solutions (0)

Answers (4)

Answers (4)

SAP_UserKT
Newcomer
0 Kudos

I know this is an old query, however, I had the same error and realized it happened when I instantiated the variable that is to contain Company without an initialization value.

 

public static SAPbobsCOM.Company? oCom;

 

this generated the error that you indicate, and it was solved with this variable initialization.

 

public static SAPbobsCOM.Company? oCom = null;

 

is the only thing that was needed in my case.

Regards

Santiago M.

P.S.: this was translated, my native language is Spanish.

kennywest
Explorer
0 Kudos

REGDB_E_CLASSNOTREG is an typical error when you dont have the correct DI API installed.

SAPBusinessOneSDK.dll should be treated as an interface to the DI API COM when developing and and building your project.

Install DI API with matching platform (x86/x64) to your .NET program.
Be aware of the 'Prefer 32-bit' option in the Build tab in your .NET project

former_member675331
Discoverer
0 Kudos

For #1, SAPBusinessOneSDK.dll may not work without DI API, I think you should install DI API on your dev server.

For #2, you may not be able to just copy DI API folder and install from there, you may need to copy the entire B1 installation folders/files, and run the 'root' setup.exe or the DI API setup.exe in sub-folder to do the installation.

anrodse
Participant
0 Kudos

As far as I know, Interop COM libraries don't works with .net Core. You have to use .net Framework.

I you have any solution to this issue, please please let me know.

paolo_fornari3
Participant
0 Kudos

Same problem, did you find a solution ? Thanks

anrodse
Participant

You can use COM objects with the latest versions of .NET (.Net 5 and on). Only problem is your application won't be cross-platform.

To make it works, define target platform in the .csproj xml file as this:

        <TargetFramework>net6.0-windows</TargetFramework>

Then go to Project References > COM and find the one you want (DiAPI, UiApi, DiServer or any other). I daily use DiAPI with no issues.