<?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>David&#039;s Blog &#187; .net</title>
	<atom:link href="http://www.davidmoore.info/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidmoore.info</link>
	<description>Computer says no</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:49:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Running .NET 2 Runtime applications under the .NET 4 Runtime</title>
		<link>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/</link>
		<comments>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 21:38:31 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[NetFx40_LegacySecurityPolicy]]></category>
		<category><![CDATA[startup]]></category>
		<category><![CDATA[supportRuntime]]></category>
		<category><![CDATA[useLegacyV2RuntimeActivationPolicy]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=381</guid>
		<description><![CDATA[<p>In some situations, you might want to run a .NET 2 Runtime application (.NET 2, 3.0, 3.5 SP1 etc) under the .NET 4 Runtime &#8211; without recompiling.</p>
<p>You can configure your app to execute under the .NET 4 runtime by adding these lines to the executable&#8217;s configuration file, under the root  configuration element:</p>
&#60;startup&#62;
  &#60;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&#62;
&#60;/startup&#62;
<p>Because the security <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/">Running .NET 2 Runtime applications under the .NET 4 Runtime</a></span>]]></description>
			<content:encoded><![CDATA[<p>In some situations, you might want to run a .NET 2 Runtime application (.NET 2, 3.0, 3.5 SP1 etc) under the .NET 4 Runtime &#8211; without recompiling.</p>
<p>You can configure your app to execute under the .NET 4 runtime by adding these lines to the executable&#8217;s configuration file, under the root  <strong>configuration</strong> element:</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span></pre>
<p>Because the security framework has changed in the .NET 4 runtime, you will likely encounter some exceptions containing a message similar to:</p>
<blockquote><p>System.NotSupportedException: This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.</p></blockquote>
<p>To avoid this, you  have to enable the legacy support by adding a runtime element :</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<strong><span style="color: blue;">&lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span></strong></pre>
<p>If your application also uses mixed assemblies that contain both managed and native code (such as System.Data.SQLite.dll), you&#8217;ll see an error message like this:</p>
<blockquote><p>Mixed mode assembly is built against version &#8216;v2.0.50727&#8242; of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.</p></blockquote>
<p>You will need to enable the legacy activation to allow these to be loaded also:</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;"> </span><strong><span style="color: red;">useLegacyV2RuntimeActivationPolicy</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"</strong><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">&lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;

</span></pre>
<h3>References</h3>
<p><a href="http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;startup&gt; Element @ MSDN</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/w4atty68.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;supportedRuntime&gt; Element @ MSDN</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/dd409253.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;NetFx40_LegacySecurityPolicy&gt; Element @ MSDN</a></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
<pre style="font-family: consolas;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;"> </span><span style="color: red;">useLegacyV2RuntimeActivationPolicy</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unit testing multi-threaded, asynchronous code and/or events</title>
		<link>http://www.davidmoore.info/2009/06/03/unit-testing-multi-threaded-asynchronous-code-andor-events/</link>
		<comments>http://www.davidmoore.info/2009/06/03/unit-testing-multi-threaded-asynchronous-code-andor-events/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 22:50:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[mstest]]></category>
		<category><![CDATA[nunit]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=171</guid>
		<description><![CDATA[<p>I&#8217;ve been writing some unit tests recently that test some multi-threaded functionality.</p>
<p>Typically this involves hooking up some event handlers then waiting for some asynchronous code to fire the event before proceeding with the unit test and assertions.</p>
<p>The ManualResetEvent class (MSDN) seems a good choice for this, and this post has a small example of using it <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/06/03/unit-testing-multi-threaded-asynchronous-code-andor-events/">Unit testing multi-threaded, asynchronous code and/or events</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing some unit tests recently that test some multi-threaded functionality.</p>
<p>Typically this involves hooking up some event handlers then waiting for some asynchronous code to fire the event before proceeding with the unit test and assertions.</p>
<p>The <a title="ManualResetEvent Class @ MSDN" href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">ManualResetEvent class (MSDN)</a> seems a good choice for this, and <a title="Unit Testing Multi-Threaded Asynchronous Events" href="http://jopinblog.wordpress.com/2007/07/10/unit-testing-multi-threaded-asynchronous-events/" onclick="javascript:pageTracker._trackPageview('/outbound/article/jopinblog.wordpress.com');">this post</a> has a small example of using it in a unit test:</p>
<blockquote><pre><code>
[Test()]
public void AfterRunAsync()
{
    ManualResetEvent manualEvent = new ManualResetEvent(false);

    TestTestCase tc = new TestTestCase(1, "", 0, 0);
    bool eventFired = false;
    tc.RunCompleted +=
        delegate(object sender, AsyncCompletedEventArgs e) {
            Assert.IsInstanceOfType(typeof (TestTestCase), sender, "sender is TestCase");
            bool passed = tc.Passed;
            string output = tc.Output;
            eventFired = true;
            manualEvent.Set();
        };
    tc.RunAsync();
    manualEvent.WaitOne(500, false);
    Assert.IsTrue(eventFired, "RunCompleted fired");
}
</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/06/03/unit-testing-multi-threaded-asynchronous-code-andor-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote debugging from Visual Studio 2008 on a domain machine to a machine not on the domain</title>
		<link>http://www.davidmoore.info/2009/05/28/remote-debugging-from-visual-studio-2008-on-a-domain-machine-to-a-machine-not-on-the-domain/</link>
		<comments>http://www.davidmoore.info/2009/05/28/remote-debugging-from-visual-studio-2008-on-a-domain-machine-to-a-machine-not-on-the-domain/#comments</comments>
		<pubDate>Thu, 28 May 2009 05:25:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[attach]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[machine]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[remote debugger]]></category>
		<category><![CDATA[remote debugging]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=166</guid>
		<description><![CDATA[<p>This details how you can debug an application running on a remote machine from Visual Studio on your local machine, as if the remote application was running on your local machine.</p>
<p>The keys are:</p>

There must be a user account with the same username and password on the remote machine and the local machine (MACHINE account, not domain <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/05/28/remote-debugging-from-visual-studio-2008-on-a-domain-machine-to-a-machine-not-on-the-domain/">Remote debugging from Visual Studio 2008 on a domain machine to a machine not on the domain</a></span>]]></description>
			<content:encoded><![CDATA[<p>This details how you can debug an application running on a remote machine from Visual Studio on your local machine, as if the remote application was running on your local machine.</p>
<p>The keys are:</p>
<ol>
<li>There must be a user account with the same username and password on the remote machine and the local machine (MACHINE account, not domain account).</li>
<li>Visual Studio 2008 Remote Debugger must be installed and running on the remote machine under the user account in point 1</li>
</ol>
<h2>Create local machine account</h2>
<ol>
<li>Right click My Computer &gt; Manage</li>
<li>Expand Computer Management &gt; System Tools &gt; Local Users and Groups</li>
<li>Right-click Users under Local Users and Groups and choose New User&#8230;</li>
<li>Enter in the username e.g. DebugUser</li>
<li>Enter and confirm the password</li>
<li> Un-check &#8220;User must change password at next login&#8221; and tick &#8220;Password never expire&#8221;</li>
<li>Click Create</li>
<li>Click Close</li>
</ol>
<h2>Create remote machine account</h2>
<ol>
<li>Log on to the remote machine and repeat the steps for &#8220;Create local machine account&#8221;</li>
<li><em>You must use the same username and password</em></li>
<li>Find the user in the Users list and double-click to edit them</li>
<li>Go to the Member Of tab</li>
<li>Click Add&#8230;</li>
<li>Type in Administrators and hit Enter or click OK</li>
<li>Click OK</li>
</ol>
<h2>Run Visual Studio 2008 Remote Debugger</h2>
<p>You have several options for launching the Remote Debugger.</p>
<ol>
<li>If you install Visual Studio 2008, the Remote Debugger folder can be found in %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE. In the Remote Debugger folder are separate folders for the x86 and x64 versions. Perhaps the easiest solution is to share this folder over the network, allowing you to launch the debugger over the network without having to install anything on the remote machine.</li>
<li>Alternatively, you can find the Remote Debugger setup on the first disc for the Visual Studio 2008 setup, in a sub folder called Remote Debugger.</li>
<li>Or, you can download it from <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=440ec902-3260-4cdc-b11a-6a9070a2aaab&amp;displaylang=en" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');">here</a></li>
</ol>
<p>It&#8217;s a good idea to run this as a Windows application as recommended by the Visual Studio 2008 Remote Debugger Configuration Wizard (and in my opinion easier to troubleshoot).</p>
<p>At this point if you&#8217;re not logged in as the new user you created, you might want to do that now so that you can run the Remote Debugger under them.</p>
<p>Once you&#8217;ve followed instructions for installing, run the remote debugger if it isn&#8217;t already by going to Start &gt; Programs &gt; Microsoft Visual Studio 2008 &gt; Visual Studio Tools &gt; Visual Studio 2008 Remote Debugger.</p>
<p>It should say that it&#8217;s running an instance similar to DebugUser@RemoteMachineName</p>
<h2>Connect to the remote machine with Visual Studio</h2>
<ol>
<li>In Visual Studio on your local machine, go to Debug &gt; Attach to process&#8230;</li>
<li>Make sure the Transport drop-down at the top is set to Default</li>
<li>In Qualifier, type in the name of the Remote Debugger instance e.g. DebugUser@RemoteMachineName and hit Enter</li>
<li>You should then see the list of remote processes in the list and can select the one you want and click Attach.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/05/28/remote-debugging-from-visual-studio-2008-on-a-domain-machine-to-a-machine-not-on-the-domain/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Set up IP filtering in uTorrent and keep your ipfilter.dat up to date easily</title>
		<link>http://www.davidmoore.info/2009/05/27/set-up-ip-filtering-in-utorrent-and-keep-your-ipfilterdat-up-to-date-easily/</link>
		<comments>http://www.davidmoore.info/2009/05/27/set-up-ip-filtering-in-utorrent-and-keep-your-ipfilterdat-up-to-date-easily/#comments</comments>
		<pubDate>Tue, 26 May 2009 12:14:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[bittorrent]]></category>
		<category><![CDATA[bt]]></category>
		<category><![CDATA[ipfilter]]></category>
		<category><![CDATA[ipfilter.dat]]></category>
		<category><![CDATA[ipfilterupdater]]></category>
		<category><![CDATA[torrent]]></category>
		<category><![CDATA[utorrent]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=157</guid>
		<description><![CDATA[<p>The IPFilter Updater application now has its own page: http://www.davidmoore.info/ipfilter-updater/</p>
<p>uTorrent is one of the most popular BitTorrent clients out there. In my opinion it&#8217;s the best.</p>
<p>You can set up IP filtering in uTorrent to block bad seeds and peers from a list maintained by the community.</p>
How to set up IP filtering in uTorrent

Open up uTorrent and <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/05/27/set-up-ip-filtering-in-utorrent-and-keep-your-ipfilterdat-up-to-date-easily/">Set up IP filtering in uTorrent and keep your ipfilter.dat up to date easily</a></span>]]></description>
			<content:encoded><![CDATA[<blockquote><p>The IPFilter Updater application now has its own page: <a href="http://www.davidmoore.info/ipfilter-updater/" >http://www.davidmoore.info/ipfilter-updater/</a></p></blockquote>
<p>uTorrent is one of the most popular BitTorrent clients out there. In my opinion it&#8217;s the best.</p>
<p>You can set up IP filtering in uTorrent to block bad seeds and peers from a list maintained by the community.</p>
<h2>How to set up IP filtering in uTorrent</h2>
<ol>
<li>Open up uTorrent and go to Options &gt; Preferences from the menu or click the Preferences button in the toolbar</li>
<li>Select the Advanced option in the tree</li>
<li>Find ipfilter.enabled in the list and make sure it&#8217;s set to true</li>
<li>Click OK</li>
</ol>
<h2>How to get and update the ipfilter.dat</h2>
<p>I&#8217;ve written a simple program that will download the ipfilter.dat from SourceForge and copy it into the file where uTorrent expects it.</p>
<p><a href="http://www.davidmoore.info/wp-content/uploads/2009/05/IPFilterUpdater.png" ><img class="alignnone size-medium wp-image-251" title="IPFilterUpdater" src="http://www.davidmoore.info/wp-content/uploads/2009/05/IPFilterUpdater.png" alt="" width="683" height="172" /></a></p>
<p><a href="/ipfilter-updater/">uTorrent IPFilter Updater</a> [ Requires .NET 3.5 ]</p>
<blockquote><p><strong>UPDATED  26 Jan 2010</strong>: Now requires .NET 3.5, and allows mirror selection</p>
<ol>
<li>Extract the files to a folder, and run IPFilter.UI.exe</li>
<li>Wait for it to download the mirrors, select the one you want, and click Go</li>
<li>Once the file has downloaded and extracted, you can close the window</li>
</ol>
<h4>Enhancements</h4>
<p><strong>Done:</strong></p>
<ul>
<li>Download and extract zip file to speed up the download time and minimize the download usage</li>
</ul>
<ul>
<li>Allow selection of mirror you want to use</li>
</ul>
<p><strong>To Do:</strong></p>
<ul>
<li>Automation through command-line arguments, for scheduled tasks</li>
</ul>
<p>Source Code: <a href="http://github.com/DavidMoore/IP-Filter-Updater/" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">http://github.com/DavidMoore/IP-Filter-Updater/</a></p></blockquote>
<h2>How to get uTorrent to pick up the new ipfilter.dat</h2>
<p>You have two options:</p>
<ol>
<li>You can simply exit and restart uTorrent to load theIPFilter <strong>or</strong></li>
<li>You can leave uTorrent open and reload the IPFilter by selecting the Peers tab, right clicking in the list and choosing Reload IPFilter. Annoyingly you need a selected torrent for this to work.</li>
</ol>
<p>Looking in the Log should show a message similar to &#8220;Loaded ipfilter.dat xxxxxx entries)&#8221;</p>
<p>Because IP ranges and addresses change often, it&#8217;s a good idea to update your filter list often too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/05/27/set-up-ip-filtering-in-utorrent-and-keep-your-ipfilterdat-up-to-date-easily/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Could not load file or assembly ‘x’ or one of its dependencies. Strong name validation failed.</title>
		<link>http://www.davidmoore.info/2009/05/26/could-not-load-file-or-assembly-x-or-one-of-its-dependencies-strong-name-validation-failed/</link>
		<comments>http://www.davidmoore.info/2009/05/26/could-not-load-file-or-assembly-x-or-one-of-its-dependencies-strong-name-validation-failed/#comments</comments>
		<pubDate>Tue, 26 May 2009 03:54:34 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[failed]]></category>
		<category><![CDATA[sn]]></category>
		<category><![CDATA[sn.exe]]></category>
		<category><![CDATA[strong name]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=153</guid>
		<description><![CDATA[<p>In some of the work I&#8217;m doing right now, I&#8217;m manipulating an assembly after compile time &#8211; having it disassembled into IL, tweaked, then re-compiled back into an assembly.</p>
<p>The assembly is signed and what is being done to the assembly is breaking the strong name. This is quite comforting to know; the strong name wouldn&#8217;t be <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/05/26/could-not-load-file-or-assembly-x-or-one-of-its-dependencies-strong-name-validation-failed/">Could not load file or assembly ‘x’ or one of its dependencies. Strong name validation failed.</a></span>]]></description>
			<content:encoded><![CDATA[<p>In some of the work I&#8217;m doing right now, I&#8217;m manipulating an assembly after compile time &#8211; having it disassembled into IL, tweaked, then re-compiled back into an assembly.</p>
<p>The assembly is signed and what is being done to the assembly is breaking the strong name. This is quite comforting to know; the strong name wouldn&#8217;t be so strong if it was that easy to hack an assembly with a strong name.</p>
<p>When trying to load the hacked assembly, I am getting an exception (FileLoadException in this case but I&#8217;m guessing this may differ depending on your assembly load method) with the message &#8220;Could not load file or assembly &#8216;MyAssemblyName&#8217; or one of its dependencies. Strong name validation failed.&#8221;.</p>
<p>The first interesting thing here is that the assembly named in the error message isn&#8217;t the hacked assembly; the hacked assembly is one of MyAssemblyName&#8217;s dependencies and is what&#8217;s triggering the error.</p>
<p><em>Make sure that you check the dependencies of the assembly named in the exception message when troubleshooting. The problem may be with one of the dependencies.</em></p>
<p>In my case the exception isn&#8217;t a surprise because of what&#8217;s being done to the assembly. But until I resolve that, how can I get around this for now?</p>
<p>You can exclude an assembly from strong name validation for development purposes using the <a title="Strong Name Tool" href="http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.71).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">Microsoft (R) .NET Framework Strong Name Utility</a> tool aka sn.exe:</p>
<p><code>"%ProgramFiles%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -Vr "C:\Path\To\Assembly.dll"</code></p>
<p>Make sure you change the sn.exe path depending on which version of the .NET Framework SDK you have installed. If you&#8217;re having trouble, get into the  &#8221;%ProgramFiles%\Microsoft SDKs\Windows&#8221; dir and search for sn.exe, and use the newest one you can find.</p>
<p>You might find it handy to add this as a Post-build event command-line for your project from within Visual Studio in Project Properties &gt; Build Events:</p>
<p><code>"%ProgramFiles%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -Vr "$(TargetPath)"</code></p>
<p>So how do you switch the strong name validation back on for your assembly?</p>
<p>Use the -Vu switch:</p>
<p><code>"%ProgramFiles%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -Vu "C:\Path\To\Assembly.dll"</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/05/26/could-not-load-file-or-assembly-x-or-one-of-its-dependencies-strong-name-validation-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring NLog for your application when NLog is in the Global Assembly Cache (GAC)</title>
		<link>http://www.davidmoore.info/2009/05/22/configuring-nlog-for-your-application-when-nlog-is-in-the-global-assembly-cache-gac/</link>
		<comments>http://www.davidmoore.info/2009/05/22/configuring-nlog-for-your-application-when-nlog-is-in-the-global-assembly-cache-gac/#comments</comments>
		<pubDate>Fri, 22 May 2009 00:28:23 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[ConfigSectionHandler]]></category>
		<category><![CDATA[gac]]></category>
		<category><![CDATA[global assembly cache]]></category>
		<category><![CDATA[NLog]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=140</guid>
		<description><![CDATA[<p>If you have several applications that are using NLog, it can be a good idea to install NLog into the GAC and reference that.</p>
<p>A gotcha you must watch out for is caused by this piece of configuration from the NLog site:

&#60;configuration&#62;
&#60;configSections&#62;
&#60;section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/&#62;
&#60;/configSections&#62;
&#60;nlog&#62;
&#60;/nlog&#62;
&#60;/configuration&#62;</p>
<p>Because you are not using the strong name for the Assembly-qualified name of <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/05/22/configuring-nlog-for-your-application-when-nlog-is-in-the-global-assembly-cache-gac/">Configuring NLog for your application when NLog is in the Global Assembly Cache (GAC)</a></span>]]></description>
			<content:encoded><![CDATA[<p>If you have several applications that are using NLog, it can be a good idea to install NLog into the GAC and reference that.</p>
<p>A gotcha you must watch out for is caused by this piece of configuration from the NLog site:<br />
<code><br />
&lt;configuration&gt;<br />
&lt;configSections&gt;<br />
&lt;section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/&gt;<br />
&lt;/configSections&gt;<br />
&lt;nlog&gt;<br />
&lt;/nlog&gt;<br />
&lt;/configuration&gt;</code></p>
<p>Because you are not using the strong name for the Assembly-qualified name of ConfigSectionHandler, it&#8217;s impossible to do a GAC lookup, therefore NLog won&#8217;t be found and you&#8217;ll get an application error (even if NLog is actually in the GAC).</p>
<p>This means your application will throw an exception when the configuration is loaded; there will be no NLog.dll in your application folder and it can&#8217;t check the GAC as it doesn&#8217;t have the strong name of the assembly you want.</p>
<p>You can fix this by including the strong name:<br />
<code><br />
&lt;section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog, Version=1.0.0.505, Culture=neutral, PublicKeyToken=5120e14c03d0593c" /&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/05/22/configuring-nlog-for-your-application-when-nlog-is-in-the-global-assembly-cache-gac/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating thumbnail images with automatic cropping and maintaining aspect ratio</title>
		<link>http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/</link>
		<comments>http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 14:17:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[thumb]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://davidmoore.info/?p=76</guid>
		<description><![CDATA[<p>Most thumbnail-generation solutions will shrink the original down while maintaining aspect ratio.</p>
<p>Usually you specify the maximum height and width of the thumbnail, e.g. 150 x 200.</p>
<p>However, if your original image&#8217;s aspect ratio is different to the maximum thumbnail dimensions, you will end up with dead space vertically or horizontally (shown in green in the illustration). This <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/">Creating thumbnail images with automatic cropping and maintaining aspect ratio</a></span>]]></description>
			<content:encoded><![CDATA[<p>Most thumbnail-generation solutions will shrink the original down while maintaining aspect ratio.</p>
<p>Usually you specify the maximum height and width of the thumbnail, e.g. 150 x 200.</p>
<p>However, if your original image&#8217;s aspect ratio is different to the maximum thumbnail dimensions, you will end up with dead space vertically or horizontally (shown in green in the illustration). This can be quite an eyesore when displaying thumbnails in a grid.</p>
<p><img class="alignnone size-full wp-image-77" title="Normal Thumbnail Resizing Diagram" src="http://davidmoore.info/wp-content/uploads/2009/02/image-resize-normal.gif" alt="Normal Thumbnail Resizing Diagram" width="672" height="334" /></p>
<p>I&#8217;ve got an algorithm that will automatically crop the image either horizontally or vertically to then match the thumbnail aspect ratio, so you end up with the thumbnails all being the same size even though they may be coming from originals of wildly different aspect ratio.</p>
<p>In the illustration, you can see that the image is scaled down and fills all the available thumbnail space, showing the parts in grey from the original that were cropped out.</p>
<p><img class="alignnone size-full wp-image-78" title="Image resizing with automatic cropping" src="http://davidmoore.info/wp-content/uploads/2009/02/image-resize-crop.gif" alt="Image resizing with automatic cropping" width="716" height="333" /></p>
<p>The algorithm does the cropping before the resizing. It takes the width and height of the original image, and the width and height of the desired thumbnail. It will return the width and height that the original must be cropped to, to match the aspect ratio of the thumbnail.<span id="more-76"></span></p>
<p><img class="alignnone size-full wp-image-79" title="Image resize with automatic cropping C# code" src="http://davidmoore.info/wp-content/uploads/2009/02/image-resize-crop.png" alt="Image resize with automatic cropping C# code" width="926" height="521" /></p>
<p>Of course this isn&#8217;t quite enough; where do we do the cropping? All from the top of the image, or the bottom, or a mix? Ideally we want the user to choose which parts of the original they want cropped out. But we can do some very simple automatic cropping by cropping equal amounts from each side that needs to be cropped.</p>
<p><img class="alignnone size-full wp-image-80" title="image-resize-crop-rectangle" src="http://davidmoore.info/wp-content/uploads/2009/02/image-resize-crop-rectangle.png" alt="image-resize-crop-rectangle" width="950" height="229" /></p>
<p>Now we know exactly which part of the original we can take and then resize down to a thumbnail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Castle Project update</title>
		<link>http://www.davidmoore.info/2009/01/08/castle-project-update/</link>
		<comments>http://www.davidmoore.info/2009/01/08/castle-project-update/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 03:18:26 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[castle]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[windsor]]></category>

		<guid isPermaLink="false">http://davidmoore.info/?p=64</guid>
		<description><![CDATA[<p>Hamilton has applied a bunch of patches and fixes to the Castle Project for the Components and Windsor sub-projects. Including 2 minor and insignificant patches that I submitted +D. It&#8217;s good to feel part of a major Open Source project, even for a small contribution.</p>
<p>http://hammett.castleproject.org/?p=336</p>
<p>While I&#8217;m currently focusing my efforts on ASP.NET MVC and moved away <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2009/01/08/castle-project-update/">Castle Project update</a></span>]]></description>
			<content:encoded><![CDATA[<p>Hamilton has applied a bunch of patches and fixes to the Castle Project for the Components and Windsor sub-projects. Including 2 minor and insignificant patches that I submitted +D. It&#8217;s good to feel part of a major Open Source project, even for a small contribution.</p>
<p>http://hammett.castleproject.org/?p=336</p>
<p>While I&#8217;m currently focusing my efforts on ASP.NET MVC and moved away from MonoRail, I use Castle extensively in my .NET projects, particularly ActiveRecord and Windsor/MicroKernel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2009/01/08/castle-project-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio Performance</title>
		<link>http://www.davidmoore.info/2008/12/09/visual-studio-performance/</link>
		<comments>http://www.davidmoore.info/2008/12/09/visual-studio-performance/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 18:18:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://davidmoore.info/?p=60</guid>
		<description><![CDATA[<p>I&#8217;m running Visual Studio 2008 on a old, single-core laptop with 1GB RAM.</p>
<p>VS is a resource hog, so it&#8217;s not long before my laptop is struggling having a reasonable size solution in addition to the usual open applications.</p>
<p>There are a few things you can do to try and squeeze a bit more performance out of Visual <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2008/12/09/visual-studio-performance/">Visual Studio Performance</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m running Visual Studio 2008 on a old, single-core laptop with 1GB RAM.</p>
<p>VS is a resource hog, so it&#8217;s not long before my laptop is struggling having a reasonable size solution in addition to the usual open applications.</p>
<p>There are a few things you can do to try and squeeze a bit more performance out of Visual Studio I&#8217;ve found from various blogs and looking around myself. The first two are the most useful. Don&#8217;t muck with the other options unless you know what they&#8217;re going to do.</p>
<p><strong>Recycle Memory</strong><br />
Perhaps the biggest trick is the simplest: if you <strong>minimize Visual Studio</strong>, it will force a garbage collection, and packing of the memory usage. This can make VS drop from a few hundreds MB of memory usage to 20 or less. Of course things will slow down when you go back into VS as things get reloaded into memory from virtual memory and disk.</p>
<p><strong>Patch to SP1</strong><br />
Make sure <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;displaylang=en" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');" target="_blank">Visual Studio 2005 SP1</a> is installed, for the bug and performance fixes since release.</p>
<p><strong>Turn off animation</strong><br />
Tools &gt; Options &gt; Environment &gt; General and uncheck Animate environment tools.</p>
<p><strong>Disable the Navigation Bar</strong><br />
Go to Tools &gt; Options &gt; Text Editor &gt; C# and uncheck Navigation bar under Display.</p>
<p><strong>Turn off Track Changes</strong><br />
Tools &gt; Options &gt; Text Editor and uncheck Track changes.</p>
<p><strong>Turn off Track Active item</strong><br />
Tools &gt; Options &gt; Projects and Solutions: uncheck Track Active Item in Solution Explorer.</p>
<p><strong>Turn off AutoToolboxPopulate.</strong><br />
Tools &gt; Options &gt; Windows Forms Designer: set AutoToolboxPopulate to False.</p>
<p><strong>Startup with an empty environment</strong><br />
Tools &gt; Options &gt; At startup: Show empty content</p>
<p><strong>Windows Forms refactoring</strong><br />
Tools &gt; Windows Forms Designer &gt; General: Set “EnableRefactoringOnRename” to false in the Refactoring section</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2008/12/09/visual-studio-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System.BadImageFormatException</title>
		<link>http://www.davidmoore.info/2008/10/14/systembadimageformatexception/</link>
		<comments>http://www.davidmoore.info/2008/10/14/systembadimageformatexception/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 12:52:42 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[BadImageFormatException]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://davidmoore.info/?p=28</guid>
		<description><![CDATA[<p>I&#8217;m currently build the new Overclockers New Zealand website in .NET</p>
<p>I have a nice continuous integration server going smoothly, but my most recent check-in threw up a strange error when running the Unit Tests:</p>
<p>System.BadImageFormatException : Could not load file or assembly &#8216;Overclockers.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; or one of its dependencies. The module was expected to contain <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2008/10/14/systembadimageformatexception/">System.BadImageFormatException</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently build the new Overclockers New Zealand website in .NET</p>
<p>I have a nice continuous integration server going smoothly, but my most recent check-in threw up a strange error when running the Unit Tests:</p>
<blockquote><p>System.BadImageFormatException : Could not load file or assembly &#8216;Overclockers.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; or one of its dependencies. The module was expected to contain an assembly manifest.</p></blockquote>
<p>The server is actually a VMWare instance, but is running a 32-bit version of Windows Server 2003 EE.</p>
<p>After some troubleshooting and searching, I decided to first try to explicitly build for x86 first anyway. This is done in the Project Properties dialog in Visual Studio.</p>
<p><img class="alignnone" title="Target platform for X86" src="/wp-content/uploads/target-platform-x86.jpg" alt="" width="625" height="371" /></p>
<p>When changing this, make sure you make the change for both Debug and Release configurations.</p>
<p>This seemed to fix the problem.</p>
<p>I suspect this could be because I have some Shell32 interop in one of my shared libraries, and this may have caused problems, and/or the fact I&#8217;m running the instance on VMWare.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2008/10/14/systembadimageformatexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

