3

I am getting weird error on c# winforms. I summarize the problem step by step.

  1. I have 1 model (public class)
  2. I have a winform that includes a datagridtable and this is binded to model.
  3. Winfom.cs is opened.
  4. Close the visual studio and reopen.
  5. I am getting error as below :

at System.RuntimeType. ThrowIfTypeNeverValidGenericArgument(RuntimeType type) SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters) MakeGenericType(Type[] instantiation)

at System.Windows.Forms.BindingSource. CreateBindingList(Type type) GetListFromType(Type type) ResetList() System.ComponentModel.ISupportInitialize.EndInit()

  1. When I click the error message it forwards me the winform.designer.cs below

(System.ComponentModel.ISupportInitialize)(this.tankModelBindingSource).EndInit();

  1. I close all of them without any change & reopen the winform.cs (designer)

  2. Error is gone!

Am I missing something? Every time do I have to get this error? Is this a bug or not?

Thanks.

    public void datagridFixedItemVisualization()
    {
        fixedItemModelBindingSource.DataSource = MainParticularsModel.FixedItemList;
    }

    private void dgTankSet_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {

        // CALCULATING....

        dgTankSet.DataSource = MainParticularsModel.TankList;

        dgTankSet.Refresh();

    }

    private void cmbCatFilter_SelectedIndexChanged(object sender, EventArgs e)
    {
        CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgTankSet.DataSource];
        currencyManager1.SuspendBinding();

        TankCategory cmbfiltername = (TankCategory)Enum.Parse(typeof(TankCategory), cmbCatFilter.SelectedItem.ToString());

        switch (cmbfiltername)
        {
            case TankCategory.ALL:
                makeALLrowsVisible();
                currencyManager1.ResumeBinding();
                break;

            case TankCategory.ETC:
                makeALLrowsVisible();
                foreach (DataGridViewRow row in dgTankSet.Rows)
                {
                    if (row.Cells[0].Value.ToString() != "ETC")
                    {
                        row.Visible = false;
                    }
                }
                currencyManager1.ResumeBinding();
                break;

        }

    }


    private void btnAddFixedItem_Click(object sender, EventArgs e)
    {
        using (FixedItemForm frm = new FixedItemForm() {FixedItemInfo=new FixedItemModel() })
        {
            if (frm.ShowDialog() == DialogResult.OK)
            {
                MainParticularsModel.FixedItemList.Add(frm.FixedItemInfo);

                fixedItemModelBindingSource.ResetBindings(false);

                fixedItemModelBindingSource.DataSource = MainParticularsModel.FixedItemList;

                dgFixedItems.Update();

                dgFixedItems.DataSource = fixedItemModelBindingSource;

            }
        }
    }
  • when the designer is opened - code runs. there is something you have perhaps changed in the designer code behind? if yes, you should not really touch the machine generate code as it can lead to odd behaviour of the designer code when it runs – jazb May 10 '19 at 07:03
  • "and this is binded to model" - what is the model? what is happening is almost certainly related to whatever you're assigning as the source... – Marc Gravell May 10 '19 at 07:11
  • This section is a little bit complicated. For simple understanding, Think about car model, and datagrid table shows cars (name, color, power etc) and if I change a property, model list also updated. So the datagrid table is just for visualization and changing parameters of model. – Xazar Cengiz May 10 '19 at 07:22
  • 1
    @XazarCengiz I doubt stronly that it is necessary to explain to Marc how the binding of a model works. I guess he asked you to post the code of the model and the binding – Mong Zhu May 10 '19 at 07:25
  • 1
    @MongZhu, I added some codes in my question at the top from VS. On the other hand model is binded from Properties>Datasource... – Xazar Cengiz May 10 '19 at 07:55
  • On the other hand I am doing some "trial and error". I delete all datagrid table and binding sources. But I got the same error ((System.ComponentModel.ISupportInitialize)(this.tankModelBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.fixedItemModelBindingSource)).EndInit(); Maybe generic list make this problem. All things are rounding by public static List TankList { get; set; } – Xazar Cengiz May 10 '19 at 08:11
  • I had a devExpress TreeList. THe datasource had somehow got set to System.Void. THis is weird because i searched the designer.vb file and did not find VOID anywhere.... anyhoo... that was the issue. Worst case, delete the control and readd – greg Oct 21 '22 at 17:24

0 Answers0