<?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>Factory Automation Software Blog &#187; .NET Framework Development</title>
	<atom:link href="http://factoryswblog.org/category/development-techniques/dotnet-dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://factoryswblog.org</link>
	<description>Merging modern software development with electrons and metal</description>
	<lastBuildDate>Wed, 09 May 2012 00:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Compiling Code for Visual Studio 2003 Without VS2003</title>
		<link>http://factoryswblog.org/2011/09/02/compiling-code-for-vs-2003-free/</link>
		<comments>http://factoryswblog.org/2011/09/02/compiling-code-for-vs-2003-free/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 20:04:46 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[.NET Framework Development]]></category>
		<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharpDvelop]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://factoryswblog.org/?p=974</guid>
		<description><![CDATA[I used SharpDevelop 2.2 to compile VS2003 code for .NET 1.1]]></description>
			<content:encoded><![CDATA[<p>Recently, I needed to compile some code for Visual Studio 2003, which I don&#8217;t have (I have VS 2002 and VS 2005).</p>
<p>The obvious approach is to convert the project to VS 2005, which uses .NET 2.0.  However, I wanted to compile to .NET 1.1 for various reasons, and VS2005 does not allow this out of the box.</p>
<p>The first approach I tried was using the <a href="http://www.codeplex.com/wikipage?ProjectName=MSBee">MSBee</a> program.  MSBee is a program for MSBuild to allow compiling a program in VS 2005 to .NET 1.1.  MSBee requires modifying the project file, and has to be run from the command line.  I gave it a try, and it gave me a lot of errors.</p>
<p>I probably could have figured out those MSBuild errors, but I found a better solution: <a href="http://sharpdevelop.net/opensource/sd/download/">SharpDevelop 2.2</a>.  SharpDevelop typically allows you to compile to either the current .NET version or the previous one.  So SharpDevelop 2.2 can target either .NET 2.0 or .NET 1.1 &#8212; and it can read and convert VS 2003 project files.</p>
<p>Sharp Develop read my VS 2003 solution files without a problem, and I went to the Project menu, selected Project Options, clicked on the Compiling tab, and set the Target Framework to .NET Framework 1.1.  Success!</p>
 <img src="http://factoryswblog.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=974" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://factoryswblog.org/2011/09/02/compiling-code-for-vs-2003-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There&#8217;s No Substitute For The Real (.NET) Thing</title>
		<link>http://factoryswblog.org/2010/11/20/theres-no-substitute-for-the-real-net-thing/</link>
		<comments>http://factoryswblog.org/2010/11/20/theres-no-substitute-for-the-real-net-thing/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 05:37:22 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[.NET Framework Development]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://factoryswblog.org/?p=705</guid>
		<description><![CDATA[Sometimes the .NET Framework's backwards compatibility doesn't work -- you have to the older version installed]]></description>
			<content:encoded><![CDATA[<p>Sometimes, the .NET framework&#8217;s backwards compatibility doesn&#8217;t work, and you have to install the exact version required by an assembly.</p>
<p>Recently, I was working on a project that used a number of components compiled for .NET 1.1 (I didn&#8217;t have the source code) &#8212; and, since I strongly prefer Visual Studio 2005 over the earlier versions, I was writing my test code in VS 2005, which installed .NET 2.0 only on the computer.</p>
<p>The result?  No obvious error messages from .NET (which I would&#8217;ve expected if there were version incompatibilities), but the .NET Remoting portion did not work.  The only error message was about being unable to serialize an object.</p>
<p>The solution?  I installed the .NET framework V1.1, and the Remoting (and serialization) problems went away.</p>
 <img src="http://factoryswblog.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=705" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://factoryswblog.org/2010/11/20/theres-no-substitute-for-the-real-net-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Case of the Disappearing Exception</title>
		<link>http://factoryswblog.org/2008/06/24/case-disappearing-exception/</link>
		<comments>http://factoryswblog.org/2008/06/24/case-disappearing-exception/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 19:07:03 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[.NET Framework Development]]></category>
		<category><![CDATA[Exceptions]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://factoryswblog.org/?p=57</guid>
		<description><![CDATA[I was doing some debugging recently on an inherited Visual Basic.NET codebase. Something odd was going on &#8211; the code that reads a PLC&#8217;s input was always returning True, but I could see the input changing. The problem? The original programmer, who I&#8217;ll call &#8220;Bugs Bunny&#8221;, didn&#8217;t understand exception handling at all. The function, part [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some debugging recently on an inherited Visual Basic.NET codebase.  Something odd was going on &#8211; the code that reads a PLC&#8217;s input was always returning True, but I could see the input changing.  The problem?  The original programmer, who I&#8217;ll call &#8220;Bugs Bunny&#8221;, didn&#8217;t understand exception handling at all.</p>
<p>The function, part of a class that communicated with a PLC, went roughly like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://factoryswblog.org/wp-content/plugins/wp-codebox/wp-codebox.php?p=57&amp;download=Disappearing-Exception.vb">Disappearing-Exception.vb</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p573"><td class="code" id="p57code3"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Function</span> bubba<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span>
    bubba <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
    <span style="color: #0600FF;">Try</span>
        bubba <span style="color: #008000;">=</span> getResultFromPlc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
        logException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></td></tr></table></div>

<p>Since all Exceptions are caught and <strong>not handled</strong> any Exceptions raised in bubba()&#8217;s Try block just disappear.  So all the code calling bubba() has no way of knowing if there are problem (such as the PLC isn&#8217;t powered or the serial port isn&#8217;t connected) .  Instead, because the return value is initially set to True (<em>bubba = True</em>), if an Exception occurs, bubba() always return True.</p>
<p>Sometimes you do need to ignore Exceptions.  For example, on a maintenance screen that repeatedly reads a PLC&#8217;s inputs, it&#8217;s good to indicate if there are any problems reading the inputs, but it&#8217;s not helpful to pop up a dialog box or exit the maintenance screen.  Exceptions should be ignored occasionally as needed in the calling code, not completely swallowed up in the base library code.</p>
<p>Another common anti-pattern in Bug&#8217;s code is:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://factoryswblog.org/wp-content/plugins/wp-codebox/wp-codebox.php?p=57&amp;download=Useless_try-catch.vb">Useless_try-catch.vb</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p574"><td class="code" id="p57code4"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Sub</span> joe<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Try</span>
        blah<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        blahblah<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
        logException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Throw</span> ex
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">Sub</span> groovy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Try</span>
        joe<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
        logException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Throw</span> ex
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p>What&#8217;s the point?  All that happens is the exception gets logged multiple times (adding confusion to the log file), more useless code is added (making the code harder to understand), and the program runs slower (throw, catching, and re-throwing Exceptions takes time).</p>
<p><em>Tony</em></p>
 <img src="http://factoryswblog.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=57" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://factoryswblog.org/2008/06/24/case-disappearing-exception/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Write Microsoft .NET code faster with Boo</title>
		<link>http://factoryswblog.org/2007/09/26/write-microsoft-net-code-faster-with-boo/</link>
		<comments>http://factoryswblog.org/2007/09/26/write-microsoft-net-code-faster-with-boo/#comments</comments>
		<pubDate>Thu, 27 Sep 2007 04:23:40 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[.NET Framework Development]]></category>
		<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[Boo Language]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://factoryswblog.org/2007/09/26/write-microsoft-net-code-faster-with-boo/</guid>
		<description><![CDATA[Why use a .NET language with interactive command line]]></description>
			<content:encoded><![CDATA[<p>even if you&#8217;re using C# or VB.NET.  How?  By using <a href="http://boo.codehaus.org/">Boo&#8217;s</a> interpreter to try out ideas, test usage of .NET framework functions, and interact with components (COM, .NET).  Then when you&#8217;re comfortable, you can write the polished code in the language of your choice.</p>
<p>This is one use for mixed language programming, mentioned by me <a href="http://factoryswblog.org/2007/06/21/software-development-trends/">here</a>, but where the final software might not use both languages.</p>
<p>In fact, any .NET interpreter such as IronPython or IronRuby could be used.  And it&#8217;s a great technique for other than .NET &#8211; I&#8217;ve used it a lot with Python on Win32, and you can use it in Java with JRuby, Jython, Groovy, etc. This approach could be very useful for embedded and factory software development.</p>
<p>On .NET IronPython and IronRuby have advantages because they&#8217;re official Microsoft languages (and IP has a book coming out &#8211; <a href="http://www.manning.com/foord/">IronPython In Action</a>) and the languages are already in wide use (Win32, *nix, Java).  I&#8217;m using Boo because it comes with the open source <a href="http://sharpdevelop.net/OpenSource/SD/Default.aspx">SharpDevelop IDE</a>, and right now it integrates better with .NET (IP does not support attributes well, and it&#8217;s not easy to make an IP assembly callable by other .NET languages, etc).</p>
<p>Short example &#8211; interactively using DirectoryInfo in Boo (text I typed in bold):</p>
<p>&gt;&gt;&gt; <strong>di = DirectoryInfo(&#8220;C:\\Download&#8221;)</strong><br />
C:\Download<br />
&gt;&gt;&gt; <strong>files = di.GetFiles()</strong><br />
(AdbeRdr80_en_US.exe, AdbeRdr80_en_US_Nosso_error.log, Firefox Setup 2.0.0.1.exe, SharpDevelop_2.2.1.2648_Setup.msi, TortoiseSVN-1.4.3.8645-win32-svn-1.4.3.msi)<br />
&gt;&gt;&gt; <strong>files = di.GetFiles(&#8216;t*&#8217;)</strong><br />
(TortoiseSVN-1.4.3.8645-win32-svn-1.4.3.msi)</p>
<p>Interactively calling a COM object in Boo:</p>
<p>&gt;&gt;&gt; <strong>ieType = System.Type.GetTypeFromProgID(&#8216;InternetExplorer.Application&#8217;)</strong><br />
System.__ComObject<br />
&gt;&gt;&gt;<strong> ie = System.Activator.CreateInstance(ieType)</strong><br />
System.__ComObject<br />
&gt;&gt;&gt; <strong>ie.Visible</strong><br />
false<br />
&gt;&gt;&gt; <strong>ie.Visible = true</strong><br />
true<br />
&gt;&gt;&gt; <strong>ie.Visible</strong><br />
true</p>
<p>So far I haven&#8217;t had to use InvokeMember to call COM functions.  At least for C# and VB.NET (and probably Boo) it appears you need to use it if you are using late binding.  BTW, it is possible to use late binding with COM events, but it is significant extra work.</p>
<p><em>Tony</em></p>
 <img src="http://factoryswblog.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=26" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://factoryswblog.org/2007/09/26/write-microsoft-net-code-faster-with-boo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

