Skip to Content
avatar image
Former Member

Reflection in SAP B1 SDK

Hi, ALL

I'm trying to implement a reflection over the BusinessPartners object, but I'm getting the following error: "Object reference not set to an instance of an object.".

Bellow follows the source code:

 BusinessPartners PN = sapCom.Company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            Type BussinessPartnesType = PN.GetType(); // typeof(BusinessPartners);
            PropertyInfo propertySet = BussinessPartnesType.GetProperty("CardName", BindingFlags.Instance);
            propertySet.SetValue(PN, "BusinessPartners Test", null);
            PN.Add();

What can be done to achieve a similar result?
Add comment
10|10000 characters needed characters exceeded

  • Your code should work also with the following change.

    Type BussinessPartnesType = PN.GetType();// typeof(BusinessPartners);

    to

    Type BussinessPartnesType = typeof(SAPbobsCOM.IBusinessPartners);

    Note that you need to get the Interface, not the class it self. (IBusinessPartners, not BusinessPartners)

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 11, 2017 at 12:30 PM

    Hi Andrew,

    Try to use the InvokeMember method like below:

    BusinessPartners PN = oCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);
    
    
    Type BusinessPartnesType = PN.GetType();
    BusinessPartnesType.InvokeMember("CardName", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, PN, new object[] { "BusinessPartners Test" });
    Console.WriteLine(PN.CardName);
    

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded