Error in created job site

I have created job site by using below mentioned code but when try to see created job site details Quantify app gets crashed. I have attached that error message.
Please advise.


RateProfileCollection oRateProfileCollection = RateProfileCollection.GetRateProfileCollection(ActiveStatus.Active, true, true, false);
Guid oRateProfile = new Guid();
oRateProfile = oRateProfileCollection[1].RateProfileID;

        Guid oBP =new Guid();
        BusinessPartner customer = BusinessPartner.GetBusinessPartnerByNumber("CUS-0000080");
        if (customer.BusinessPartnerID == Guid.Empty)
        {
            customer = BusinessPartner.NewBusinessPartner(PartnerTypes.Vendor);
            customer.AccountingID = "Test";
            customer.Name = "Test";
            customer.Save();
            System.Windows.Forms.MessageBox.Show("Customer Created!!");
        }
        else
        {
            oBP = customer.BusinessPartnerID;
        }

        var oTradingPartner = TradingPartner.GetTradingPartner("Dubai");

         
        StockingLocation Newjob = StockingLocation.NewStockingLocation(PartnerTypes.JobSite, oTradingPartner.TradingPartnerID);
            
        // Set parent ID
        //Newjob.ParentTradingPartnerID = oTradingPartner.TradingPartnerID;
        Newjob.Name = "TestJobSite";

        Newjob.BusinessPartnerID = oBP;

        Newjob.DefaultRateProfileID = oRateProfile;
        Newjob.BillingMethod = BillingMethodType.Arrears;
        Newjob.FirstInvoiceDate = "3/30/2021";
        
        Newjob.ArrearsBillingCycle = ArrearsBillingCycleType.Daily;
        Newjob.CycleDaysArrears = 10;
        try
        {
            if (Newjob.IsSavable)
            { Newjob.Save(); }
        }
        catch(Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
        }
        // Add other properties here
        // Check broken rules and save

Hello.

API code below is one that works fine on our end. Let us know if you still face any issue with this code.

    var profiles = RateProfileList.GetRateProfileList(ActiveStatus.Active, false, Guid.Empty, false);
    Guid profileID = profiles[0].RateProfileID;

    BusinessPartner customer = BusinessPartner.GetBusinessPartnerByNumber("CUS-0000880"); 
    if (string.IsNullOrEmpty(customer.Name))
    {
        customer = BusinessPartner.NewBusinessPartner(PartnerTypes.Customer);
        customer.Name = "CUS880";
        customer.PartnerNumber = "CUS-0000880";
        customer.Save();
    }

    Guid custID = customer.BusinessPartnerID;

    var parentTradingPartner = TradingPartner.GetTradingPartner("Branch");

    StockingLocation newJob = StockingLocation.NewStockingLocation(PartnerTypes.JobSite, parentTradingPartner.StockingLocationID);
    newJob.ParentTradingPartnerID = parentTradingPartner.TradingPartnerID;
    newJob.Name = "TestJobSite";
    newJob.BusinessPartnerID = custID;
    newJob.DefaultRateProfileID = profileID;
    newJob.BillingMethod = BillingMethodType.Arrears;
    newJob.FirstInvoiceDate = "3/30/2021";
    newJob.ArrearsBillingCycle = ArrearsBillingCycleType.Daily;
    newJob.CycleDaysArrears = 10;
    if (newJob.IsSavable)
        newJob.Save();

Thanks for posting.