Anybody seen this exception before, Google doesn't have a single post regarding the exception. The code that raises the error is a simple add.
Items.Add(item);
System.TypeLoadException: Bad flags on delegate constructor.
at System.Windows.Forms.ListView.Sort()
at System.Windows.F开发者_运维知识库orms.ListView.InsertItems(Int32 displayIndex, ListViewItem[] items, Boolean checkHosting)
at System.Windows.Forms.ListView.ListViewNativeItemCollection.Add(ListViewItem value)
at System.Windows.Forms.ListView.ListViewItemCollection.Add(ListViewItem value)
The cause is a System.Windows.Form v2.0 bug I identified this morning (and that is fixed in System.Windows.Form v4.0).
For me it happened while my code adds an Item
to the ListBox
while the hosting process is shutting down. The private instance field ListBox.listItemsArray
is null and this provokes the NullReferenceException
. I don't know exactly why ListBox.listItemsArray
is null, but I'd guess it is related to a handle creation problem.
For me the workaround was easy since a try/catch
was enough because the process is shutting down anyway. You can certainly dig ino the problem with the decompiling Reflector feature as I did:
I can give you general advice on how to solve internal exceptions. Take tool called Reflector (google it) and get into the method System.Windows.Forms.ListView.Sort()
and try to understand what conditions lead to exception. this helped me many times.
I think that it's a case of searching on the error number 80131506. I've found a few references:
If your application has been written using NET 2 and maybe ASP.NET, but more importantly runs under a user profile then look here:
Microsoft hotfix
I've also come across someone whereby SQL Developer on the server machine was causing issues: SQL DEvloper issues
There is also talk of this problem occuring on 64 bit machines shown here. Typically involving access to memory addresses beyond 4Gb.
精彩评论