Question

my code is as follows:

IList<Users> myData = new List<Users>();

myData = HelperUsers.GetUsersList(); // return IList<Users>

BindingSource bsUsers = new BindingSource { DataSource = myData };
dataGridViewUsers.DataSource = bsUsers;

dataGridViewUsers.Columns["Name"].HeaderText = "Name";
dataGridViewUsers.Columns["LastName"].HeaderText = "Last name";

dataGridViewUsers.Invalidate();

works perfectly still in debug, but when compiling as releace occurs following error "Object reference not set to an instance of an object." in the line:

dataGridViewUsers.Columns["Name"].HeaderText = "Name";

Thanks

Was it helpful?

Solution

The Name property of your Users class is being renamed/obfuscated. Therefore the Columns collection doesn't have an entry for it.

Per the Eazfuscator you can do the following to disable class property renaming:

[System.Reflection.ObfuscationAttribute(Feature = "properties renaming")]
class MyOneThousandAndThirdClass {
    // ...
}

Or for a single property:

class MyOneThousandAndFourthClass {

    [System.Reflection.ObfuscationAttribute(Feature = "renaming")]
    public string DisplayName
    {
        get;
        set;
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top