04 Feb

Solution: Invalid FORMATETC structure

I was making a ASP.NET components library and when I was ready with my library I made a Web Application project and started dragging and dropping to them my form.

To my surprise, I was not able to do so and I got following error.

The operation could not be completed. Invalid FORMATETC structure

Many of you may also get a similar error:

Invalid FORMATETC structure (Exception from HRESULT: 0×80040064 (DV_E_FORMATETC))

After few hours extensive searching on net and trying out many solutions, I got to know few things.

Microsoft uses this exception in many scenarios and not in a specific situation. This means the root causes can be different but it will show you only this error.

This makes you to try many solution. Unfortunately no solution listed on Internet worked for me and I was forced to find my own.

I’m listing my solution along with other solutions that may work.

————————————————————————————–

See Also:  MCTS 70-630 all you need to know to clear this exam

————————————————————————————–

I highly recommend to read all solutions and try the simpler ones first and then go for complex ones. This will save your day.

Solution 1:

ASP.NET 3.5

In my case I was using following hierarchy.

ASP.NET Button -> ThemedButton -> DesktopButton.

I didn’t wanted developers to start using ThemedButton so I don’t wanted to show it on toolbox.

So I put some attributes to it. Like below:

[DefaultProperty("Text"), ToolboxData("<{0}:ThemedButton runat=server>"), ToolboxItem(false), DesignTimeVisible(false)]

I don’t know the root cause, but removing following piece of code worked for me.

ToolboxItem(false)

Solution 2:

Resetting toolbox items has also helped many of them. (very simple solution)

Solution 3:

Remove all project reference and add them one by one. Recompile and done!

Solution 4:

Check if you are using old Ajax controls library. Make sure you use the latest one.

(Brian Chavez has posted a solution on this: Check here)

Solution 5:

Unloading a project that used Script#

(Brian Chavez has posted a solution on this: Check here)

Solution 6:

Unloading and re-loading the project. (very stupid, but works somehow)

Solution 7:

Adding new web.config file.

Just remove the old one and add a new one and then transfer your customizations (if any) to the new one from old one.

If you know more, then please comment.

28 Responses to “Solution: Invalid FORMATETC structure”

  1. 1
    Basangouda Says:

    Hi you saved my time. Good Solution.Thanks

  2. 2
    Dmitry Gusev Says:

    1. Exit VS 2. Delete *.suo file 3. Restart VS

  3. 3
    Jayvardhan Patil (Jay) Says:

    to Dmitry Gusev:Right said. This works too.

  4. 4
    MyViewState.NET | “The operation could not be completed. Invalid FORMATETC structure.” Says:

    [...] at one point or another. This error has popped up in numerous blogs and forum posts and there’s a list of solutions (and possible causes) which seems to work for most folks. Well, the bug still rears its ugly head [...]

  5. 5
    Joem Says:

    Solution 3.

    Check the version of the AjaxControlToolkit.dll in the /bin. In my case, I removed all the reference to ajaxtoolkit and delete the .dll. Add the new version of the toolkit.

    Aloha.

  6. 6
    Ozhan Karkukli Says:

    A solution:

    1. Put the control in an other project (class
    libary). We call this project X.
    2. Build project X.
    2. Set a reference to the project X.
    3. Open the page you want to use the control on it.
    4. You will see in the toolbox the control. Take this and drag to your form.

    this worked on a Windows XP, Visual Studio 2008 with a project that uses asp.net 3.5.

  7. 7
    Yuri Says:

    Yes. Thenproblem was that the files (folder of components) were moved..
    bst rgds.
    Yuri

  8. 8
    Claudio Friederich Says:

    In WebControls that are derived from others, no control in the inheritance chain is permitted 1) to have ToolBoxItem(False), or 2) be without a valid ToolBoxData attribute, otherwise the error occurs. This applies even to MustInherit/abstract controls. That last point is important. Note that abstract controls, due to their abstract nature, are automatically excluded from toolbox.

  9. 9
    Daniel Says:

    Reset tool box = WIN! Thanks, bud!

  10. 10
    Rahul Says:

    Thank u very much
    it worked

    Rahul

  11. 11
    alex clarke Says:

    This line is wrong
    [ToolboxData( "" )]

    This line is correct
    [ToolboxData( "" )]

    ‘server’ element in “runat=server” directive must be surrouned with quotation marks

  12. 12
    Corse Says:

    thank you! reset of toolbox solved this issue.

  13. 13
    Ruan Says:

    Thank you very much. Resetting the toolbox worked.

  14. 14
    Basem Says:

    In Team system 2008 looks like the VS can not somehow overwrite the web.config file .. so you need to manually add a couple of lines to your web.config … what are they ????
    simply do the following:
    1- create new local website.
    2-add report viewer component to the default page
    3- see the changes on the web.config file and add them to your original non-working website.

    PEACE ..

  15. 15
    Oliver Says:

    1. Right click on your project, Select “Clean”
    2. Right click on your project, Select “Build”

    Cheers.

  16. 16
    Damien Says:

    Hi there,

    For me it was the read-only attribute of my web.config file which was checked!

    It appears too when trying to add a user control from a non-standard library with a bad structured web.config (close tag not present for instance).

    The designer add automatically assembly dependancies in web.config and add the close tag on the same line after the last dependance. When deleting all dependances, I delete the close tag too… Oups! When I tried to add the user control (non-standard one) on my page, the error has thrown.

    Best wishes…

    Ciao

  17. 17
    MyViewState.NET | “The operation could not be completed. Invalid FORMATETC structure.” Says:

    [...] point or another. This error has popped up in numerous blogs and forum posts and there’s a list of solutions (and possible causes) which seems to work for most folks. Well, the bug still rears its ugly head [...]

  18. 18
    Obrienne Says:

    In my case, the error comes from web.config, for a extrange reason, when i drag and drop control, the vs2008 not add that lines to web.config.
    Solve, doing drag and drop in new proyect, and copy lines from new project(in web.config) to old and problematic web.config:
    “add this in that “

  19. 19
    Obrienne Says:

    Sorry, i forgot to tell, remember to add reference to the project.

  20. 20
    Aru Says:

    Solution 2 worked for me. Thanks.

  21. 21
    Oleg Says:

    Reset toolbox helps…

  22. 22
    Dani Says:

    Delete *.suo worked for me! Tks!

  23. 23
    rj Says:

    I renamed my web.config then created a new one. When I dragged the component it worked. Then I deleted the new web config and renamed my old to the original name. All things worked.

  24. 24
    TonyG Says:

    I tried most other solutions but eventually it was Solution #1 that worked: Don’t bother changing ToolboxItem to true or false, just remove that attribute. Thanks for this page!

  25. 25
    AM Says:

    Solution 9 worked for me, Visual Studio 2008 Pro, ASP.Net 3.5 – XP. Thanks

  26. 26
    Sumit Sinha Says:

    Thank you very much
    I was having the same issue but now it is resolved. I simply reset my toolbox and then again added the controls to new tab and then it was working fine

  27. 27
    unname Says:

    sometime Class Access Modifiers has to Private
    try change to Public

  28. 28
    Simon Says:

    My project was checked into source control (TFS), which caused all my non-checked out files to be locked. When I tried to add an Infragistics control I got the invalid FORMATETC message.

    After seeing your tip with web.config I realized that Infragistics probably needed to write to the web.config file but was unable to, since the file is write-protected while in source control. I checked out the file (which made it writable) and suddenly it worked. You may want to add a tip to Solution 7 that the file must be writable.

    Thanks!

Leave a Reply