<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.brokenwire.net/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-us"><title type="text">Brokenwire.NET</title>
<subtitle type="text">Stuff about programming... and more</subtitle>

<link rel="alternate" type="text/html" href="http://www.brokenwire.net/bw/" />
<id>tag:www.brokenwire.net,2005:241f6adfa9f57b1a204d945d0bd1c51e</id>
<generator uri="http://textpattern.com/" version="4.2.0">Textpattern</generator>
<updated>2012-02-02T13:40:33Z</updated>
<author>
		<name>Thijs Kroesbergen</name>
		
		<uri>http://www.brokenwire.net/bw/</uri>
</author>

<feedburner:info uri="brokenwire" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://www.brokenwire.net/bw/rss" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://www.brokenwire.net/bw/rss" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fwww.brokenwire.net%2Fbw%2Frss" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2011-11-23T21:02:25Z</published>
		<updated>2011-11-23T21:26:56Z</updated>
		<title type="html">ChristmasLights review [2]</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/0deSB81MxKQ/christmaslights-review" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/0ee70aaabc4948b345e56fb581ae3ab9</id>
		
		
		
<content type="html">
&lt;p&gt;It has become a annual tradition for me to release a new version of the “&lt;a href="http://www.brokenwire.net/ChristmasLights/publish.htm"&gt;WPF Christmaslights&lt;/a&gt;” every year. I try to add something fresh to the application every time. The reason for doing so is because it’s fun to do and it allows me to experiment with different technologies. I’ve actually spent very little time on this application, but it’s fun to see it running on the desktops of my co-workers. &lt;/p&gt;  &lt;p&gt;Therefore I was surprised to hear that the &lt;a href="http://www.brokenwire.net/ChristmasLights/publish.htm"&gt;ChristmasLights&lt;/a&gt; application was reviewed by &lt;a href="http://christmaslights.software.informer.com/"&gt;Software Informer&lt;/a&gt;, and even better the the review comments are even quite good :). This is what they wrote about my app:&lt;/p&gt;  &lt;blockquote&gt;   &lt;h5&gt;Review&lt;/h5&gt; At Christmas, many people like to decorate not only their houses and offices, but also their computer desktops. If you are one of those people, then this little and free program will come in handy for you. It consists in a virtual garland of light bulbs that light on an off and change their color according to a set pattern, just as those lights you use to decorate your Christmas tree or the front of your house. The garland surrounds your desktop and it remains always on top, so you can watch the lights even if you have another program's window open.     &lt;br /&gt;The program can be customized in several ways. For example, you can adjust the space between the bulbs as well as their blinking speed. You can program the lights to blink automatically, or as you type, or following the rhythm of the music that is playing in your media player. The program also offers different types of blinking, such as standard blinking, interlaced, flashing, and some more. Also, you can adjust the intensity of the lights colors.     &lt;br /&gt;In sum, if you enjoy Christmas and want to add a beautiful ornament to your desktop for the upcoming holidays, then you may want to try this one. &lt;/blockquote&gt;  &lt;p&gt;And guess what, it got a 5 star review!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://Software.informer.com"&gt;Software.informer.com&lt;/a&gt; would like to inform you that your product ChristmasLights 1.0 has been reviewed by our editors and your program got &amp;quot;5* Editor's Pick Award&amp;quot; &lt;a href="http://christmaslights.software.informer.com/"&gt;http://christmaslights.software.informer.com/&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://christmaslights.software.informer.com/" target="_blank"&gt;&lt;img style="display: inline" border="0" alt="Software.Informer Editor&amp;#39;s pick award" src="http://img.informer.com/awards/si_editor5.gif" width="166" height="111" /&gt;&lt;/a&gt;&lt;a href="http://christmaslights.software.informer.com/"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" border="0" src="http://www.brokenwire.net/bw/images/132.png" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nice huh? :)&lt;/p&gt;  &lt;p&gt;If you want to see how the application works, if you want to contribute or if you want to report bugs you should visit the &lt;a href="http://wpfxmaslights.codeplex.com/"&gt;project page on Codeplex&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So tell me, what new features do you want to see in this years update?&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-Pbvg9bETBQBVEW3IOw2JbLr2U4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Pbvg9bETBQBVEW3IOw2JbLr2U4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-Pbvg9bETBQBVEW3IOw2JbLr2U4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Pbvg9bETBQBVEW3IOw2JbLr2U4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=0deSB81MxKQ:JmUzX5LnXb8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=0deSB81MxKQ:JmUzX5LnXb8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=0deSB81MxKQ:JmUzX5LnXb8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=0deSB81MxKQ:JmUzX5LnXb8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=0deSB81MxKQ:JmUzX5LnXb8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/0deSB81MxKQ" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Various/131/christmaslights-review</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-12-10T18:02:52Z</published>
		<updated>2010-12-10T19:11:43Z</updated>
		<title type="html">Quick Tip: VirtualBox sound on Windows Server 2008R2 x64</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/pGwtEDOe3Qo/quick-tip-virtualbox-sound-on-windows-server-2008r2-x64" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/f53b749257b7303bb88c9bdfef04cd27</id>
		<category term="M" />
		
		
<content type="html">
&lt;p&gt;To enable audio for a Windows Server 2008 (and most probably also on windows 7) guest in VirtualBox you can get the generic AC'97 Audio Codecs from the realtek website:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.realtek.com/downloads/downloadsCheck.aspx?Langid=1&amp;amp;PNid=23&amp;amp;PFid=23&amp;amp;Level=4&amp;amp;Conn=3&amp;amp;DownTypeID=3&amp;amp;GetDown=false" href="http://www.realtek.com/downloads/downloadsCheck.aspx?Langid=1&amp;amp;PNid=23&amp;amp;PFid=23&amp;amp;Level=4&amp;amp;Conn=3&amp;amp;DownTypeID=3&amp;amp;GetDown=false"&gt;http://www.realtek.com/downloads/downloadsCheck.aspx?Langid=1&amp;amp;PNid=23&amp;amp;PFid=23&amp;amp;Level=4&amp;amp;Conn=3&amp;amp;DownTypeID=3&amp;amp;GetDown=false&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The zip file is about 30 mb, seems like a lot of bytes for just a sound driver… but hey, it works.&lt;/p&gt;  &lt;p&gt;Just download and extract the zip file to a folder, then point the device manager to that folder and let it install the driver.&lt;/p&gt;  &lt;p&gt;Update:&lt;/p&gt;  &lt;p&gt;If you want to play sounds using the WPF &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.aspx" target="_blank"&gt;MediaPlayer&lt;/a&gt; class then you also need to have Media Player (at least version 10) installed. To do that on Windows Server you need to install the “Desktop Experience” feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dqR_i9gmOv2ncPLXupZ6cg5X-8s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dqR_i9gmOv2ncPLXupZ6cg5X-8s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dqR_i9gmOv2ncPLXupZ6cg5X-8s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dqR_i9gmOv2ncPLXupZ6cg5X-8s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=pGwtEDOe3Qo:JJ4DAG5LOAI:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=pGwtEDOe3Qo:JJ4DAG5LOAI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=pGwtEDOe3Qo:JJ4DAG5LOAI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=pGwtEDOe3Qo:JJ4DAG5LOAI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=pGwtEDOe3Qo:JJ4DAG5LOAI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/pGwtEDOe3Qo" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Various/129/quick-tip-virtualbox-sound-on-windows-server-2008r2-x64</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-12-08T15:13:11Z</published>
		<updated>2010-12-08T15:37:38Z</updated>
		<title type="html">How to unittest internals</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/QygC-PoXdsg/how-to-unittest-internals" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/7a8d98d63a9ca668ed46b26d5825217f</id>
		<category term="M" />
		<category term="NET" />
		
<content type="html">
&lt;p&gt;&lt;em&gt;This how-to is written by &lt;/em&gt;&lt;a href="http://www.twitter.com/margroot" target="_blank"&gt;&lt;em&gt;Mark Groot&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, and published on here on &lt;a href="http://www.brokenwire.net/" target="_blank"&gt;Brokenwire.net&lt;/a&gt; with his permission.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Normally when you try to unit test a method from an internal class, u will receive a message saying something like ‘… is inaccessible due to its protectionlevel’. The typical response in these kind of situations is either ‘ah, f.. it. I’ll just skip this test’ or ‘I’ll just make the class public. Who cares.’.&lt;/p&gt;  &lt;p&gt;What you actually want to do is to make the internal method accessible to your unit test project. As it turns out, that this isn’t really all that difficult. Visual Studio will do most work for you. There are however a few things u have to keep in mind. In this article I will stretch out on those things.&lt;/p&gt;  &lt;p&gt;First, let’s make a little console app which contains an internal class. (The entire solution can be downloaded &lt;a href="http://www.brokenwire.net/bw/file_download/27/coinflip.zip" target="_blank"&gt;here&lt;/a&gt;).&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ICoinFlip
{
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; YouWon(&lt;span class="kwrd"&gt;bool&lt;/span&gt; choiceIsHead);
}


&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CoinFlip : ICoinFlip
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; CoinFlip()
  {
  }

  &lt;span class="kwrd"&gt;bool&lt;/span&gt; ICoinFlip.YouWon(&lt;span class="kwrd"&gt;bool&lt;/span&gt; choiceIsHead)
  {
      &lt;span class="rem"&gt;// You can only win if you pick head&lt;/span&gt;
      &lt;span class="rem"&gt;// This is stupid, but that is not the point here&lt;/span&gt;
      &lt;span class="kwrd"&gt;return&lt;/span&gt; choiceIsHead;
  }
}

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
  ICoinFlip flip = &lt;span class="kwrd"&gt;new&lt;/span&gt; CoinFlip();
            
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; coinSideIsHead = (&lt;span class="kwrd"&gt;new&lt;/span&gt; Random()).Next(0, 2) == 1;

  &lt;span class="kwrd"&gt;if&lt;/span&gt; (flip.YouWon(&lt;span class="kwrd"&gt;true&lt;/span&gt;) == coinSideIsHead)
    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;You win!&amp;quot;&lt;/span&gt;);
  &lt;span class="kwrd"&gt;else&lt;/span&gt;
    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;You lose!&amp;quot;&lt;/span&gt;);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;When you run this code you will get a nice little console window telling u whether or not you won. &lt;/p&gt;

&lt;p&gt;Now how to test this? There are a few steps you have to take.&lt;/p&gt;

&lt;h2&gt;Let Visual Studio create a unittest and a unit test project for you.&lt;/h2&gt;

&lt;p&gt;You can create a unit test for the YouWon method by right-clicking the method and selecting ‘Create Unit Tests…’ from the contextmenu.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/128.png" /&gt;&lt;/p&gt;

&lt;p&gt;Clicking the menu option will popup the following window.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/129.png" /&gt;&lt;/p&gt;

&lt;p&gt;In the treeview you can select additional methods for which you want to create unit tests. You have to select a project from the listview in which the test has to be created.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/130.png" /&gt;&lt;/p&gt;

&lt;p&gt;Now Visual Studio will create a test class for the selected method in your selected unit test project including all the necessary references. &lt;/p&gt;

&lt;p&gt;Visual Studio will also add the assembly:&lt;a href="http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx" target="_blank"&gt;InternalsVisibleTo&lt;/a&gt; attribute to the AssemblyInfo file of your console application.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&lt;span class="str"&gt;&amp;quot;coinflipTest&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;By using this attribute the unit test assembly will become a “friend assembly ” of the main assembly, and therefore the main assembly will allow the test assembly access to its internals.&lt;/p&gt;

&lt;h2&gt;Edit the test method&lt;/h2&gt;

&lt;p&gt;Visual Studio will generate a TestMethod in the new test class looking like this:&lt;/p&gt;

&lt;p&gt;After some clean up the code looks like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[TestMethod()]
[DeploymentItem(&lt;span class="str"&gt;&amp;quot;coinflip.exe&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; YouWonTest()
{
  ICoinFlip target = &lt;span class="kwrd"&gt;new&lt;/span&gt; CoinFlip();
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; choiceIsHead = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; expected = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; actual;
  actual = target.YouWon(choiceIsHead);
  Assert.AreEqual(expected, actual);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;We enter the value &lt;b&gt;&lt;i&gt;false&lt;/i&gt;&lt;/b&gt; into the method and we expect to receive a value &lt;b&gt;&lt;i&gt;false&lt;/i&gt;&lt;/b&gt; back. If that is true, then the test passed.&lt;/p&gt;

&lt;h3&gt;&lt;i&gt;&lt;strong&gt;The following steps are only necessary when you have a strongly signed project:&lt;/strong&gt;&lt;/i&gt;&lt;/h3&gt;

&lt;p&gt;Find the public key of your unit test project&lt;/p&gt;

&lt;p&gt;There was a time where finding the public key token using sn –T was enough. Now however, the InternalsVisibleTo&amp;#160; attribute uses the public key.
  &lt;br /&gt;We can retrieve that key in two steps by using the sn.exe tool.

  &lt;br /&gt;First create a file with the public key from the assembly key file using the following command (inside a Visual Studio command prompt)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;sn –p &lt;i&gt;NameOfYourKeyFile&lt;/i&gt;.snk &lt;i&gt;NameOfYourOutputFile&lt;/i&gt;.PublicKey.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use the output file to retrieve the public key with the –tp option of sn.exe: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;sn –tp &lt;i&gt;NameOfYourOutputFile&lt;/i&gt;.PublicKey.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The result is some text and a large key looking like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Microsoft (R) .NET Framework Strong Name Utility&amp;#160; Version 4.0.30319.1
    &lt;br /&gt;Copyright (c) Microsoft Corporation.&amp;#160; All rights reserved.&lt;/p&gt;

  &lt;p&gt;Public key is
    &lt;br /&gt;00240000048000009400000006020000002400005253413100040000010001003b825be7fe7e93

    &lt;br /&gt;f782f0ff49cb2c86845698b15301834dc63cf9b9c62ea95aa02151a069cafb82f1902dfec1e2be

    &lt;br /&gt;16b7f05d99e84a5796060d044ab62a1bcc6ffc7d12ab03827c22b4a70a67797bc82aea51a6c9b9

    &lt;br /&gt;c31fee99410dbbc54b32dd9b18f202e97912b967120d4655a8575a2568738e7a08b662a0004440

    &lt;br /&gt;91d500cf&lt;/p&gt;

  &lt;p&gt;Public key token is de3fc1b9aa83af40&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then add the key into the AssemblyInfo of the console application.&lt;/p&gt;

&lt;p&gt;As we saw before, when we created the unit test the following entry was created in the AssemblyInfo file:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&lt;span class="str"&gt;&amp;quot;coinflipTest&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;You have to change this into:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&lt;span class="str"&gt;&amp;quot;coinflipTest, PublicKey=PASTE-YOUR-PUBLIC-KEY-HERE&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Here you copy-paste the public key from the previous step into the marked section. You will have to remove the linebreaks, but that should be rather obvious. Don’t copy the key shown here, you have to use your own key…&lt;/p&gt;

&lt;p&gt;To see if this works: build the project, and run the test.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TEkDGR0pUHktoxW7_EHu9VYhP1U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TEkDGR0pUHktoxW7_EHu9VYhP1U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TEkDGR0pUHktoxW7_EHu9VYhP1U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TEkDGR0pUHktoxW7_EHu9VYhP1U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=QygC-PoXdsg:mzfbdHr3hvI:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=QygC-PoXdsg:mzfbdHr3hvI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=QygC-PoXdsg:mzfbdHr3hvI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=QygC-PoXdsg:mzfbdHr3hvI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=QygC-PoXdsg:mzfbdHr3hvI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/QygC-PoXdsg" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Programming/128/how-to-unittest-internals</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-10-12T11:43:23Z</published>
		<updated>2010-10-12T11:43:24Z</updated>
		<title type="html">Equals is not Differs</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/dejyW_i5wCM/equals-is-not-differs" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/c3e8e0acc932d7ee9fecdd9d14187c8f</id>
		<category term="M" />
		<category term="NET" />
		
<content type="html">
&lt;p&gt;Just a small code snippet I wanted to share with you… (it made me laugh and cry at the same time)&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Equals(Adres a2)
{
    &lt;span class="kwrd"&gt;return&lt;/span&gt; !Differs(a2);
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Differs(Adres a2)
{
    &lt;span class="kwrd"&gt;return&lt;/span&gt; (a2 == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Straat != a2.Straat)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Huisnummer != a2.Huisnummer)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Postcode != a2.Postcode)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Plaats != a2.Plaats)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.DatumIngang != a2.DatumIngang)
    || (!&lt;span class="kwrd"&gt;this&lt;/span&gt;.DatumEinde.HasValue &amp;amp;&amp;amp; a2.DatumEinde.HasValue)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.DatumEinde.HasValue &amp;amp;&amp;amp; !a2.DatumEinde.HasValue)
    || (&lt;span class="kwrd"&gt;this&lt;/span&gt;.DatumEinde.HasValue &amp;amp;&amp;amp; a2.DatumEinde.HasValue &amp;amp;&amp;amp; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.DatumEinde.Value != a2.DatumEinde.Value))
    ;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Watch, learn, don’t repeat. Share the pain in the comments.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1aKLRHz-Q9Xqae1gMGD6tQkvzcg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1aKLRHz-Q9Xqae1gMGD6tQkvzcg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1aKLRHz-Q9Xqae1gMGD6tQkvzcg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1aKLRHz-Q9Xqae1gMGD6tQkvzcg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=dejyW_i5wCM:FqI7Fk51pWw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=dejyW_i5wCM:FqI7Fk51pWw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=dejyW_i5wCM:FqI7Fk51pWw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=dejyW_i5wCM:FqI7Fk51pWw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=dejyW_i5wCM:FqI7Fk51pWw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/dejyW_i5wCM" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Programming/126/equals-is-not-differs</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-10-06T14:48:59Z</published>
		<updated>2010-10-06T14:58:59Z</updated>
		<title type="html">Querying XML fields using t-sql [2]</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/tokrA6-G5Ng/querying-xml-fields-using-t-sql" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/ac5ac3351255f85ed40052a355fb7b6c</id>
		
		
		
<content type="html">
&lt;p&gt;Recently I got several questions about this topic, so I thought it would be nice to write a little bit about how to use XML inside SQL Server.&lt;/p&gt;  &lt;p&gt;First of all: &lt;strong&gt;*don’t* &lt;/strong&gt;query XML using substring(), pos() and other string manipulations. If you still do ugly stuff like that then you &lt;strong&gt;have &lt;/strong&gt;to read this article and you also have to buy a big pie for your co-workers.&lt;/p&gt;  &lt;p&gt;So we had this project where we had several nvarchar(max) fields which actually contained xml documents. This way of storing XML is fine when you don’t need to look inside the xml data itself. But when you want to use the data inside the xml documents its convenient to use the &lt;a href="http://msdn.microsoft.com/en-us/library/ms189887%28SQL.90%29.aspx" target="_blank"&gt;xml datatype&lt;/a&gt;. This datatype is available from Sql Server 2005 and up. In this post i’ll try to introduce you to the magical world of XML inside sql server.&lt;/p&gt;  &lt;p&gt;All examples below are in &lt;a href="http://www.brokenwire.net/bw/file_download/26/xmldemo.sql" target="_blank"&gt;this downloadable xmldemo.sql file&lt;/a&gt;, so you can easily try them yourself.&lt;/p&gt;  &lt;h2&gt;Xml Datatype&lt;/h2&gt;  &lt;p&gt;The Xml datatype allows you to perform several operations on the xml data from within t-sql. Although this is not very fast, it’s often better than round-tripping and doing the xml parsing in your application layers.&lt;/p&gt;  &lt;p&gt;You can use the xml datatype just like any other datatype. You can use it for tables, table variables and also for regular variables and procedure/function parameters.&lt;/p&gt;  &lt;h2&gt;Example&lt;/h2&gt;  &lt;p&gt;This creates a table with one column of the xml datatype and inserts one row with a (simple) XML document:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;table&lt;/span&gt; #demo (field1 xml)
insert &lt;span class="kwrd"&gt;into&lt;/span&gt; #demo (field1) 
&lt;span class="kwrd"&gt;values&lt;/span&gt; (&lt;span class="str"&gt;'&amp;lt;document&amp;gt;
&amp;lt;header&amp;gt;Alphabet&amp;lt;/header&amp;gt;
&amp;lt;items&amp;gt;
&amp;lt;item id=&amp;quot;a&amp;quot;&amp;gt;a is for apple&amp;lt;/item&amp;gt;
&amp;lt;item id=&amp;quot;b&amp;quot;&amp;gt;b is for balloon&amp;lt;/item&amp;gt;
&amp;lt;/items&amp;gt;
&amp;lt;/document&amp;gt;'&lt;/span&gt;)&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;As you can observe the document structure is like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;document&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Alphabet&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;items&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;item&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;a is for apple&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;item&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;item&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;b is for balloon&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;item&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;items&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;document&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;Now the cool thing is that there are &lt;a href="http://msdn.microsoft.com/en-us/library/ms190798%28SQL.90%29.aspx" target="_blank"&gt;several methods&lt;/a&gt; that can be executed on the Xml datatype, such as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Query &lt;/li&gt;

  &lt;li&gt;Value &lt;/li&gt;

  &lt;li&gt;Exists &lt;/li&gt;

  &lt;li&gt;Modify &lt;/li&gt;

  &lt;li&gt;Nodes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this brief introduction I’ll highlight the usage of the Value and Query methods. All methods are well documented in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms190798%28SQL.90%29.aspx" target="_blank"&gt;MSDN library&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Query&lt;/h2&gt;

&lt;p&gt;To get the “header” tag from our example xml document a query like this could be used:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; field1.query(&lt;span class="str"&gt;'/document/header'&lt;/span&gt;) &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;This would return only the &amp;lt;header&amp;gt; element, with its contents. The language used to write the query is called “&lt;a href="http://www.w3.org/XML/Query/" target="_blank"&gt;XQuery&lt;/a&gt;”, which is an XPath based query language &lt;a href="http://www.w3.org/TR/xquery/" target="_blank"&gt;defined by W3C&lt;/a&gt;. But be warned, only a subset of the official language is supported.&lt;/p&gt;

&lt;p&gt;Say you’d like to get the xml node which has an “id” attribute with a value of “a”. You can use a query like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; field1.query(&lt;span class="str"&gt;'/document/items/item[@id=&amp;quot;a&amp;quot;]'&lt;/span&gt;) &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;This would return only the first of the two &amp;lt;item&amp;gt; elements, as an XML fragment in an XML field. If you are puzzeled by the syntax here, then please take a moment to look at &lt;a href="http://msdn.microsoft.com/en-us/library/ms256086.aspx" target="_blank"&gt;these examples&lt;/a&gt;, that’ll give you a quick start.&lt;/p&gt;

&lt;h2&gt;Value&lt;/h2&gt;

&lt;p&gt;The value method is one of the methods that I personally have used the most. With this method you can select contents from an XML field and convert it to a “regular” sql datatype (also known as scalar values).&lt;/p&gt;

&lt;p&gt;So…&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; field1.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'(/document/items/item)[1]'&lt;/span&gt;, &lt;span class="str"&gt;'nvarchar(max)'&lt;/span&gt;) &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;Will return: “a is for apple”, because we asked for value of the the first [1] node that matched the “/document/items/item” expression.&lt;/p&gt;

&lt;p&gt;But you can use these methods &amp;amp; expressions also in the WHERE clause of a t-sql query. Like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo &lt;span class="kwrd"&gt;where&lt;/span&gt; field1.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'(/document/items/item)[1]'&lt;/span&gt;, &lt;span class="str"&gt;'nvarchar(max)'&lt;/span&gt;) &lt;span class="kwrd"&gt;like&lt;/span&gt; &lt;span class="str"&gt;'a%'&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This statement would return all records which have an xml document in their “field1” column where the value first “item” tag starts with “a”. Please remember: this is nice but it will kill performance if you attempt this on a large table with loads of xml documents in it: in sql 2005 you cannot put indexes on values inside XML field! Sql server 2008 (and up) will let you create &lt;a href="http://msdn.microsoft.com/en-us/library/bb934097.aspx" target="_blank"&gt;XML indexes&lt;/a&gt; as well.&lt;/p&gt;

&lt;h2&gt;Namespaces&lt;/h2&gt;

&lt;p&gt;One of the things I get asked most is how to query xml documents which have one or more xml namespaces associated.&lt;/p&gt;

&lt;p&gt;So lets add another example record&lt;/p&gt;

&lt;pre class="csharpcode"&gt;insert &lt;span class="kwrd"&gt;into&lt;/span&gt; #demo (field1) &lt;span class="kwrd"&gt;values&lt;/span&gt; (&lt;span class="str"&gt;'&amp;lt;document xmlns=&amp;quot;http://www.brokenwire.net/xmldemo&amp;quot;&amp;gt;
&amp;lt;header&amp;gt;Alphabet&amp;lt;/header&amp;gt;
&amp;lt;items&amp;gt;
&amp;lt;item id=&amp;quot;a&amp;quot;&amp;gt;a is for apple&amp;lt;/item&amp;gt;
&amp;lt;item id=&amp;quot;b&amp;quot;&amp;gt;b is for balloon&amp;lt;/item&amp;gt;
&amp;lt;/items&amp;gt;
&amp;lt;/document&amp;gt;'&lt;/span&gt;)&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;Please notice that the only difference is the addition of a namespace.&lt;/p&gt;

&lt;p&gt;Running the first .value method example query on this record will return a NULL value. This is because the xml elements now live inside the “http://www.brokenwire.net/xmldemo” namespace, and the “/document/items/item” xpath expression looks for these elements without a namespace, so it doesn’t find anything in this document.&lt;/p&gt;

&lt;p&gt;To be able to query with namespaces there are (at least) 2 possibilities. You can either completely ignore the namespaces and go directly to the elements you need, or you can declare the namespace and use it properly in your expressions.&lt;/p&gt;

&lt;p&gt;The quick-and-dirty and I-don’t-care-about-namespaces way:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; field1.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'(//*[local-name()=&amp;quot;item&amp;quot;])[1]'&lt;/span&gt;, &lt;span class="str"&gt;'nvarchar(max)'&lt;/span&gt;) &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;p&gt;This expression will work for both the document WITH a namespace and the document WITHOUT a namespace.&lt;/p&gt;

&lt;p&gt;The proper way:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; field1.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'declare namespace bw=&lt;a href="http://www.brokenwire.net/xmldemo"&gt;http://www.brokenwire.net/xmldemo&lt;/a&gt;;&lt;br /&gt;(/bw:document/bw:items/bw:item)[1]'&lt;/span&gt;, &lt;span class="str"&gt;'nvarchar(max)'&lt;/span&gt;) &lt;span class="kwrd"&gt;from&lt;/span&gt; #demo&lt;/pre&gt;

&lt;p&gt;This expression will only work for the document WITH the namespace, because in the other document the elements live in the default namespace.&lt;/p&gt;

&lt;h2&gt;More details&lt;/h2&gt;

&lt;p&gt;If you can’t get enough of this then this &lt;a href="http://msdn.microsoft.com/en-us/library/ms345122%28SQL.90%29.aspx" target="_blank"&gt;introduction to XQuery&lt;/a&gt; article on MSDN is worth reading too. You’ll need a lot more Xpath and Xquery knowledge than covered here to make really good use of the potential powers that are enabled by the xml datatype. Fortunately these are both standardized by W3C, so learning them will enable you to do much more cool stuff.&lt;/p&gt;

&lt;p&gt;And don’t forget, you can post your ideas, notes, thoughts and “&lt;a href="http://plzsendmethecode.blogspot.com/" target="_blank"&gt;please send me the codez&lt;/a&gt;” requests in the comments, that’s what they are for.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.brokenwire.net/bw/file_download/26/xmldemo.sql" target="_blank"&gt;File with demo code for download here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5_8qpOZBx3oNrpIBATrVvzwP43c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5_8qpOZBx3oNrpIBATrVvzwP43c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5_8qpOZBx3oNrpIBATrVvzwP43c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5_8qpOZBx3oNrpIBATrVvzwP43c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=tokrA6-G5Ng:aU1G3OZe8Ds:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=tokrA6-G5Ng:aU1G3OZe8Ds:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=tokrA6-G5Ng:aU1G3OZe8Ds:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=tokrA6-G5Ng:aU1G3OZe8Ds:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=tokrA6-G5Ng:aU1G3OZe8Ds:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/tokrA6-G5Ng" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Programming/125/querying-xml-fields-using-t-sql</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-10-04T11:53:50Z</published>
		<updated>2010-10-04T11:53:51Z</updated>
		<title type="html">Bill Gates in Outlook 2010</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/A9YX22B4cco/bill-gates-in-outlook-2010" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/8f9d6ea0c28d5e8eb3f100b7798b4309</id>
		<category term="Fun-8216n-Games" />
		<category term="M" />
		
<content type="html">
&lt;p&gt;If you have used outlook 2010 you must have seen the new ‘People pane’ which feature the contact information of all people involved in the current item. Last week a colleague pointed out that the gray “Generic User” is supposed to be an image of Bill Gates himself. So lets see…&lt;/p&gt;  &lt;p&gt;The avatar in outlook:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/123.png" /&gt;&lt;/p&gt;  &lt;p&gt;The Bill Gates Mugshot:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/122.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;This mugshot is said to be made when Bill was caught speeding, back in the seventies.&lt;/p&gt;  &lt;p&gt;Now lets combine the two images: &lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/124.png" /&gt;&lt;/p&gt;  &lt;p&gt;And because i’m not very good with Paint.Net you may like this one better (it’s been spreading all over the web since the last few days)&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/125.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Well how about that! These folks at Microsoft sure have a good sense of humor.&lt;/p&gt;  &lt;p&gt;Next question: who is the shadow person used in Google contacts &amp;amp; Gmail?&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/126.png" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LORaj8335-MEENa1KZfTs5EfCr0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LORaj8335-MEENa1KZfTs5EfCr0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LORaj8335-MEENa1KZfTs5EfCr0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LORaj8335-MEENa1KZfTs5EfCr0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=A9YX22B4cco:2wZQlUpXJCw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=A9YX22B4cco:2wZQlUpXJCw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=A9YX22B4cco:2wZQlUpXJCw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=A9YX22B4cco:2wZQlUpXJCw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=A9YX22B4cco:2wZQlUpXJCw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/A9YX22B4cco" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Various/124/bill-gates-in-outlook-2010</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-08-25T14:26:46Z</published>
		<updated>2010-08-25T14:27:30Z</updated>
		<title type="html">Site updated [1]</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/gadyqwA9pnk/site-updated" />
		<id>tag:www.brokenwire.net,2010-08-25:241f6adfa9f57b1a204d945d0bd1c51e/6c9b1d8d22d7009d6b4e1cc9150e2e6e</id>
		<category term="Networking" />
		<category term="System" />
		
<content type="html">
&lt;p&gt;Just upgraded this site to a new version of &lt;a href="http://www.textpattern.com"&gt;textpattern&lt;/a&gt;. I think everything still works fine, but please leave a comment if you find anything suspicious.
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9gTxdiMji1C_EfywC7TNvsO2UjQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9gTxdiMji1C_EfywC7TNvsO2UjQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9gTxdiMji1C_EfywC7TNvsO2UjQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9gTxdiMji1C_EfywC7TNvsO2UjQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=gadyqwA9pnk:VaZQiLkge2w:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=gadyqwA9pnk:VaZQiLkge2w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=gadyqwA9pnk:VaZQiLkge2w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=gadyqwA9pnk:VaZQiLkge2w:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=gadyqwA9pnk:VaZQiLkge2w:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/gadyqwA9pnk" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Various/123/site-updated</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-06-29T15:17:42Z</published>
		<updated>2010-06-29T15:17:42Z</updated>
		<title type="html">How to Copy TFS Build Definitions</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/ZZ-nP5-PI_I/how-to-copy-tfs-build-definitions" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/4ae31de0ce9c473e71e69465e708c21c</id>
		
		
		
<content type="html">
&lt;p&gt;&lt;/p&gt;  &lt;p&gt;First of all a question: &lt;strong&gt;Where is the copy option?&lt;/strong&gt;&lt;/p&gt; &lt;img src="http://www.brokenwire.net/bw/images/121.png" /&gt;   &lt;p&gt;The answer: there is no copy option. &lt;/p&gt;  &lt;p&gt;So because the Team Explorer doesn’t allow you to copy Build Definitions without manually copying all the fields I had to write a small tool to do so. In this post I’ll show you how that works. &lt;/p&gt;  &lt;p&gt;First of all, the user-friendly designed-by-a-developer user interface:&lt;/p&gt; &lt;img src="http://www.brokenwire.net/bw/images/120.png" /&gt;   &lt;p&gt;First you connect to the TFS server then you select the Build Definition that you’d like to copy. Optionally you can add some find/replace values and finally you hit the button. As easy as 1-2-3. The interesting bit is of course how this is done.&lt;/p&gt;  &lt;p&gt;The tree view at the left hand side is populated by this little piece of code:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(&lt;span class="str"&gt;&amp;quot;http://xxx:8080&amp;quot;&lt;/span&gt;);
buildDefTreeview.BeginUpdate();
buildDefTreeview.Nodes.Clear();
ICommonStructureService common = (ICommonStructureService)tfs.GetService(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ICommonStructureService));
var projects = common.ListAllProjects();
IBuildServer buildServer = (IBuildServer)tfs.GetService(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IBuildServer));
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var project &lt;span class="kwrd"&gt;in&lt;/span&gt; projects.OrderBy(p =&amp;gt; p.Name))
{
    var currentNode = buildDefTreeview.Nodes.Add(project.Name, project.Name);
    var buildDefinitions = buildServer.QueryBuildDefinitions(project.Name);
    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var buildDef &lt;span class="kwrd"&gt;in&lt;/span&gt; buildDefinitions.OrderBy(b =&amp;gt; b.Name))
    {
        var newNode = currentNode.Nodes.Add(buildDef.Name, buildDef.Name);
        newNode.Tag = buildDef;
    }
}
buildDefTreeview.EndUpdate();&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Basically it connects to the TFS server and iterates through the projects. For each project the Build Definitions are queried and the results are added as child nodes to the tree. 
  &lt;br /&gt;Behind the the copy button this piece of code does the real super-time-saver magic:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;IBuildDefinition original = (IBuildDefinition)buildDefTreeview.SelectedNode.Tag;
IBuildDefinition copy = original.BuildServer.CreateBuildDefinition(original.TeamProject);
copy.Name = FindReplace(original.Name);
&lt;span class="kwrd"&gt;if&lt;/span&gt; (copy.Name == original.Name)
{
    copy.Name = &lt;span class="str"&gt;&amp;quot;Copy of &amp;quot;&lt;/span&gt; + original.Name;
}
copy.ConfigurationFolderPath = FindReplace(original.ConfigurationFolderPath);
copy.ContinuousIntegrationQuietPeriod = original.ContinuousIntegrationQuietPeriod;
copy.ContinuousIntegrationType = original.ContinuousIntegrationType;
copy.DefaultBuildAgent = original.DefaultBuildAgent;
copy.DefaultDropLocation = original.DefaultDropLocation;
copy.Description = original.Description;
copy.Enabled = original.Enabled;
copy.Schedules.AddRange(original.Schedules);
copy.Workspace.Mappings.AddRange(original.Workspace.Mappings);
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var mapping &lt;span class="kwrd"&gt;in&lt;/span&gt; copy.Workspace.Mappings)
{
    mapping.ServerItem = FindReplace(mapping.ServerItem);
}
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var retp &lt;span class="kwrd"&gt;in&lt;/span&gt; original.RetentionPolicies)
{
    copy.RetentionPolicies[retp.Key] = retp.Value;
}
copy.Save();&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The FindReplace function takes care of replacing the values from the find/replace list. The copying of most properties is rather straightforward. Of the the things to take into account is that the paths to the workspace and the Build Script (ConfigurationFolderPath) have to exist before you copy (create) the build definition.&lt;/p&gt;

&lt;p&gt;I use this tool on TFS2008, but converting this to TFS2010 shouldn’t be hard. Of course it would be nice to see this kind of functionality in the next version of the Team Explorer. Until then, you can save a lot of typing and mouse clicks (and $$$) by using a tool like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ASd0qGeQL4zvCKNCqybud5cEaEc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ASd0qGeQL4zvCKNCqybud5cEaEc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ASd0qGeQL4zvCKNCqybud5cEaEc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ASd0qGeQL4zvCKNCqybud5cEaEc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=ZZ-nP5-PI_I:9k-YidrqKX0:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=ZZ-nP5-PI_I:9k-YidrqKX0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=ZZ-nP5-PI_I:9k-YidrqKX0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=ZZ-nP5-PI_I:9k-YidrqKX0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=ZZ-nP5-PI_I:9k-YidrqKX0:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/ZZ-nP5-PI_I" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Programming/122/how-to-copy-tfs-build-definitions</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-02-23T19:17:53Z</published>
		<updated>2010-02-23T19:17:53Z</updated>
		<title type="html">System.Timers.Timer still broken</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/hr05iowgcj4/systemtimerstimer-still-broken" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/334f20d83d7c58f42511620ba52d9c03</id>
		
		
		
<content type="html">
&lt;p&gt;About one year ago I wrote about &lt;a href="http://www.brokenwire.net/bw/Programming/108/timerelapsed-event-the-silent-killer" target="_blank"&gt;System.Timer.Timer and it’s exception silencing capabilities&lt;/a&gt;. Now the .NET framework version 4 is almost done I thought it would be nice to do the same test again on the brand new framework. And guess what? It’s still broken!&lt;/p&gt;  &lt;p&gt;Just to be clear what’s happening here: when an exception is thrown in the .Elapsed event of a System.Timers.Timer object then the exception gets silenced by an empty catch block within the framework code surrounding this event. You can see the sample code for reproducing this in my &lt;a href="http://www.brokenwire.net/bw/Programming/108/timerelapsed-event-the-silent-killer" target="_blank"&gt;previous post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Now there are many &lt;a href="http://stackoverflow.com/questions/1234343/why-are-empty-catch-blocks-a-bad-idea" target="_blank"&gt;discussions about the usage of empty catch blocks&lt;/a&gt; but the general opinion seems to be that &lt;strong&gt;empty catch blocks are usually a bad idea&lt;/strong&gt;. So why is this not fixed yet?&lt;/p&gt;  &lt;p&gt;There is even a &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/286105/system-timers-timer-swallows-exceptions" target="_blank"&gt;Microsoft Connect bug&lt;/a&gt; for this issue, in which we are promised that this will be fixed in “a next version of the framework”. That bug was opened in 2007… &lt;/p&gt;  &lt;p&gt;So, if you want .Net framework 4 to suck a little bit less: go &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/286105/system-timers-timer-swallows-exceptions" target="_blank"&gt;HERE&lt;/a&gt; and vote for this bug. And remember: You ARE the framework ;)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ppb1-b2a3IuS-Wk-WcrI_F4HdFA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ppb1-b2a3IuS-Wk-WcrI_F4HdFA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ppb1-b2a3IuS-Wk-WcrI_F4HdFA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ppb1-b2a3IuS-Wk-WcrI_F4HdFA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=hr05iowgcj4:ILOPTV_AxV4:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=hr05iowgcj4:ILOPTV_AxV4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=hr05iowgcj4:ILOPTV_AxV4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=hr05iowgcj4:ILOPTV_AxV4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=hr05iowgcj4:ILOPTV_AxV4:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/hr05iowgcj4" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Programming/121/systemtimerstimer-still-broken</feedburner:origLink></entry>
<entry>
		<author>
			<name>Thijs Kroesbergen</name>
		</author>
		<published>2010-02-15T10:33:54Z</published>
		<updated>2011-10-20T19:04:54Z</updated>
		<title type="html">Fix: Virtualbox causes "Unidentified" network on Vista and Windows 7 [7]</title>
		<link rel="alternate" type="text/html" href="http://feeds.brokenwire.net/~r/brokenwire/~3/Ivx4KPvaV0M/fix-virtualbox-causes-unidentified-network-on-vista-and-windows-7" />
		<id>tag:www.brokenwire.net,1970-01-01:241f6adfa9f57b1a204d945d0bd1c51e/e2a1b5468de52447f0faaeefb306ccf6</id>
		
		
		
<content type="html">
&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When you install Virtualbox on Windows Vista or Windows 7 it will install an additional virtual network adapter on the host system. This “Virtualbox Host-Only Adapter” causes the Windows network detection to show an additional “unidentified” network. And while this “unidentified” network is present the windows firewall settings will stay on “Public”. This behavior is undesirable because you want to be able to switch your firewall settings based on your location (home/work/public).&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.brokenwire.net/bw/images/118.png" /&gt;     &lt;br /&gt;&lt;img src="http://www.brokenwire.net/bw/images/119.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The solution (manually):&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;WARNING; DANGER: THE REGISTRY IS NO PLAYGROUND, IF YOU DON’T UNDERSTAND WHAT YOU’RE DOING THEN DON’T DO IT!    &lt;br /&gt;Now we have that out of the way, here is what you should do:&lt;/p&gt;  &lt;p&gt;1. Open regedit and navigate to &lt;em&gt;HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;2. Browse through the subkeys (named 0000, 0001, etc) until you find the subkey containing the virtualbox network adapter, this is the one where the “&lt;em&gt;DriverDesc&lt;/em&gt;” key has “&lt;em&gt;VirtualBox Host-Only Ethernet Adapter&lt;/em&gt;” as value.&lt;/p&gt;  &lt;p&gt;3. Add a new DWORD value with a name of “&lt;em&gt;*NdisDeviceType&lt;/em&gt;” and a value of “&lt;em&gt;1&lt;/em&gt;”&lt;br/&gt;&lt;img src="http://www.brokenwire.net/bw/images/131.png" /&gt;&lt;/p&gt;  &lt;p&gt;4. Disable en re-enable the virtuabox host-only network adapter, or alternatively reboot your pc.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The solution (PowerShell)&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I hacked together this PowerShell script to easily re-do this trick after a virtualbox upgrade. The script has only been tested on my pc (and it works), use at your own risk. You need to run an elevated PowerShell shell to modify the registry.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;$devices = &lt;span class="str"&gt;&amp;quot;HKLM:\SYSTEM\CurrentControlSet\Control\Class\*&amp;quot;&lt;/span&gt;
$adapters = Get-ItemProperty $devices | Where-Object  {$_.Class &lt;span class="preproc"&gt;-eq&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Net&amp;quot;&lt;/span&gt;} | Foreach-Object { $_.PSPath }
Get-ChildItem $adapters -erroraction silentlycontinue | Foreach-Object { get-itemproperty -path $_.PSPath } | Where-Object {$_.ComponentId &lt;span class="preproc"&gt;-eq&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;sun_vboxnetadp&amp;quot;&lt;/span&gt;} | Foreach-Object { Set-ItemProperty -path $_.PSPath -name &lt;span class="str"&gt;&amp;quot;*NdisDeviceType&amp;quot;&lt;/span&gt; -Type DWORD -Value 1}
Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name &lt;span class="preproc"&gt;-like&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;*Virtualbox Host*&amp;quot;&lt;/span&gt;} | Foreach-Object {$_.Disable(); $_.Enable()}&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;Why this registry fix fixes that:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is actually an &lt;a href="http://msdn.microsoft.com/en-us/library/bb201634.aspx"&gt;MSDN article&lt;/a&gt; that describes the possible registry keys for network adapters:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;dt&gt;&lt;strong&gt;*NdisDeviceType&lt;/strong&gt; 

    &lt;p&gt;&lt;/p&gt;
  &lt;/dt&gt;&lt;dd&gt;The type of the device. The default value is zero, which indicates a standard networking device that connects to a network. Set &lt;strong&gt;*NdisDeviceType&lt;/strong&gt; to NDIS_DEVICE_TYPE_ENDPOINT (1) if this device is an endpoint device and is not a true network interface that connects to a network. For example, you must specify NDIS_DEVICE_TYPE_ENDPOINT for devices such as smart phones that use a networking infrastructure to communicate to the local computer system but do not provide connectivity to an external network.&lt;/dd&gt;&lt;/blockquote&gt;

&lt;p&gt;And&lt;/p&gt;

&lt;blockquote&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;#160; Windows Vista automatically identifies and monitors the networks to which a computer connects. If the NDIS_DEVICE_TYPE_ENDPOINT flag is set, the device is an endpoint device and is not a connection to a true external network. Consequently, Windows ignores the endpoint device when Windows identifies networks. The Network Awareness APIs indicate that the device does not connect the computer to a network. For end users in this situation, the Network and Sharing Center and the network icon in the notification area do not show the NDIS endpoint device as connected. However, the connection is shown in the Network Connections Folder.&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;More&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similar problem and similar fix for vmware: &lt;/p&gt;

&lt;p&gt;&lt;a title="http://aspoc.net/archives/2008/10/30/unidentified-network-issue-with-vmwares-virtual-nics-in-vista/" href="http://aspoc.net/archives/2008/10/30/unidentified-network-issue-with-vmwares-virtual-nics-in-vista/"&gt;http://aspoc.net/archives/2008/10/30/unidentified-network-issue-with-vmwares-virtual-nics-in-vista/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With a much nicer powershell script:&lt;/p&gt;

&lt;p&gt;&lt;a title="http://www.nivot.org/2008/09/05/VMWareVMNETAdaptersTriggeringPublicProfileForWindowsFirewall.aspx" href="http://www.nivot.org/2008/09/05/VMWareVMNETAdaptersTriggeringPublicProfileForWindowsFirewall.aspx"&gt;http://www.nivot.org/2008/09/05/VMWareVMNETAdaptersTriggeringPublicProfileForWindowsFirewall.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the virtualbox forums thread that pointed me in the right direction:&lt;/p&gt;

&lt;p&gt;&lt;a title="http://forums.virtualbox.org/viewtopic.php?f=6&amp;amp;t=17153#p73167" href="http://forums.virtualbox.org/viewtopic.php?f=6&amp;amp;t=17153#p73167"&gt;http://forums.virtualbox.org/viewtopic.php?f=6&amp;amp;t=17153#p73167&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7vpdTFI7fo1_U_8Vu33lEZtbT7A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7vpdTFI7fo1_U_8Vu33lEZtbT7A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7vpdTFI7fo1_U_8Vu33lEZtbT7A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7vpdTFI7fo1_U_8Vu33lEZtbT7A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=Ivx4KPvaV0M:jo6Cm5CMKI8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=Ivx4KPvaV0M:jo6Cm5CMKI8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=Ivx4KPvaV0M:jo6Cm5CMKI8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?i=Ivx4KPvaV0M:jo6Cm5CMKI8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.brokenwire.net/~ff/brokenwire?a=Ivx4KPvaV0M:jo6Cm5CMKI8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/brokenwire?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/brokenwire/~4/Ivx4KPvaV0M" height="1" width="1"/&gt;</content><feedburner:origLink>http://www.brokenwire.net/bw/Various/120/fix-virtualbox-causes-unidentified-network-on-vista-and-windows-7</feedburner:origLink></entry></feed>

