In my first SAP B1 project I set Embed Interop Types to True for the SAPbobsCom.dll
. This was a "DI API" add-on project, i.e. there was no need to run the add-on from inside SAP B1. The code I created compiled just fine and I thought I was OK.
However, a new requirement arose that it would have to run inside SAP B1. Long story short, I realized that in order to package the add-on the SAP b1 tools required that I set Embed Interop Types to False.
I then found some articles in SAP forums indicating that it was advisable to set interop types to false, otherwise it would "cause problems". But no explanation was given as to why, or what the problems would be. I am wondering whether this is a problem that is specific to the SAP classes, or to COM, or something else. Why would that setting change the way the classes behave?
When I attempted to recompile the add-on with Embed Interop Types set to False many of the statements that used SAPbobsCOM classes failed. The errors were of the form: Cannot implicitly convert type 'xyz' to 'abc'. An explicit conversion exists (are you missing a cast?)
For example, in order to get the statement:
objRecSetDN = SapObjects.oCompany.GetBusinessObject(BoObjectTypes.BoRecordset)
to compile, I had to change it to:
objRecSetDN = (SAPbobsCOM.Recordset)SapObjects.oCompany.GetBusinessObject(BoObjectTypes.BoRecordset)
And I had to change:
string CheckSend = RS.Fields.Item("U_Send").Value;
to:
string CheckSend = (string)RS.Fields.Item("U_Send").Value;
I have been making SAP B1 AddOns for years and have never set Embed Interop Types
to false. I do not think you have to do this. This is for addons added using the .ard file and programs running outside of B1.
This applies also to SAPbouiCom.dll
.
I package my addons within Visual Studio using the B1DESetup_B192
tool and there is no such requirement as you stated above. See image below.