<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code For Future &#187; ASP.NET</title>
	<atom:link href="http://codeforfuture.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeforfuture.com</link>
	<description>Share as you code.</description>
	<lastBuildDate>Sun, 18 Jul 2010 05:30:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solution: Invalid FORMATETC structure</title>
		<link>http://codeforfuture.com/2009/02/04/solution-invalid-formatetc-structure/</link>
		<comments>http://codeforfuture.com/2009/02/04/solution-invalid-formatetc-structure/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 14:25:00 +0000</pubDate>
		<dc:creator>Jayvardhan Patil</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MS.NET]]></category>

		<guid isPermaLink="false">http://codeforfuture.com/2009/02/04/solution-invalid-formatetc-structure/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>To my surprise, I was not able to do so and I got following error.</p>
<p><span style="font-weight: bold;">The operation could not be completed. Invalid FORMATETC structure </span></p>
<p>Many of you may also get a similar error:</p>
<p><span style="font-weight: bold;">Invalid FORMATETC structure (Exception from HRESULT: 0&#215;80040064 (DV_E_FORMATETC)) </span></p>
<p>After few hours extensive searching on net and trying out many solutions, I got to know few things.</p>
<p>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.</p>
<p>This makes you to try many solution. Unfortunately no solution listed on Internet worked for me and I was forced to find my own.</p>
<p>I&#8217;m listing my solution along with other solutions that may work.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>See Also:</strong>  <a href="http://codeforfuture.com/2009/04/19/mcts-70-630/" target="_blank">MCTS 70-630 all you need to know to clear this exam</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><span style="font-weight: bold;">I highly recommend to read all solutions and try the simpler ones first and then go for complex ones. This will save your day. </span></p>
<p><span style="font-weight: bold;">Solution 1: </span></p>
<p>ASP.NET 3.5</p>
<p>In my case I was using following hierarchy.</p>
<p>ASP.NET Button -&gt; ThemedButton -&gt; DesktopButton.</p>
<p>I didn&#8217;t wanted developers to start using ThemedButton so I don&#8217;t wanted to show it on toolbox.</p>
<p>So I put some attributes to it. Like below:</p>
<p>[DefaultProperty("Text"), ToolboxData("&lt;{0}:ThemedButton runat=server&gt;<!--{0}:ThemedButton-->"), ToolboxItem(false), DesignTimeVisible(false)]</p>
<p>I don&#8217;t know the root cause, but removing following piece of code worked for me.</p>
<p>ToolboxItem(false)</p>
<p><span style="font-weight: bold;">Solution 2: </span></p>
<p>Resetting toolbox items has also helped many of them. (very simple solution)</p>
<p><span style="font-weight: bold;">Solution 3: </span></p>
<p>Remove all project reference and add them one by one. Recompile and done!</p>
<p><span style="font-weight: bold;">Solution 4: </span></p>
<p>Check if you are using old Ajax controls library. Make sure you use the latest one.</p>
<p>(Brian Chavez has posted a solution on this: <a href="http://bchavez.bitarmory.com/archive/2008/01/23/invalid-formatetc-structure.aspx">Check here</a>)</p>
<p><span style="font-weight: bold;">Solution 5: </span></p>
<p>Unloading a project that used Script#</p>
<p>(Brian Chavez has posted a solution on this: <a href="http://bchavez.bitarmory.com/archive/2008/01/23/invalid-formatetc-structure.aspx">Check here</a>)</p>
<p><span style="font-weight: bold;">Solution 6: </span></p>
<p>Unloading and re-loading the project. (very stupid, but works somehow)</p>
<p><span style="font-weight: bold;">Solution 7: </span></p>
<p>Adding new web.config file.</p>
<p>Just remove the old one and add a new one and then transfer your customizations (if any) to the new one from old one.</p>
<p><span style="font-weight: bold;">If you know more, then please comment. </span></p>
]]></content:encoded>
			<wfw:commentRss>http://codeforfuture.com/2009/02/04/solution-invalid-formatetc-structure/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Collection was modified; enumeration operation may not execute</title>
		<link>http://codeforfuture.com/2008/12/01/collection-was-modified-enumeration-operation-may-not-execute/</link>
		<comments>http://codeforfuture.com/2008/12/01/collection-was-modified-enumeration-operation-may-not-execute/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 12:35:00 +0000</pubDate>
		<dc:creator>Jayvardhan Patil</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MS.NET]]></category>
		<category><![CDATA[reusable code]]></category>

		<guid isPermaLink="false">http://codeforfuture.com/2008/12/01/collection-was-modified-enumeration-operation-may-not-execute/</guid>
		<description><![CDATA[Collection was modified; enumeration operation may not execute
This exception is thrown when you are trying to delete items of a collection in a for loop or using a for each loop.
The ideal solution could be to use a for loop with a descending counter.
Problem:
for e.g. 
If suppose you are executing any of following code snippets
1.
for [...]]]></description>
			<content:encoded><![CDATA[<p>Collection was modified; enumeration operation may not execute</p>
<p>This exception is thrown when you are trying to delete items of a collection in a for loop or using a for each loop.</p>
<p>The ideal solution could be to use a for loop with a descending counter.</p>
<p>Problem:</p>
<p>for e.g. </p>
<p>If suppose you are executing any of following code snippets</p>
<p>1.</p>
<p>for (int listcounter = 0; listcounter < ReferenceOwnersList.Items.Count; listcounter++)<br />{<br /> ReferenceOwnersList.Items.Delete(0);<br />}</p>
<p>2.</p>
<p>foreach (SPListItem Li in ReferenceOwnersList.Items)<br />{<br /> Li.Delete();<br />}</p>
<p>Here ReferenceOwnersList is a collection.</p>
<p>Now whenever this code will execute for the first time, the number of items reduce. So the second item gets the first index.<br />I tried deleting 0th item everytime but still I got the exception. Again changing index may cause skipping the items in most senerios.</p>
<p>And the collection throws the &#8220;Collection was modified; enumeration operation may not execute&#8221; exception.</p>
<p>Solution:</p>
<p>Solution <br />Use a reducing for loop.</p>
<p>for (int cntLi = ReferenceOwnersList.Items.Count &#8211; 1; cntLi >=0 ;cntLi &#8212; )<br />{<br /> ReferenceOwnersList.Items.Delete(cntLi);<br />}</p>
<p>so that even if the last item is deleted, the index of other items wont change.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeforfuture.com/2008/12/01/collection-was-modified-enumeration-operation-may-not-execute/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.NET Dynamic controls: Twice click problem</title>
		<link>http://codeforfuture.com/2008/06/25/aspnet-dynamic-controls-twice-click-problem/</link>
		<comments>http://codeforfuture.com/2008/06/25/aspnet-dynamic-controls-twice-click-problem/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 13:17:00 +0000</pubDate>
		<dc:creator>Jayvardhan Patil</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MS.NET]]></category>

		<guid isPermaLink="false">http://codeforfuture.com/2008/06/25/aspnet-dynamic-controls-twice-click-problem/</guid>
		<description><![CDATA[

Sometimes, you need to click twice for the dynamic control to work.
Symptoms:
1. Your dynamic controls get loaded
2. You click on the button/other control
3. The page simply refreshes and no code is executed.
4. You try to debug the “onclick” method, but no break point is hit.
5. Next time when you hit the button, everything works properly.
Solution:
After [...]]]></description>
			<content:encoded><![CDATA[<div class="entry">
<div class="snap_preview">
<p>Sometimes, you need to click twice for the dynamic control to work.</p>
<p>Symptoms:</p>
<p>1. Your dynamic controls get loaded</p>
<p>2. You click on the button/other control</p>
<p>3. The page simply refreshes and no code is executed.</p>
<p>4. You try to debug the “onclick” method, but no break point is hit.</p>
<p>5. Next time when you hit the button, everything works properly.</p>
<p>Solution:</p>
<p>After creating the control, simply assign some id to it.</p>
<p>e.g.</p>
<p>myControl.id = “thisID”;</p>
<p>Somehow this is needed by the internal .NET code, so for the first time the click doesn’t work, but when you click next time, the id has already been generated, so the code works normally.</p>
</p></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://codeforfuture.com/2008/06/25/aspnet-dynamic-controls-twice-click-problem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
