<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0">

<channel>
	<title>Blinded by the lights</title>
	
	<link>http://dobrzanski.net</link>
	<description>The blog for developers</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:20:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BlindedByTheLights" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="blindedbythelights" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.0/</creativeCommons:license><item>
		<title>2011 in review</title>
		<link>http://dobrzanski.net/2012/01/25/2011-review/</link>
		<comments>http://dobrzanski.net/2012/01/25/2011-review/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 21:20:19 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[blogging]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=834</guid>
		<description><![CDATA[It&#8217;s end of January 2012 by now, but I decided to share some stats on what was going on with this blog in 2011. If you fancy reading my stuff (is there anybody? ) you might find it interesting. Let&#8217;s get down to the business: only 3 posts that year busy? lazy? &#8230;? nevertheless, I [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s end of January 2012 by now, but I decided to share some stats on what was going on with this blog in 2011. If you fancy reading my stuff (is there anybody? <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_smile.gif' alt="icon smile 2011 in review" class='wp-smiley' title="2011 in review Photo" /> ) you might find it interesting. </p>
<p>Let&#8217;s get down to the business:</p>
<ul>
<li>only 3 posts that year <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_neutral.gif' alt="icon neutral 2011 in review" class='wp-smiley' title="2011 in review Photo" />  busy? lazy? &#8230;?</li>
<li>nevertheless, I was observing constant interest growth (more and more vistst, by Google Analytics):
<ul>
<li>196,717 Visits (+45% comparing to 2010)</li>
<li>178,770 Unique Visitors (+46% comparing to 2010)</li>
<li>222,258 Pageviews (+42% comparing to 2010)</li>
</ul>
</li>
<li>most popular post: <a href="http://dobrzanski.net/2009/05/14/c-decimaltostring-and-how-to-get-rid-of-trailing-zeros/">C#, decimal.toString(), and how to get rid of trailing zeros</a> &#8211; 17,302 pageviews
</ul>

<p><a href="http://feedads.g.doubleclick.net/~a/Q8_5fRV8eSMOLpOXR_zyPq3pZ50/0/da"><img src="http://feedads.g.doubleclick.net/~a/Q8_5fRV8eSMOLpOXR_zyPq3pZ50/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Q8_5fRV8eSMOLpOXR_zyPq3pZ50/1/da"><img src="http://feedads.g.doubleclick.net/~a/Q8_5fRV8eSMOLpOXR_zyPq3pZ50/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2012/01/25/2011-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio TFS: How to undelete file(s)</title>
		<link>http://dobrzanski.net/2012/01/21/visual-studio-tfs-how-to-undelete-files/</link>
		<comments>http://dobrzanski.net/2012/01/21/visual-studio-tfs-how-to-undelete-files/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 14:32:15 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[TFS]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=828</guid>
		<description><![CDATA[What if you need to undelete a file or bunch of files that at some point have been deleted from TFS? Naive option would be to get the content of the file, copy it, create a new file, and paste the copied content to just created file. Of course, this is not a good option [...]]]></description>
			<content:encoded><![CDATA[<p>What if you need to undelete a file or bunch of files that at some point have been deleted from TFS? Naive option would be to get the content of the file, copy it, create a new file, and paste the copied content to just created file. Of course, this is not a good option because history of changes to the file(s) will be lost.</p>
<p><span id="more-828"></span></p>
<h2>Solution</h2>
<p>Go to Source Control window and locate the file(s) that need restoring. If you can&#8217;t see deleted items, go to Tools > Options > Source Control > Visual Studio Team Foundation Server and check &#8216;Show deleted items in the Source Control Explorer&#8217; (see the screenshot below). This way, in Source Control explorer you should be able to locate both existing and deleted items.</p>
<p><a href="http://dobrzanski.net/wp-content/uploads/2012/01/vs_tfs_settings.png" rel="lightbox[828]"><img src="http://dobrzanski.net/wp-content/uploads/2012/01/vs_tfs_settings-350x203.png" alt="vs tfs settings 350x203 Visual Studio TFS: How to undelete file(s)" title="Visual Studio Team Foundation Server settings" width="350" height="203" class="alignnone size-medium wp-image-829" /></a></p>
<p>Now, in Source Control window, right click the item(s) you want to restore and select Undelete. The file(s) will be marked with undelete chage in Pending Changes window. All you need to do now is to check in the change. Complete history of changes to the restored files will be saved.</p>
<p>P.S. This is hint given by my friend (thanks Tomek <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Visual Studio TFS: How to undelete file(s)" class='wp-smiley' title="Visual Studio TFS: How to undelete file(s) Photo" /> ).</p>

<p><a href="http://feedads.g.doubleclick.net/~a/3cFuLucSiTqZwxaKu_OwY1zuqrY/0/da"><img src="http://feedads.g.doubleclick.net/~a/3cFuLucSiTqZwxaKu_OwY1zuqrY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3cFuLucSiTqZwxaKu_OwY1zuqrY/1/da"><img src="http://feedads.g.doubleclick.net/~a/3cFuLucSiTqZwxaKu_OwY1zuqrY/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2012/01/21/visual-studio-tfs-how-to-undelete-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: How to get service name listening at specific port number?</title>
		<link>http://dobrzanski.net/2012/01/09/how-to-get-service-name-listening-at-specific-port-number/</link>
		<comments>http://dobrzanski.net/2012/01/09/how-to-get-service-name-listening-at-specific-port-number/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 12:52:45 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=825</guid>
		<description><![CDATA[How to get service name listening at specific port in C#? What you have as input is only two pieces of information: host name and the port number the service is listening at. Solution Apparently, .NET does not provide such feature so one needs to stretch a bit to get the answer. What I can [...]]]></description>
			<content:encoded><![CDATA[<p>How to get service name listening at specific port in C#? What you have as input is only two pieces of information: host name and the port number the service is listening at.</p>
<h2>Solution</h2>
<p>Apparently, .NET does not provide such feature so one needs to stretch a bit to get the answer. What I can suggest (I&#8217;m far from saying it&#8217;s good approach, though) is to get the name in two steps:</p>
<ol>
<li>Use <code>netstat -a -o</code> and parse the output (ouch!) to get ID of the process (PID) that is listening at given port number</li>
<li>Perform a WMI call to get the name of the service: <code>SELECT Name FROM Win32_Service where ProcessId = PID</code></li>
</ol>
<p>Following this will give you what you want, but to be honest any time I need to parse output to get some information I feel anxious&#8230; This is the first place in the code where errors can be introduced. </p>
<p>If there is/are better/safer way(s) to retrieve service name having the host name and port it&#8217;s listening at, please share it.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/77moj6MecjNj87sOzf2-vSlKI6c/0/da"><img src="http://feedads.g.doubleclick.net/~a/77moj6MecjNj87sOzf2-vSlKI6c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/77moj6MecjNj87sOzf2-vSlKI6c/1/da"><img src="http://feedads.g.doubleclick.net/~a/77moj6MecjNj87sOzf2-vSlKI6c/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2012/01/09/how-to-get-service-name-listening-at-specific-port-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio: Improved navigation through the files with RockScroll</title>
		<link>http://dobrzanski.net/2011/12/12/visual-studio-improved-navigation-through-the-files-with-rockscroll/</link>
		<comments>http://dobrzanski.net/2011/12/12/visual-studio-improved-navigation-through-the-files-with-rockscroll/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 07:39:11 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[visual studio]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=814</guid>
		<description><![CDATA[If you have never used RockScroll you are probably most comfortable with standard scrollbar Visual Studio offers. I guarantee you, however, that the moment you install RockScroll and work with it for a while, you will miss it a lot if you switch to Visual Studio that&#8217;s not extended with it. I&#8217;ve experienced that many [...]]]></description>
			<content:encoded><![CDATA[<p>If you have never used <a href="http://www.hanselman.com/blog/IntroducingRockScroll.aspx">RockScroll</a> you are probably most comfortable with standard scrollbar Visual Studio offers. I guarantee you, however, that the moment you install RockScroll and work with it for a while, you will miss it a lot if you switch to Visual Studio that&#8217;s not extended with it. I&#8217;ve experienced that many times when kneeled at a teammate&#8217;s desk trying to help him move on with their task. This is probably best moment when you will realize that Visual Studio misses a thing without RockScroll <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Visual Studio: Improved navigation through the files with RockScroll" class='wp-smiley' title="Visual Studio: Improved navigation through the files with RockScroll Photo" /> </p>
<p>Here are most important pros that make me think RockScroll is must-have plugin for Visual Studio:</p>
<p><span id="more-814"></span></p>
<ul>
<li>Replaces standard Visual Studio scrollbar with slightly wider one which is actually a thumbnail of current file with indication what you currently see in main window. Great, especially when working with long files.</li>
<li>Highlights in red all occurrences of selected word. This is most powerful &#8211; no more &#8216;Find all references&#8217; and switching context between the main window and Find Symbol Results pane.</li>
</ul>
<p>Here&#8217;s a snapshot of how it looks (taken from Scott Hanselman&#8217;s blog):<br />
<img src="http://dobrzanski.net/wp-content/uploads/2011/12/RockScroll.png" alt="RockScroll Visual Studio: Improved navigation through the files with RockScroll" title="RockScroll" width="500" height="379" class="alignnone size-full wp-image-815" /></p>
<p>I recommend you <a href="http://www.hanselman.com/blog/IntroducingRockScroll.aspx">download RockScroll from Scott Hanselman&#8217;s blog</a> and give it a try.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/LJrHeLrfjJ_kotovBY_Hn5L6YvI/0/da"><img src="http://feedads.g.doubleclick.net/~a/LJrHeLrfjJ_kotovBY_Hn5L6YvI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LJrHeLrfjJ_kotovBY_Hn5L6YvI/1/da"><img src="http://feedads.g.doubleclick.net/~a/LJrHeLrfjJ_kotovBY_Hn5L6YvI/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2011/12/12/visual-studio-improved-navigation-through-the-files-with-rockscroll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++: Overriding methods – problem with hiding overloads in the base class</title>
		<link>http://dobrzanski.net/2011/12/10/cpp-overriding-methods-problem-with-hiding-overloads-in-the-base-class/</link>
		<comments>http://dobrzanski.net/2011/12/10/cpp-overriding-methods-problem-with-hiding-overloads-in-the-base-class/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 17:53:10 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=801</guid>
		<description><![CDATA[What is the outcome of the simple program below? #include &#60;iostream&#62; #include &#60;conio.h&#62; using namespace std; class Base { public: void DoSth(int tmp) { cout]]></description>
			<content:encoded><![CDATA[<p>What is the outcome of the simple program below?</p>
<pre name="code" class="c-sharp">
#include &lt;iostream&gt;
#include &lt;conio.h&gt;

using namespace std;

class Base
{
public:
   void DoSth(int tmp)
   {
	   cout << "Base::DoSth(int)\n";
   }

   void DoSth(char tmp)
   {
	   cout << "Base::DoSth(char)\n";
   }
};

class Derived : public Base
{
public:
   void DoSth(int tmp)
   {
	   cout << "Derived:DoSth(int)\n";
   }
};

int main()
{
	Derived d;
	d.DoSth(5);
	d.DoSth('c');

	getch();
    return 0;
}
</pre>
<p><span id="more-801"></span></p>
<h2>Answer</h2>
<pre name="code" class="c-sharp">
Derived:DoSth(int)
Derived:DoSth(int)
</pre>
<p>Surprised? If so, you probably chose:</p>
<pre name="code" class="c-sharp">
Derived:DoSth(int)
Base::DoSth(char)
</pre>
<p>There's a tricky problem here, though. The reason why the code worked as it did is class <code>Derived</code> overrode only one method from <code>Base</code> class: <code>Base::DoSth(int)</code> and thus it hid the other overloads defined by class <code>Base</code>. This way, executing <code>d.DoSth('c')</code> actually invoked <code>Derived::DoSth(int)</code>, casting <code>char</code> to <code>int</code>.</p>
<p>In order to get this output:</p>
<pre name="code" class="c-sharp">
Derived:DoSth(int)
Base::DoSth(char)
</pre>
<p>class <code>Derived</code> must be defined as below:</p>
<pre name="code" class="c-sharp">
class Derived : public Base
{
public:
   void DoSth(int tmp)
   {
	   cout << "Derived:DoSth(int)\n";
   }
   using Base::DoSth;	// brings the other Base::DoSth overloads into scope
};
</pre>
<p>Please mind that <strong>using declaration</strong> was added: <code>using Base::DoSth;</code>. Check <a href="http://msdn.microsoft.com/en-US/library/was37tzw(v=VS.90).aspx">description of using declaration at MSDN</a> to get more information if you are still lost.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/81DqNk3RgkBT6pnU4neXZkZMNTc/0/da"><img src="http://feedads.g.doubleclick.net/~a/81DqNk3RgkBT6pnU4neXZkZMNTc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/81DqNk3RgkBT6pnU4neXZkZMNTc/1/da"><img src="http://feedads.g.doubleclick.net/~a/81DqNk3RgkBT6pnU4neXZkZMNTc/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2011/12/10/cpp-overriding-methods-problem-with-hiding-overloads-in-the-base-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CrypTool – understanding cryptography with examples</title>
		<link>http://dobrzanski.net/2011/10/22/cryptool-understanding-cryptography-with-examples/</link>
		<comments>http://dobrzanski.net/2011/10/22/cryptool-understanding-cryptography-with-examples/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 11:47:07 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[cryptography]]></category>
		<category><![CDATA[PKI]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=788</guid>
		<description><![CDATA[One of the sessions I liked most on Microsoft Technology Summit 2011 was one delivered by Krzysztof Bińkowski &#8211; it was about certificates and PKI in context of Windows Server 2008. I&#8217;m not going to describe the session here, but wanted to share the tool that might help better understand the world of cryptography. To [...]]]></description>
			<content:encoded><![CDATA[<p>One of the sessions I liked most on <a href="http://www.mtskonferencja.pl/">Microsoft Technology Summit 2011</a> was one delivered by <a href="http://securityforensics.wordpress.com/">Krzysztof Bińkowski</a> &#8211; it was about certificates and PKI in context of Windows Server 2008. I&#8217;m not going to describe the session here, but wanted to share the tool that might help better understand the world of cryptography.</p>
<p>To better explain theory provided on his slides, Krzysztof used <a href="http://www.cryptool.org/">CrypTool</a>. Let me cite the authors of this tool to give you a basic idea on what CrypTool is:</p>
<blockquote><p>CrypTool is a free, open-source e-learning application, used worldwide in the implementation and analysis of cryptographic algorithms. It supports both contemporary teaching methods at schools and universities as well as awareness training for employees and civil servants.</p></blockquote>
<p><span id="more-788"></span></p>
<p>I think this is a great tool that can be used to systematize knowledge related to cryptography, e.g. hash functions, digital signature, PKI. You can play around with CrypTool and see on the fly how different methodologies / algorithms work and what they require. What I liked most were the flow diagrams that visualize how some techniques (e.g. digital signare generation, hybrid cryptography) work step by step and see the intermittent results (see below).</p>
<p><a href="http://dobrzanski.net/wp-content/uploads/2011/10/sig_gen.png" rel="lightbox[788]"><img src="http://dobrzanski.net/wp-content/uploads/2011/10/sig_gen-350x339.png" alt="sig gen 350x339 CrypTool   understanding cryptography with examples" title="Digital signature generation step by step (taken from official CrypTool presentation)" width="350" height="339" class="alignnone size-medium wp-image-791" /></a></p>
<p>P.S. I used CrypTool 1.4.30 but there&#8217;s also CrypTool 2.0 (still beta) available at the official web site.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/iBRDzPeH228BStgSyibiygqIqXE/0/da"><img src="http://feedads.g.doubleclick.net/~a/iBRDzPeH228BStgSyibiygqIqXE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iBRDzPeH228BStgSyibiygqIqXE/1/da"><img src="http://feedads.g.doubleclick.net/~a/iBRDzPeH228BStgSyibiygqIqXE/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2011/10/22/cryptool-understanding-cryptography-with-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book review: LINQ Unleashed for C#</title>
		<link>http://dobrzanski.net/2010/10/10/linq-unleashed-for-csharp-book-review/</link>
		<comments>http://dobrzanski.net/2010/10/10/linq-unleashed-for-csharp-book-review/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 10:53:30 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=779</guid>
		<description><![CDATA[I find this book relevant and very informative. If you want to master LINQ lingo, just read it. For broader evaluation see my review on DZone. P.S. DZone&#8217;s IT Book Zone is another great initiative. In short DZone gives you a free copy of a book and expects to receive its review in return. Fair [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dobrzanski.net/wp-content/uploads/2010/10/linq_unleashed.jpg" rel="lightbox[779]"><img src="http://dobrzanski.net/wp-content/uploads/2010/10/linq_unleashed.jpg" alt="linq unleashed Book review: LINQ Unleashed for C#" title="linq_unleashed" width="160" height="160" class="alignleft size-full wp-image-780" /></a></p>
<p>I find this book relevant and very informative. If you want to master LINQ lingo, just read it.</p>
<p>For broader evaluation see <a href="http://www.dzone.com/reviews/book-review-linq-unleashed-c">my review on DZone</a>.</p>
<p>P.S. <a href="http://books.dzone.com/">DZone&#8217;s IT Book Zone</a> is another great initiative. In short DZone gives you a free copy of a book and expects to receive its review in return. Fair agreement &#8211; one can stretch the envelope of IT domains for free, while DZone broadens thier public resources.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/bNNYpu8YxwnZ9fsm0evMr8uup1g/0/da"><img src="http://feedads.g.doubleclick.net/~a/bNNYpu8YxwnZ9fsm0evMr8uup1g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bNNYpu8YxwnZ9fsm0evMr8uup1g/1/da"><img src="http://feedads.g.doubleclick.net/~a/bNNYpu8YxwnZ9fsm0evMr8uup1g/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2010/10/10/linq-unleashed-for-csharp-book-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSTest: Unit Test Adapter threw exception: Type is not resolved for member XXX</title>
		<link>http://dobrzanski.net/2010/09/20/mstest-unit-test-adapter-threw-exception-type-is-not-resolved-for-member/</link>
		<comments>http://dobrzanski.net/2010/09/20/mstest-unit-test-adapter-threw-exception-type-is-not-resolved-for-member/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 06:49:32 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=773</guid>
		<description><![CDATA[This was not an easy one&#8230; I was trying to run a unit test with MSTest but I was always getting the following error: Unit Test Adapter threw exception: Type is not resolved for member &#8216;XXX,XXX Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; As usual in such case &#8211; a message which does not really say what&#8217;s wrong. I [...]]]></description>
			<content:encoded><![CDATA[<p>This was not an easy one&#8230; I was trying to run a unit test with MSTest but I was always getting the following error:<br />
<strong>Unit Test Adapter threw exception: Type is not resolved for member &#8216;XXX,XXX Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217;</strong></p>
<p>As usual in such case &#8211; a message which does not really say what&#8217;s wrong. I googled the problem but there was not much about it on the web. The best resource I found was post titled <a href="http://thisthattechnology.blogspot.com/2009/03/vsts-unit-test-type-is-not-resolved.html">VSTS Unit Test &#8216;Type is not resolved&#8217; exception</a>. It describes how VSTestHost process runs the test and explains what the possible problem might be in this case. </p>
<p>The author suggests that data required for test (e.g. a dll file) is not found in base directory for AppDomain (i.e. unit test &#8216;Out&#8217; directory) because it&#8217;s already switched back to directory that holds VSTestHost.exe. There are two links to MSDN given where Microsoft admits this is a known bug and provides a hack to work around the problem &#8211; supply VSTestHost with copies of required artifacts (again, this is described in details in above mentioned post). </p>
<p>Unfortunately that didn&#8217;t work with my case. I&#8217;ve found the root cause though&#8230;</p>
<p><span id="more-773"></span></p>
<h2>Solution</h2>
<p>Now, to be more precise, that error message was telling me the member whose type was unresolved was a class with implementation of my custom exception. For the sake of the example let&#8217;s assume that the message I was getting looked as below:<br />
<strong>Unit Test Adapter threw exception: Type is not resolved for member &#8216;MyCustomException,TestProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217;</strong>,<br />
where TestProject is the project in which I wrote MyCustomException class.</p>
<p>This information implied something wrong was happening at the the very beginning of the test &#8211; exception might be thrown between class initialization (MSTest ClassInitialize) and class constructor or fields&#8217; definition. I analyzed, line by line, the earliest logic looking for an invocation that could throw MyCustomException, and I found it&#8230; MyCustomException was thrown at the definition of one of the class fields. With that fixed, the test was running without problems.</p>
<p>To recap, MyCustomException was thrown at very early stage of test execution. The dll that contained it was not loaded yet so Unit Test Adapter indeed could not reach it. The general idea provided in the referred post really matched my problem. However, in details the root cause in my case was slightly different.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/BR_d-Z0Ldz8cj1XtckIyeh-OZL4/0/da"><img src="http://feedads.g.doubleclick.net/~a/BR_d-Z0Ldz8cj1XtckIyeh-OZL4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/BR_d-Z0Ldz8cj1XtckIyeh-OZL4/1/da"><img src="http://feedads.g.doubleclick.net/~a/BR_d-Z0Ldz8cj1XtckIyeh-OZL4/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2010/09/20/mstest-unit-test-adapter-threw-exception-type-is-not-resolved-for-member/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C#: GetHashCode() might cause OverflowException</title>
		<link>http://dobrzanski.net/2010/09/13/csharp-gethashcode-cause-overflowexception/</link>
		<comments>http://dobrzanski.net/2010/09/13/csharp-gethashcode-cause-overflowexception/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 07:29:37 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=760</guid>
		<description><![CDATA[Microsoft recommends if you overload Equals method you should also overload GetHashCode. Now, how to properly implement GetHashCode? There are many resources on the web that describe it. A good starting point might be this article on Stack Overflow. Following MSDN guidlines GetHashCode must fulfill these requirements: If two objects of the same type represent [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/ms173147%28VS.80%29.aspx">Microsoft recommends</a> if you overload Equals method you should also overload GetHashCode. Now, how to properly implement GetHashCode? There are many resources on the web that describe it. A good starting point might be <a href="http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode">this article on Stack Overflow</a>. </p>
<p>Following <a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode%28v=VS.80%29.aspx">MSDN guidlines</a> GetHashCode must fulfill these requirements: </p>
<ul>
<li>If two objects of the same type represent the same value, the hash function must return the same constant value for either object.</li>
<li>For the best performance, a hash function must generate a random distribution for all input.</li>
<li>The hash function must return exactly the same value regardless of any changes that are made to the object.</li>
</ul>
<p>Sticking to first bullet, you (probably?) should consider the same fields in Equals and GetHashCode methods. Let&#8217;s have a look at the example in which I did so:</p>
<pre name="code" class="c-sharp">public class Contact
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public override bool Equals(object obj)
    {
        // If parameter is null return false.
        if (obj == null)
        {
            return false;
        }

        // If parameter cannot be cast to Contact return false.
        Contact c = obj as Contact;
        if c == null)
        {
            return false;
        }

        // Return true if the fields match:
        return ID == c.ID
            &#038;&#038; FirstName == c.FirstName
            &#038;&#038; LastName == c.LastName;;
    }

    public override int GetHashCode()
    {
        return ID.GetHashCode()
            + FirstName.GetHashCode()
            + LastName.GetHashCode();
    }
}
</pre>
<p>Now, what is wrong with this example of GetHashCode? There&#8217;s one drawback here. The hash is calculated as a sum of three integer values, which might give a value that is greater than int.MaxValue and that will result in OverflowException.</p>
<p><span id="more-760"></span></p>
<p>Default configuration of C# project results in this exception being swallowed so you won&#8217;t experience that problem. However, you can enforce checking for arithmetic overflow / underflow in project settings, advanced settings in build section:</p>
<p><a href="http://dobrzanski.net/wp-content/uploads/2010/09/project_settings.jpg" rel="lightbox[760]"><img src="http://dobrzanski.net/wp-content/uploads/2010/09/project_settings-350x298.jpg" alt="project settings 350x298 C#: GetHashCode() might cause OverflowException" title="C# project settings - advanced build options" width="350" height="298" class="alignnone size-medium wp-image-761" /></a></p>
<p>Once you do this, it&#8217;s highly possible an OverflowException will occur in your application. Therefore it might be useful to turn on checking for arithmetic overflow / underflowo only in Debug mode.</p>
<p>One way or the other, implementation of hash method presented above needs to be improved. </p>
<h2>Solution</h2>
<h3>Operation on bits</h3>
<p>One possible solution would be to change + operator to one that operates on bits, e.g. ^ (XOR). That&#8217;s bitwise exclusive-OR, whose result for two integers will always fit an integer value.</p>
<pre name="code" class="c-sharp">public override int GetHashCode()
{
    return ID.GetHashCode()
        ^ FirstName.GetHashCode()
        ^ LastName.GetHashCode();
}
</pre>
<h3>Use unchecked</h3>
<p>In an unchecked context, if an expression produces a value that is outside the range of the destination type, the result is truncated. That&#8217;s enough for GetHashCode.</p>
<pre name="code" class="c-sharp">public override int GetHashCode()
{
    unchecked
    {
        return ID.GetHashCode()
        + FirstName.GetHashCode()
        + LastName.GetHashCode();
    }
}
</pre>
<p>To learn more on unchecked and checked, please refer to <a href="http://theburningmonk.com/2010/05/understanding-arithmetic-overflow-checking-in-c-sharp/">this post</a> or <a href="http://www.codeproject.com/KB/cs/overflow_checking.aspx">that article on Code Project</a>.</p>
<h2>Conclusion</h2>
<p>I presented two possible fixes for risk of OverflowException thrown in GetHashCode. Now, you might expect an answer which solution is better. I honestly don&#8217;t know. Probably there are scientific papers that elaborate on that. All I can say both both options do what they should.</p>
<p>By the way, if you speak on better uniqueness of the calculated hash, you might include prime numbers as a carefully selected random number multiplier, which in details is described <a href="http://computinglife.wordpress.com/2008/11/20/why-do-hash-functions-use-prime-numbers/">there</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/LwTpvWAAQaAIPpfzfeefToXcApU/0/da"><img src="http://feedads.g.doubleclick.net/~a/LwTpvWAAQaAIPpfzfeefToXcApU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LwTpvWAAQaAIPpfzfeefToXcApU/1/da"><img src="http://feedads.g.doubleclick.net/~a/LwTpvWAAQaAIPpfzfeefToXcApU/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2010/09/13/csharp-gethashcode-cause-overflowexception/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>It’s possible to support this blog</title>
		<link>http://dobrzanski.net/2010/09/04/its-possible-to-support-this-blog/</link>
		<comments>http://dobrzanski.net/2010/09/04/its-possible-to-support-this-blog/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 09:10:36 +0000</pubDate>
		<dc:creator>Jarosław Dobrzański</dc:creator>
				<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://dobrzanski.net/?p=756</guid>
		<description><![CDATA[A few days ago I decided to add &#8216;Donate&#8217; button on my blog (see the sidebar to the right). This is a feature provided by PayPal. If you want to prove you are really delighted with my help or simply you have too much spare money , it&#8217;s possible to pay me a kind of [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I decided to add &#8216;Donate&#8217; button on my blog (see the sidebar to the right). This is a feature provided by PayPal.</p>
<p>If you want to prove you are really delighted with my help or simply you have too much spare money <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Its possible to support this blog" class='wp-smiley' title="Its possible to support this blog Photo" /> , it&#8217;s possible to pay me a kind of tip. That can be a dollar or two, that&#8217;s not really important; every little helps. All in all that could help pay for the hosting. </p>
<p>Of course I&#8217;m still blogging for fun so treat this as a feature &#8211; use it only if you really want to <img src='http://dobrzanski.net/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Its possible to support this blog" class='wp-smiley' title="Its possible to support this blog Photo" /> </p>

<p><a href="http://feedads.g.doubleclick.net/~a/a0axyb-ZgoHozW9FbZWtVaFr8I8/0/da"><img src="http://feedads.g.doubleclick.net/~a/a0axyb-ZgoHozW9FbZWtVaFr8I8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/a0axyb-ZgoHozW9FbZWtVaFr8I8/1/da"><img src="http://feedads.g.doubleclick.net/~a/a0axyb-ZgoHozW9FbZWtVaFr8I8/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://dobrzanski.net/2010/09/04/its-possible-to-support-this-blog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 0.359 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-02 12:54:13 -->

