<?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>marthijn. &#187; Windows</title>
	<atom:link href="http://www.marthijnvandenheuvel.com/category/software/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marthijnvandenheuvel.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Dec 2011 13:03:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fix .NET 4 SocketPermission for MySQL driver in Medium Trust</title>
		<link>http://www.marthijnvandenheuvel.com/2011/04/14/fix-net-4-socketpermission-for-mysql-driver-in-medium-trust/</link>
		<comments>http://www.marthijnvandenheuvel.com/2011/04/14/fix-net-4-socketpermission-for-mysql-driver-in-medium-trust/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 18:57:38 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SocketPermission]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=328</guid>
		<description><![CDATA[Most .NET 4 shared hosting providers offering their customers a medium trust environment. This is not a problem for most web applications unless the applications uses MySQL in combination with the .NET MySQL driver (MySQL.Data.dll). The MySQL driver connects to the MySQL database using a socket. However, sockets are not allowed in medium trust. The [...]]]></description>
			<content:encoded><![CDATA[<p>Most .NET 4 shared hosting providers offering their customers a medium trust environment. This is not a problem for most web applications unless the applications uses MySQL in combination with the .NET MySQL driver (<a href="http://dev.mysql.com/downloads/connector/net/" target="_blank">MySQL.Data.dll</a>). The MySQL driver connects to the MySQL database using a socket. However, sockets are not allowed in medium trust. The application will throw a SecurityException with the following message:</p>
<pre><code>Request for the permission of type 'System.Net.SocketPermission,  System, Version=4.0.0.0, Culture=neutral,  PublicKeyToken=b77a5c561934e089' failed.</code></pre>
<p><span id="more-328"></span><br />
In order to fix this there are three solutions:</p>
<p>1. Instead of MySQL, use Microsoft SQL server.</p>
<p>2. Move to a hosting provider that supports a full trust environment or get your own server.</p>
<p>3. Ask your hosting provider to update the medium trust policy with SocketPermission. The steps will be explained here:</p>
<p>Open the following file in a text editor:</p>
<pre>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web_mediumtrust.config</pre>
<p>Or when you are running 64 bit:</p>
<pre>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web_mediumtrust.config</pre>
<p>Inside the SecurityClasses tag, add the following line:</p>
<pre><code>&lt;SecurityClass Name="SocketPermission" Description="System.Net.SocketPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/&gt;</code></pre>
<p>Scroll down and look for the following PermissionSet:</p>
<pre>&lt;PermissionSet version="1" Name="ASP.Net"&gt;</pre>
<p>Add the following inside this PermissionSet:</p>
<pre><code>&lt;IPermission class="SocketPermission" version="1" Unrestricted="true" /&gt;
</code></pre>
<p>That&#8217;s all, a restart of IIS is, as far as I know, not necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2011/04/14/fix-net-4-socketpermission-for-mysql-driver-in-medium-trust/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Possible solution for NHibernate many-to-many criteria</title>
		<link>http://www.marthijnvandenheuvel.com/2011/01/07/possible-solution-for-nhibernate-many-to-many-criteria/</link>
		<comments>http://www.marthijnvandenheuvel.com/2011/01/07/possible-solution-for-nhibernate-many-to-many-criteria/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 10:44:12 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=299</guid>
		<description><![CDATA[How to query an NHibernate many-to-many relationship.]]></description>
			<content:encoded><![CDATA[<p>In one of my .NET projects I&#8217;m using the <a href="http://nhforge.org/" target="_blank">NHibernate</a> library for object-relational mapping. I&#8217;m mainly using the ICriteria interface to fetch data from the database. Unfortunately I ran into a function that got really complicated; how to query a many-to-many relationship. For example, I have a table containing posts and a table containing tags. The post datamodel contains a set with tags so in my mapping it&#8217;s a many-to-many relationship. I want my query to return all posts tagged with one or more specific tags. On <a href="http://forum.castleproject.org/viewtopic.php?p=15157" target="_blank">this forum</a> I found a solution. I&#8217;m not sure if this is the perfect solution, so feel free to suggest a better one.<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> IList<span style="color: #008000;">&lt;</span>Post<span style="color: #008000;">&gt;</span> GetPostsByTags<span style="color: #008000;">&#40;</span>IList<span style="color: #008000;">&lt;</span>Tag<span style="color: #008000;">&gt;</span> tags<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
 ICriteria posts <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Session</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCriteria</span><span style="color: #008000;">&lt;</span>Post<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Tag t <span style="color: #0600FF; font-weight: bold;">in</span> tags<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  posts<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>Subqueries<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>DetachedCriteria<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">For</span><span style="color: #008000;">&lt;</span>Post<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;p2&quot;</span><span style="color: #008000;">&#41;</span>
   <span style="color: #008000;">.</span><span style="color: #0000FF;">SetProjection</span><span style="color: #008000;">&#40;</span>Projections<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
   <span style="color: #008000;">.</span><span style="color: #0000FF;">CreateAlias</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;p2.Tags&quot;</span>, <span style="color: #666666;">&quot;t&quot;</span><span style="color: #008000;">&#41;</span>
   <span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>Restrictions<span style="color: #008000;">.</span><span style="color: #0000FF;">Eq</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;t.Id&quot;</span>, t<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
   <span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>Restrictions<span style="color: #008000;">.</span><span style="color: #0000FF;">EqProperty</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;p2.Id&quot;</span>, <span style="color: #666666;">&quot;this.Id&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
 posts<span style="color: #008000;">.</span><span style="color: #0000FF;">SetResultTransformer</span><span style="color: #008000;">&#40;</span>NHibernate<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transformers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DistinctRootEntity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">return</span> posts<span style="color: #008000;">.</span><span style="color: #0000FF;">List</span><span style="color: #008000;">&lt;</span>Post<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2011/01/07/possible-solution-for-nhibernate-many-to-many-criteria/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using log4net to show NHibernate SQL in Visual Studio</title>
		<link>http://www.marthijnvandenheuvel.com/2010/12/02/using-log4net-to-show-nhibernate-sql-in-visual-studio/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/12/02/using-log4net-to-show-nhibernate-sql-in-visual-studio/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 10:15:28 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[log4net]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=292</guid>
		<description><![CDATA[Configure log4net in order to show NHibernate SQL queries in Visual Studio's console.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently developing a web application in <a href="http://www.asp.net/mvc" target="_blank">ASP.NET MVC</a> and <a href="http://nhforge.org/" target="_blank">NHibernate</a>. Since the application was very slow at some points I wanted to know which SQL queries NHibernate was executing. Since the <a href="http://logging.apache.org/log4net/index.html" target="_blank">log4net</a> library was already included in the application I searched for a solution to output the SQL queries to the console in Visual Studio 2010 using log4net. I found the solution on <a href="http://nhforge.org/wikis/howtonh/configure-log4net-for-use-with-nhibernate.aspx" target="_blank">this wiki</a> and <a href="http://www.davesquared.net/2008/01/viewing-sql-generated-by-nhibernate.html" target="_blank">this blog post</a>.</p>
<p><span id="more-292"></span>First thing you need to do is add a log4net section in your web.config if you don&#8217;t have one yet.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configSections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 ...
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;log4net&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Config.Log4NetConfigurationSectionHandler,log4net&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configSections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then add the log4net section, and configure an appender and logger.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;log4net<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DebugSQL&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Appender.TraceAppender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;log4net.Layout.PatternLayout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conversionPattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;%date [%thread] %-5level %logger [%property{NDC}] - %message%newline&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logger</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NHibernate.SQL&quot;</span> <span style="color: #000066;">additivity</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;level</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;DEBUG&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender-ref</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;DebugSQL&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/logger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/log4net<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That&#8217;s all. Don&#8217;t forget to configure log4net in the Global.asax.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
 log4net<span style="color: #008000;">.</span><span style="color: #0000FF;">Config</span><span style="color: #008000;">.</span><span style="color: #0000FF;">XmlConfigurator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Configure</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">...</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/12/02/using-log4net-to-show-nhibernate-sql-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to lookup MIDI notes of your MIDI controller</title>
		<link>http://www.marthijnvandenheuvel.com/2010/11/01/how-to-lookup-midi-notes-of-your-midi-controller/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/11/01/how-to-lookup-midi-notes-of-your-midi-controller/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 14:10:33 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Digital Jockey 2]]></category>
		<category><![CDATA[Midi controller]]></category>
		<category><![CDATA[Midi mapping]]></category>
		<category><![CDATA[Midi-ox]]></category>
		<category><![CDATA[Reloop]]></category>
		<category><![CDATA[Traktor]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=280</guid>
		<description><![CDATA[How to lookup MIDI note and channel information of a MIDI controller using MIDI-OX.]]></description>
			<content:encoded><![CDATA[<p>Last week I helped <a href="http://www.basvandijk.eu/" target="_blank">Bas</a> verifying his <a href="http://www.basvandijk.eu/2010/10/30/reloop-digital-jockey-2-midi-layout-overview/" target="_blank">MIDI layout of the Reloop Digital Jockey 2</a> interface and controller edition. I used a program for Windows called <a href="http://www.midiox.com/" target="_blank">MIDI-OX</a>, a diagnostic tool for the <a href="http://en.wikipedia.org/wiki/Musical_Instrument_Digital_Interface" target="_blank">MIDI protocol</a>, to do this. In order to lookup the MIDI information sent by your MIDI controller turn on your device, start MIDI-OX and go to Options â†’ MIDI Devices.</p>
<p><span id="more-280"></span>In this window select your MIDI Controller inputs in the MIDI Inputs list. Press Ok and go to View â†’ Input Monitor to view the MIDI input of your controller.</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/11/pcr_midiox.png" rel="lightbox[280]"><img class="aligncenter size-medium wp-image-282" title="MIDI-OX Input Monitor" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/11/pcr_midiox-300x240.png" alt="" width="300" height="240" /></a></p>
<p>For all buttons and keys on your controller the MIDI note is listed in the NOTE column. Unfortunately when using the knobs and sliders on my Digital Jockey 2 no information was shown about the channel used. Please post a comment if you know how to extract this information or if there are better tools to view MIDI data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/11/01/how-to-lookup-midi-notes-of-your-midi-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to stop Traktor from editing ID3 tags</title>
		<link>http://www.marthijnvandenheuvel.com/2010/10/11/how-to-stop-traktor-from-editing-id3-tags/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/10/11/how-to-stop-traktor-from-editing-id3-tags/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 22:01:45 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[ID3 Tags]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[Traktor]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=266</guid>
		<description><![CDATA[How to run Traktor as a different user so it has no permission to modify music files.]]></description>
			<content:encoded><![CDATA[<p>A few days ago I was trying a demo version of <a href="http://www.native-instruments.com/#/en/products/dj/traktor-pro/" target="_blank">Traktor Pro</a>. When playing some tracks I discovered the ID3 tags were missing when viewing the files in Windows Explorer. According to <a href="http://www.native-instruments.com/forum/showthread.php?t=119173" target="_blank">this topic</a> Traktor changes the ID3 tags from version 2.3 to version 2.4 which can&#8217;t be read by Windows 7, so it&#8217;s not really a bug but rather annoying. In this post I&#8217;ll describe how to run Traktor as a different user in Windows 7 so it has no permissions to modify files any more. This solution is mentioned in <a href="http://www.native-instruments.com/forum/showthread.php?t=115804" target="_blank">this topic</a>.</p>
<p><span id="more-266"></span>The first thing to do is create a new user.Â  Go to Start and click with the right mouse button on Computer and choose Manage from the submenu. In the left column choose Local Users and Groups and open the Users folder. Now create a new user (Action â†’ New User or right mouse button â†’ New User):</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/traktor_adduser.png" rel="lightbox[266]"><img class="aligncenter size-medium wp-image-267" title="Add user" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/traktor_adduser-300x298.png" alt="" width="300" height="298" /></a></p>
<p>Click Create and close the window. The next thing to do is change the permission of your music folder:</p>
<ol>
<li>Open Properties of your music folder</li>
<li>Open the Security tab and press the Edit button</li>
<li>In the Permissions window, choose Add</li>
<li>Enter the name of your Traktor user and press OK</li>
<li>Make sure the Traktor user is selected and in the permissions list check Deny for the Write permission</li>
</ol>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/traktor_permissions.png" rel="lightbox[266]"><img class="aligncenter size-medium wp-image-268" title="Folder permissions" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/traktor_permissions-248x300.png" alt="" width="248" height="300" /></a></p>
<p>The final step is running Traktor as the newly created user. To do so go to Start and navigate to the Traktor shortcut. Now hold Shift and right click on the shortcut. Choose Run as different user and enter the Trakor user credentials. Since you start Traktor using a different user you need to reconfigure the application, but Traktor has no permission to modify your files any more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/10/11/how-to-stop-traktor-from-editing-id3-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with LaTeX and BibTeX in LEd</title>
		<link>http://www.marthijnvandenheuvel.com/2010/10/05/getting-started-with-latex-and-bibtex-in-led/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/10/05/getting-started-with-latex-and-bibtex-in-led/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 14:56:50 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[LaTeX]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=252</guid>
		<description><![CDATA[A simple tutorial about LaTeX and BibTeX in the editor LEd.]]></description>
			<content:encoded><![CDATA[<p>Recently I started writing a simple paper in <a href="http://en.wikipedia.org/wiki/LaTeX" target="_blank">LaTeX</a>. Since I was only used to editors like Word and OpenOffice writing in LaTeX was completely different. In this post I&#8217;ll describe how to get started with LaTeX and <a href="http://www.bibtex.org/" target="_blank">BibTeX</a> in a simple and free LaTeX editor for Windows called <a href="http://www.latexeditor.org/" target="_blank">LEd</a>. First of all, download LEd <a href="http://www.latexeditor.org/download_main.html" target="_blank">here</a> and install it on your system. Make sure you install <a href="http://miktex.org/" target="_blank">MiKTeX</a>, a Windows implementation of <a href="http://en.wikipedia.org/wiki/TeX" target="_blank">Tex</a>, as well if you not already have it.</p>
<p><span id="more-252"></span>Now startup LEd. In order to create a new paper go to File â†’ New and on the Template tab choose Paper. In the file tree, open your .tex file. You will see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #E02020; ">\</span><span style="color: #800000;">documentclass</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">title</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">...</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">author</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">...</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">date</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">...</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">maketitle</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">section</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">...</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">section</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">...</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span></pre></div></div>

<p>You can change the dots for anything you like and add text under the \section tags:</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #E02020; ">\</span><span style="color: #800000;">section</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Introduction</span><span style="color: #E02020; ">}</span>
Lorem ipsum dolor sit amet...</pre></div></div>

<p>Now it&#8217;s time to compile the LaTeX document; press the green arrow button in the toolbar or F9. Press the blue arrow or F7 to create a PDF file (the file is stored in the same folder as your .tex file):</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/latex_testpaper.png" rel="lightbox[252]"><img class="aligncenter size-medium wp-image-254" title="Test paper" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/latex_testpaper-231x300.png" alt="" width="231" height="300" /></a></p>
<p>In scientific papers it&#8217;s quite common to refer to other papers. In order to manage this we use BibTeX. First create a .bib file adding a new file to the project: File â†’ New and choose &#8220;Bibliography file in BibTeX format&#8221;. Name the file for example mybib and make sure to add it to the right project. Add the following example text to your .bib file:</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;">@article<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">miles09,
 author = {Richard Miles</span><span style="color: #E02020; ">}</span>,
 title = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Who is John Doe?</span><span style="color: #E02020; ">}</span>,
 year = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">2009</span><span style="color: #E02020; ">}</span>,
 journal = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">The Unknown Magazine</span><span style="color: #E02020; ">}</span>,
 volume = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">1</span><span style="color: #E02020; ">}</span>,
 number = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">1</span><span style="color: #E02020; ">}</span>,
 pages = <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">20--42</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">}</span></pre></div></div>

<p>In your .tex file, add the following commands before the \end{document} tag to enable the bibliography:</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\bibliographystyle</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">plain</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\bibliography</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">mybib</span><span style="color: #E02020; ">}</span></pre></div></div>

<p>Now if you want to cite something simply type \cite and a window will popup containing all the entries in your bibliography:</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. <span style="color: #E02020; ">\</span><span style="color: #800000;">cite</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">miles09</span><span style="color: #E02020; ">}</span></pre></div></div>

<p>Compile the bibliography file by pressing the blue book icon or F6. Then compile your LaTeX file and create a PDF. As you can see the bibliography is included in your document:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/latex_testpaperbib.png" rel="lightbox[252]"><img class="aligncenter size-medium wp-image-255" title="Test paper bibliography" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/10/latex_testpaperbib-231x300.png" alt="" width="231" height="300" /></a></p>
<p>That&#8217;s all for now, for more information about the BibTeX format see <a href="http://www.bibtex.org/Format/" target="_blank">this</a> page. Enjoy LaTeX!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/10/05/getting-started-with-latex-and-bibtex-in-led/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using NUnit in Visual Studio 2010</title>
		<link>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:13:10 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=196</guid>
		<description><![CDATA[How to use NUnit in Visual Studio 2010.]]></description>
			<content:encoded><![CDATA[<p>Like in older versions of <a href="http://www.microsoft.com/visualstudio" target="_blank">Visual Studio</a> it is possible to use <a href="http://www.nunit.org" target="_blank">NUnit</a> as an external tool in the new 2010 version. By creating a toolbar as well it is very easy to run your test suite. The usual way to add an external command is by clicking the menu Tools -&gt; External Tools. However, by default this menu item is not visible. To enable this menu item go to Tools -&gt; Settings -&gt; Expert Settings.</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-197" title="Visual Studio 2010" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" alt="Visual Studio 2010" width="214" height="32" /></a></p>
<p><span id="more-196"></span></p>
<p>The first step is download and install the latest version of NUnit since older versions are not compatible with .NET 4. NUnit version 2.5.5 can be downloaded <a href="http://www.nunit.org/?p=download" target="_blank">here</a>.</p>
<p>Now go to Tools -&gt; External Tools:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-198" title="Visual Studio 2010 External Tools" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" alt="Visual Studio 2010 External Tools" width="493" height="481" /></a></p>
<p>I think this screen shot explains itself very well. Now its possible to add this external command to a tool bar. To do so go to View -&gt; Toolbars -&gt; Customize:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-200" title="Visual Studio 2010 Customize Toolbars" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" alt="Visual Studio 2010 Customize Toolbars" width="465" height="509" /></a></p>
<p>Press the New button and enter a name. Now open the Commands tab and add the external command (usually External Command 1 when you don&#8217;t have any other external commands) to the toolbar:</p>
<p style="text-align: center;"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-202" title="Visual Studio 2010 Commands" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" alt="Visual Studio 2010 Toolbars" width="801" height="529" /></a></p>
<p style="text-align: left;">When clicking the NUnit button in the new toolbar the NUnit GUI starts and loads your test suite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Type conversion in C#</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 11:17:17 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Type conversion]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=122</guid>
		<description><![CDATA[Type conversion in C#]]></description>
			<content:encoded><![CDATA[<p>Type conversion (or typecasting) is the technique to change an entity from one data type into another. In general there are two types of type conversion; implicit and explicit conversion. This post tells about type conversion in C#.NET and the performance issues.</p>
<h2>Implicit conversion</h2>
<p>Implicit conversion (or coercion) is automatic type conversion by the compiler. In C# it does not require a special syntax because the type conversion is safe and no data will be lost. In the following example the value of an integer is stored in a long. This is safe because an integer is 4 bytes (on a 32 bit computer), and a long is 8 bytes. So every value that fits in an integer fits in a long. For a complete conversion table see <a href="http://msdn.microsoft.com/en-us/library/y5b434w4.aspx" target="_blank">this page</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">12345678</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">long</span> l <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></pre></div></div>

<p>It is also possible to cast a derived class to a base class without using a special syntax.<br />
<span id="more-122"></span></p>
<h2>Explicit conversion</h2>
<p>Instead of implicit conversion explicit conversion (or casting) is not done by the compiler. It is explicitly defined in the application (i.e. it requires a cast operator). There is a possible risk of losing data when the source and destination have a different size or when the source is converted to a base class. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">double</span> d <span style="color: #008000;">=</span> <span style="color: #FF0000;">10.345</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>d<span style="color: #008000;">;</span></pre></div></div>

<p>This example will not compile without the explicit cast operator since a double fits not in an integer. Also the value will lose its precision since an integer does not store decimal values. On <a href="http://msdn.microsoft.com/en-us/library/yht2cx7b.aspx" target="_blank">this page</a> you can find an explicit number conversion table.</p>
<h2>User-defined conversion</h2>
<p>In C# it is possible to create your own methods for implicit and explicit conversion. For more information see <a href="http://msdn.microsoft.com/en-us/library/09479473.aspx" target="_blank">this article</a>.</p>
<h2>Helper functions</h2>
<p>The .NET framework has various helper functions for conversion. For example <a href="http://msdn.microsoft.com/en-us/library/system.convert.aspx" target="_blank">System.Convert</a> and the Parse method of various types (e.g. <a href="http://msdn.microsoft.com/en-us/library/system.int32.parse.aspx" target="_blank">Int32.Parse</a>).</p>
<h2>Boxing and unboxing</h2>
<p>C# provides a unified type system. All types are derived from the type &#8220;object&#8221;. It is possible to convert for example an integer to the type object (boxing) and back (unboxing). The <a href="http://msdn.microsoft.com/en-us/library/scekt9xw.aspx" target="_blank">is keyword</a> checks if an object is compatible with a specific type. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> Program
<span style="color: #008000;">&#123;</span>
 <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">object</span> o <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// boxing</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span> o<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// unboxing</span>
  Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>j<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>o <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
   Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;o is an int&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>&#8220;Cast&#8221; versus &#8220;as&#8221;</h2>
<p>The <a href="http://msdn.microsoft.com/en-us/library/cscsdfbt.aspx" target="_blank">as operator</a> is often used for type conversion, and it works more or less the same as the cast prefix:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> Program
<span style="color: #008000;">&#123;</span>
 <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ClassA <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  ClassA a <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ClassA<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">object</span> o <span style="color: #008000;">=</span> a<span style="color: #008000;">;</span>
&nbsp;
  ClassA a2 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ClassA<span style="color: #008000;">&#41;</span>o<span style="color: #008000;">;</span>
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> ClassA<span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The difference between these two types of conversion is that the first will throw an exception and the second will return null when the conversion is incorrect:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> Program
<span style="color: #008000;">&#123;</span>
 <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ClassA <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">object</span> o <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">try</span>
  <span style="color: #008000;">&#123;</span>
   ClassA a2 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ClassA<span style="color: #008000;">&#41;</span>o<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>InvalidCastException ex<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
   Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>ex<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> ClassA<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
   Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>However, this is not the only difference (see <a href="http://blogs.msdn.com/ericlippert/archive/2009/10/08/what-s-the-difference-between-as-and-cast-operators.aspx" target="_blank">this post</a> by Eric Lippert). When you have a user-defined conversion from class A to B, the cast operator (B)A will run the user-defined conversion while the &#8220;as&#8221; operator will not. The &#8220;as&#8221; operator will only consider reference, boxing and unboxing conversions. Like Eric says:</p>
<ul>
<li>As: &#8220;I don&#8217;t know if this conversion is legal or not; we&#8217;re going to give it a  try and see how it goes.&#8221;</li>
<li>Cast: &#8220;I am certain that this conversion is legal and I am willing to take a  runtime exception if I&#8217;m wrong.&#8221;</li>
<li>As: &#8220;I want to know what this object *really is*, not what it is convertible  to by some representation-changing specially-defined conversion rule.&#8221;</li>
<li>Cast: &#8220;Convert this thing using whatever crazy mechanism you need to do to make  it work.&#8221;</li>
</ul>
<h3>Performance</h3>
<p><a href="http://www.codeproject.com/KB/cs/csharpcasts.aspx" target="_blank">This article</a> by Emilio Guijarro gives a good explanation about performance of the cast and &#8220;as&#8221; operator. He concludes the &#8220;as&#8221; operator is about 5 times faster than the cast operator. The performance is only going to matter in the million number of casts, and then the performance problem is probably why you need so many cast operations.</p>
<h3>Why (not) to use &#8220;as&#8221;</h3>
<p>As said before the &#8220;as&#8221; operator returns null when the conversion is incorrect. When using this piece of code you can not check if the original object was null:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> Program
<span style="color: #008000;">&#123;</span>
 <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ClassA <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  ClassA a <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">object</span> o <span style="color: #008000;">=</span> a<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">try</span>
  <span style="color: #008000;">&#123;</span>
   ClassA a2 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ClassA<span style="color: #008000;">&#41;</span>o<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>InvalidCastException ex<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
   Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>ex<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> ClassA<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
   Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This program will write &#8220;Incorrect conversion&#8221; while the cast conversion didn&#8217;t throw an exception. Also the &#8220;is&#8221; operator does not help in this case since it returns false when the object is null. A correct pattern could be:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>o <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
 Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;object is null&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">else</span>
<span style="color: #008000;">&#123;</span>
 ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> ClassA<span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
  Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>References</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms173105.aspx" target="_blank">Casting and type conversion &#8211; MSDN</a></li>
<li><a href="http://www.c-sharpcorner.com/UploadFile/ggaganesh/BoxNUnBox11082005073720AM/BoxNUnBox.aspx" target="_blank">Boxing and unboxing in C# &#8211; C-Sharpcorner</a></li>
<li><a href="http://blogs.msdn.com/ericlippert/archive/2009/10/08/what-s-the-difference-between-as-and-cast-operators.aspx" target="_blank">Difference between &#8220;as&#8221; and &#8220;cast&#8221; operators &#8211; Eric Lippert</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Rhino Mocks to mock a void function</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 23:01:57 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Rhino Mocks]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=95</guid>
		<description><![CDATA[Using NUnit and Rhino Mocks to create an expectation for a void function.]]></description>
			<content:encoded><![CDATA[<p>In some of my web applications I use <a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a> to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the <a href="http://www.nunit.org/index.php" target="_blank">NUnit</a> test run will fail:</p>
<pre>Rhino.Mocks.Exceptions.ExpectationViolationException : IMyInterface.MyVoidFunction; Expected #0, Actual #1.</pre>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Record</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Return</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">/* insert expectation for void function here */</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Playback</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// DoSomething calls the mocked object's GetValue function, which returns 'b' when the parameter is 'a'</span>
  <span style="color: #008080; font-style: italic;">// DoSomething also calls a void function which is located in the interface of the mocked object, so this</span>
  <span style="color: #008080; font-style: italic;">// void function must be mocked too, else the test run will fail</span>
  Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span>, _myObject<span style="color: #008000;">.</span><span style="color: #0000FF;">DoSomething</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><span id="more-95"></span></p>
<p>When trying to create an expectation for this void function Visual Studio will give a syntax error:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Argument '1': cannot convert from 'void' to 'Rhino.Mocks.Expect.Action'</span></pre></div></div>

<p>On the internet I found two solutions to fix this problem. The <a href="http://ayende.com/Blog/archive/2007/10/17/Rhino-Mocks-Void-methods-using-Expect.Call.aspx" target="_blank">first solution</a> uses a delegate:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#123;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <a href="http://stackoverflow.com/questions/359831/rhinomock-test-mock-interface-void-functions" target="_blank">second solution</a> uses a <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now the test will succeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CUE files for radio shows</title>
		<link>http://www.marthijnvandenheuvel.com/2010/02/28/cue-files-for-radio-shows/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/02/28/cue-files-for-radio-shows/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 05:30:41 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[cue]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[Winamp]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=20</guid>
		<description><![CDATA[I frequently download the radio shows of Armin van Buuren (A State Of Trance) and Above &#38; Beyond (Trance Around The World). The download sources provide one single mp3 file, and therefore skipping tracks in the radio show is not very easy. A CUE Player plugin for Winamp is able to &#8216;split&#8217; this file and [...]]]></description>
			<content:encoded><![CDATA[<p>I frequently download the radio shows of Armin van Buuren (A State Of Trance) and Above &amp; Beyond (Trance Around The World). The download sources provide one single mp3 file, and therefore skipping tracks in the radio show is not very easy. A <a href="http://www.psytechforum.com/index.php?topic=872.msg2335" target="_blank">CUE Player plugin</a> for Winamp is able to &#8216;split&#8217; this file and show all the tracks as single files in the playlist (without actually splitting the file to separate mp3 files). Now the only problem is, where to get cue files. Recently I found a very nice site providing a lot of cue files for various radio shows: <a href="http://www.cuenation.com/" target="_blank">CueNation</a>. By using <a href="http://cuegenerator.net/" target="_blank">this tool</a> you can create your own cue files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/02/28/cue-files-for-radio-shows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

