Tuesday, June 19, 2007

Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))

I've been caught out by this twice now. If you create a new web control by creating a new class and then inheriting from Control (or some other derived class) it will appear in your toolbox, but when you try and put it on a web form, either nothing happens or you'll get the error:

Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))

This somewhat baffling error message is caused by the fact that when you create a new class Visual Studio 2005 makes it private by default. I'm not sure if this is a good or bad thing, it sure as hell beats the "everything is public, every parameter is passed by reference, every variable is a variant" ethos that used to cause so much horrendous VB code to come into existence. Just a shame the error message doesn't give a clue to the real problem.

1 comment:

Mrityunjaya Kumar said...

I also faced the same issue while creating custom control.

In my case there was a parent Custom control and child custom control. Both were workig fine on designer. I then decided not to display the Parent control in tool box and set [TooboxItem(false) in child it was set [ToolboxItem(true)] and problem started.

After removing [ToolboxItem] attribute the problem was solved automatically.

Ridiculous problem!!!