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();
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)
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
Thank is working!