<?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>voyce &#187; visualstudio</title>
	<atom:link href="http://www.voyce.com/index.php/tag/visualstudio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:56:45 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FormatException in WPF DataBinding</title>
		<link>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/</link>
		<comments>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 11:09:26 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[FormatException]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=446</guid>
		<description><![CDATA[A FormatException is generated by the WPF DataBinding diagnostics if the original exception text contains curly brackets.]]></description>
			<content:encoded><![CDATA[<p>While working on some F#/C# WPF code the other day, I kept hitting a fatal FormatException when running under the debugger. Annoyingly, the app would quit with:<br />
<code><br />
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll<br />
Additional information: Input string was not in a correct format.<br />
</code><br />
But it worked fine when started from Expression Blend, or when run using Start Without Debugging in Visual Studio. Let&#8217;s take a closer look&#8230;<br />
<span id="more-446"></span><br />
Looking at the output window, there seemed to be an intial exception before the FormatException, and from the stack trace the second one seemed to be generated as WPF was trying to log the first one:</p>
<p><a href="http://72.47.193.211/wp-content/uploads/2009/10/callstack.png"><img src="http://www.voyce.com/wp-content/uploads/2009/10/callstack-300x113.png" alt="callstack" title="callstack" width="300" height="113" class="size-medium wp-image-449" /></a></p>
<p>I had a look at the text of the first exception, and from that it was obvious:</p>
<p><code><br />
Unable to cast COM object of type 'System.__ComObject' to interface type 'IWhatever'. This operation failed because the QueryInterface call on the COM component for the interface with IID '<b>{</b>CAD939D0-5E5D-11D7-AA0B-0002B33FE9DX<b>}</b>' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).<br />
</code></p>
<p>The message contains curly brackets around the IID, and they&#8217;re being intrepreted as insertion points by a call to String.Format!</p>
<h2>Workaround</h2>
<p>So that explained why it only happens in debugger runs; as <a href="http://blogs.msdn.com/mikehillberg/archive/2006/09/14/WpfTraceSources.aspx">this post</a> helpfully points out the WPF databinding is enabled by default in that case. To workaround it, you can disable logging programmatically or using the App.config file to only display <code>Critical</code> output. So if your app is named foo.exe, create a file foo.exe.config that contains:</p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &lt;</span><span style="color: #a31515;">system.diagnostics</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;</span><span style="color: #a31515;">sources</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &nbsp; &lt;</span><span style="color: #a31515;">source</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">System.Windows.Data</span>"<span style="color: blue;"> </span><span style="color: red;">switchName</span><span style="color: blue;">=</span>"<span style="color: blue;">SourceSwitch</span>"<span style="color: blue;">/&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;/</span><span style="color: #a31515;">sources</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;</span><span style="color: #a31515;">switches</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &nbsp; &lt;</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SourceSwitch</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Critical</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;/</span><span style="color: #a31515;">switches</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &lt;/</span><span style="color: #a31515;">system.diagnostics</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
</div>
<h2>Fix&#8230;?</h2>
<p>Hopefully there&#8217;ll be a fix for this at some point soon, as disabling the logging is a pretty large hammer to crack this small nut.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>F# CTP and Visual Studio integration</title>
		<link>http://www.voyce.com/index.php/2009/01/19/f-ctp-and-visual-studio-integration/</link>
		<comments>http://www.voyce.com/index.php/2009/01/19/f-ctp-and-visual-studio-integration/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 13:41:46 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[ctp]]></category>
		<category><![CDATA[targetpath]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[vs]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=64</guid>
		<description><![CDATA[Just a quick note on an inconsistency in the F# 1.9.6.2 (CTP) release and it&#8217;s integration into Visual Studio: be aware that the standard VS environment variable $(TargetPath) is not getting set to what you&#8217;d expect. Rather than containing the full path to the output file it references the intermediate file typically in \obj\bin.
This can [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note on an inconsistency in the F# 1.9.6.2 (CTP) release and it&#8217;s integration into Visual Studio: be aware that the standard VS environment variable <code>$(TargetPath)</code> is not getting set to what you&#8217;d expect. Rather than containing the full path to the output file it references the intermediate file typically in \obj\bin.</p>
<p>This can be a problem if you&#8217;ve got any tools set-up that try and do something with the built binary. Normally you can assume that referenced assemblies will also be in that directory, so you&#8217;d be able to load and execute your built file. If you&#8217;re pointing to a copy in the intermediate directory, that&#8217;s not the case.</p>
<p>It looks like it&#8217;s just an artifact of the way they&#8217;ve integrated the F# compiler (fsc.exe) with msbuild. The F# team are aware of this bug, so hopefully it&#8217;ll be fixed in the next drop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/01/19/f-ctp-and-visual-studio-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
