我正在使用以下代码使用 AIF=(应用程序集成框架)在 AX 2012 =(Microsoft Dynamics AX)中导入客户记录的多个邮政地址。我正在使用具有两个邮政地址的客户记录测试此代码。代码第一次运行(第一次循环)时,它运行得很好,但在第二轮它失败了,给了我数组超出范围的错误。查看以下代码,对可能导致此错误的原因有何建议?
index = 0;
AxdEntity_DirPartyPostalAddressView[] array = new AxdEntity_DirPartyPostalAddressView[index];
foreach (DataRow row2 in row.GetChildRows("HdrLine"))
{
AxdEntity_DirPartyPostalAddressView address =
new AxdEntity_DirPartyPostalAddressView
{
LocationName = row2["AXDirPartyPostalAddress_LocationName"].ToString(),
Street = row2["AXDirPartyPostalAddress_Street"].ToString(),
City = row2["AXDirPartyPostalAddress_City"].ToString(),
State = row2["AXDirPartyPostalAddress_State"].ToString(),
CountryRegionId = row2["AXDirPartyPostalAddress_Country"].ToString(),
ZipCode = row2["AXDirPartyPostalAddress_zipcode"].ToString(),
Roles = row2["AXDirPartyPostalAddress_AddRoles"].ToString()
};
Array.Resize<AxdEntity_DirPartyPostalAddressView>(ref array, index + 1);
array[index] = address;
custTable.DirParty[index].DirPartyPostalAddressView =
new AxdEntity_DirPartyPostalAddressView [] { array[index] };
index++;
}