Hi Marcus, thank you for contributing this posting (above). You have, indeed, found a bug in the code I wrote. Please accept my apologies for the inconvenience.
The fix is, happily, quite simple. I forgot an important clause in the expression used in the "if" statement shown in red in your posting. I believe the correct logic should read:
if (useFields &&
(!ControlAsDetailsView.AutoGenerateRows) &&
((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert) &&
(!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible))
This fix is at line 59 of App_Code\Adapters\DetailsViewAdapter.cs. If you are using the VB version the syntax is slightly different. Use AndAlso in place of the &&.
The variable called useFields is set outside of the "for" loop that this "if" statement is within. The useFields boolean dictates whether or not we can reliably use the Fields collection in the DetailsView. We can't use it reliably when the field count doesn't match the row count because some rows are being autogenerated, as is the case in your scenario. In those situations, we always want to guard against referring to Fields by first checking that we are allowed to, via the useFields boolean. I simply forgot to do so here. If you look further down in the code below that "if" you'll see useFields is used properly in other "if" checks that are similar. Again, sorry for the inconvenience caused by this oversight.
Please post here if you run into further problems with this scenario. It's always possible that I'm out-to-lunch so-to-speak with my diagnosis and solution... though I was able to duplicate your exact error message here by adding AutoGenerateInsertButton="true" to a copy of DetailsView.aspx (the sample page for the DetailsView adapter from the kit).