<?xml version="1.0" encoding="UTF-8"?>
<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" version="2.0">

<channel>
	<title>iterator.net</title>
	
	<link>http://blog.iterator.net</link>
	<description />
	<pubDate>Wed, 25 Mar 2009 00:12:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/IteratorNetEntries" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="iteratornetentries" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Problems running xUnit 1.1 under TestDriven.NET on 64-bit Windows</title>
		<link>http://blog.iterator.net/brannon/2009/03/problems-running-xunit-11-under-testdrivennet-on-64-bit-windows/</link>
		<comments>http://blog.iterator.net/brannon/2009/03/problems-running-xunit-11-under-testdrivennet-on-64-bit-windows/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 00:04:58 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[64-bit]]></category>

		<category><![CDATA[td.net]]></category>

		<category><![CDATA[xunit]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=24</guid>
		<description><![CDATA[I ran into a problem today trying to run xUnit tests under TestDriven.NET on my 64-bit Windows (7) install.
I had xUnit installed (with TestDriven.NET support enabled).  I also had the TestDriven.NET 2.14 release installed (which is the latest stable build).
My test project had a reference to xunit.dll and my test methods were decorated with [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem today trying to run xUnit tests under TestDriven.NET on my 64-bit Windows (7) install.</p>
<p>I had xUnit installed (with TestDriven.NET support enabled).  I also had the TestDriven.NET 2.14 release installed (which is the latest <em>stable</em> build).</p>
<p>My test project had a reference to <code>xunit.dll</code> and my test methods were decorated with the <code>[Fact]</code> attribute.</p>
<p>But for some reason, when I tried to run the tests using TestDriven.NET, it would give the dreaded <strong>0 passed, 0 failed, 0 skipped</strong> result, meaning it didn&#8217;t run any tests.</p>
<p>I&#8217;m not sure what the problem was, but the solution was simple: <em>Install the latest TestDriven.NET beta build</em> (currently 2.19.2409).</p>
<p>Apparently there is an issue with TestDriven.NET on 64-bit Windows (alluded to on the <a href="http://xunit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=16811#ReleaseFiles">xUnit 1.1 release page</a>).</p>
<p>Not sure if the problem is xUnit-specific or it occurs with other test frameworks as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2009/03/problems-running-xunit-11-under-testdrivennet-on-64-bit-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Proper Disposing of System.Net.Mail.MailMessage</title>
		<link>http://blog.iterator.net/brannon/2008/10/proper-disposing-of-systemnetmailmailmessage/</link>
		<comments>http://blog.iterator.net/brannon/2008/10/proper-disposing-of-systemnetmailmailmessage/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 22:53:58 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=22</guid>
		<description><![CDATA[I ran into this today while working on some client code.
Some of the overrides for System.Net.Mail.Attachment take a Stream parameter.  The Attachment class will hold on to that stream until you send the corresponding MailMessage.
To ensure that the stream is cleaned up properly you need to call Dispose() on the MailMessage instance when you [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into this today while working on some client code.</p>
<p>Some of the overrides for <code>System.Net.Mail.Attachment</code> take a <code>Stream</code> parameter.  The <code>Attachment</code> class will hold on to that stream until you send the corresponding <code>MailMessage</code>.</p>
<p>To ensure that the stream is cleaned up properly you need to call <code>Dispose()</code> on the <code>MailMessage</code> instance when you are finished with it:<br />
<code>

using (MailMessage message = BuildMessage())
{
    SmtpClient client = new SmtpClient();
    client.Send(message);
}

</code><br />
Using .NET Reflector, you can see that disposing the <code>MailMessage</code> disposes each <code>Attachment</code>, which will in turn close each <code>Stream</code>.</p>
<p>If you don&#8217;t dispose the <code>MailMessage</code>, you are at the mercy of the garbage collector.  For a <code>FileStream</code> that can cause unexpected, and seemingly unrelated, problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2008/10/proper-disposing-of-systemnetmailmailmessage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Extension Methods</title>
		<link>http://blog.iterator.net/brannon/2008/08/c-extension-methods/</link>
		<comments>http://blog.iterator.net/brannon/2008/08/c-extension-methods/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 07:23:51 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[extension method]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=17</guid>
		<description><![CDATA[I was explaining to a friend how to use extension methods and wrote up this quick sample.

namespace Foo.Extensions
{
    public static class StringExtensions
    {
        public static string Truncate(this string value, int maxLength)
        {
    [...]]]></description>
			<content:encoded><![CDATA[<p>I was explaining to a friend how to use extension methods and wrote up this quick sample.</p>
<p><code class="block">
namespace Foo.Extensions
{
    public static class StringExtensions
    {
        public static string Truncate(<font color="red">this string value</font>, int maxLength)
        {
            if (value.Length > maxLength)
                return value.Substring(0, maxLength - 3) + "...";
            
            return value;
        }
    }
}
<!--end_raw--></code>

<p>To use the extension method:</p>

<code class="block"><!--start_raw-->
using Foo.Extensions; // IMPORTANT!

namespace Foo
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            string longText = "this is some really long text!!!";
            
            Console.WriteLine(<font color="red">longText.Truncate(20)</font>);
        }
    }
}
</code></p>
<p>The magic happens when you add the <code>this</code> keyword to the first parameter of the static method.  This tells the compiler to add the method to the specified type (<code>string</code> is this example).  The method behaves as an instance method, though your extension method can only access public members of the type.</p>
<p>You can also call the extension method the <em>old</em> way: <code>StringExtensions.Truncate(longText, 20);</code></p>
<p>It&#8217;s important to note that you MUST add a <code>using</code> statement to import the namespace where you defined the extension method (<code>Foo.Extensions</code> in this example), otherwise the compiler (and intellisense) won&#8217;t add the methods to the specified types.</p>
<p>Extension methods are one of the most useful additions to C# 3.0.  They are simple to use and in many cases you can convert an existing method to be an extension method without breaking existing code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2008/08/c-extension-methods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>.NET Reflector auto update</title>
		<link>http://blog.iterator.net/brannon/2008/07/net-reflector-auto-update/</link>
		<comments>http://blog.iterator.net/brannon/2008/07/net-reflector-auto-update/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 23:28:50 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Commentary]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=16</guid>
		<description><![CDATA[I love .NET Reflector.  It&#8217;s an indispensable programming tool.
Unfortunately it has one big flaw: it&#8217;s auto update feature is not optional.
I regularly work disconnected, either because I&#8217;m not near a hotspot or because I&#8217;m running a VM without internet access.
If Reflector determines that it is out-of-date it will refuse to run until you update [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://www.aisto.com/dotnet/">.NET Reflector</a>.  It&#8217;s an <em>indispensable</em> programming tool.</p>
<p>Unfortunately it has one big flaw: <strong>it&#8217;s auto update feature is not optional</strong>.</p>
<p>I regularly work disconnected, either because I&#8217;m not near a hotspot or because I&#8217;m running a VM without internet access.</p>
<p>If Reflector determines that it is out-of-date it will refuse to run until you update it.  This is a huge pain because I usually don&#8217;t hit the problem unless I <strong>need</strong> to use Reflector.</p>
<p>Yes, I know complaining about free software is lame, but please Lutz, make the update functionality optional.  I promise I&#8217;ll update the next time I&#8217;m connected.</p>
<p><strong>Update:</strong> <a href="http://www.red-gate.com">Red Gate</a> has acquired .NET Reflector.  Please visit my <a href="http://www.red-gate.com/messageboard/viewtopic.php?t=7501">forum post</a> and share your opinion!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2008/07/net-reflector-auto-update/feed/</wfw:commentRss>
		</item>
		<item>
		<title>iPhone software 2.0</title>
		<link>http://blog.iterator.net/brannon/2008/07/iphone-software-20/</link>
		<comments>http://blog.iterator.net/brannon/2008/07/iphone-software-20/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 18:09:18 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=10</guid>
		<description><![CDATA[This morning I upgraded my first-gen iPhone to the 2.0 software, using the process described here.

The update took maybe 30 minutes.  I was not prompted to backup my settings or media, so make sure you perform a sync before updating.
Some initial observations:

Adding my Exchange account was painless (especially compared to adding the same account [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I upgraded my first-gen iPhone to the 2.0 software, using the process described <a href="http://www.tuaw.com/2008/07/10/get-your-2-0-firmware-on-early/" target="_new">here</a>.</p>
<p><img alt="iPhone 2.0 Home Screen" src="http://blog.iterator.net/wp-content/uploads/iPhone20Home.jpg" /></p>
<p>The update took maybe 30 minutes.  I was not prompted to backup my settings or media, so make sure you perform a sync before updating.</p>
<p>Some initial observations:</p>
<ul>
<li>Adding my Exchange account was painless (especially compared to adding the same account using IMAP).</li>
<li>Exchange ActiveSync works great.  I&#8217;m getting emails on my phone before I receive them on my laptop.</li>
<li>Syncing your Exchange calendar <strong>erases</strong> all other calendars from the phone and disables calendar syncing within iTunes.</li>
<li>If you aren&#8217;t syncing an Exchange calendar, the phone now provides access to all of your iCal calendars, including Entourage (if you have enabled iCal syncing within Entourage).</li>
<li>The AppStore is working (from the phone at least).  So far I&#8217;ve installed Twitterrific, Remote, Google Mobile App, and AP Mobile News.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2008/07/iphone-software-20/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScriptSerializer non-generic Deserialize method</title>
		<link>http://blog.iterator.net/brannon/2008/07/javascriptserializer-non-generic-deserialize-method/</link>
		<comments>http://blog.iterator.net/brannon/2008/07/javascriptserializer-non-generic-deserialize-method/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 07:16:49 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[JSON]]></category>

		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=9</guid>
		<description><![CDATA[I was messing around with the ASP.NET MVC Preview 3 the other evening and ran into a &#8220;problem&#8221; with the JavaScriptSerializer.  The class provides two methods for deserializing an object from JSON data:

public T Deserialize&#60;T&#62;(string data);
public object DeserializeObject(string data);

A notable omission from the API is a non-generic method for deserializing to a specific type, [...]]]></description>
			<content:encoded><![CDATA[<p>I was messing around with the <a href="http://www.asp.net/mvc/" target="_new">ASP.NET MVC Preview 3</a> the other evening and ran into a &#8220;problem&#8221; with the <code><a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" target="_new">JavaScriptSerializer</a></code>.  The class provides two methods for deserializing an object from JSON data:</p>
<p><code class="block">
public T Deserialize&lt;T&gt;(string data);
public object DeserializeObject(string data);
<!--end_raw--></code>
<p>A notable omission from the API is a non-generic method for deserializing to a specific type, i.e.:</p>
<code class="block"><!--start_raw-->
public object Deserialize(Type type, string data);
<!--end_raw--></code>
<p>This method would be useful when dynamically deserializing objects, using reflection for instance.</p>
<p>Digging around with <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> I found that the generic method just delegates to an internal helper, passing the generic parameter <code>T</code> as <code>typeof(T)</code>.  It would be a simple matter then to provide the necessary overload that accepts the <code>Type</code> directly.</p>
<p>Hopefully the ASP.NET team will add the missing overload, but in the meantime I decided to "cheat" with the following extension method:</p>
<code class="block"><!--start_raw-->
public static class JavaScriptSerializerExtensions
{
    public static object Deserialize(this JavaScriptSerializer serializer,
                                     Type type,
                                     string data)
    {
        Type serializerType = typeof(JavaScriptSerializer);

        object[] args = new object[]
            {
            serializer,
            data,
            type,
            serializer.RecursionLimit,
            };

        return serializerType.InvokeMember(
            "Deserialize",
            BindingFlags.Static |
                BindingFlags.NonPublic |
                BindingFlags.InvokeMethod,
            Type.DefaultBinder,
            null,
            args);
    }
}
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2008/07/javascriptserializer-non-generic-deserialize-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MVC and DLR presentations at ALT.NET</title>
		<link>http://blog.iterator.net/brannon/2007/10/mvc-and-dlr-presentations-at-altnet/</link>
		<comments>http://blog.iterator.net/brannon/2007/10/mvc-and-dlr-presentations-at-altnet/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 05:36:25 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=4</guid>
		<description><![CDATA[
Some pretty cool presentations from the ALT.NET conference by Scott Guthrie and Scott Hanselman.  Check out Scott Hanselman&#8217;s blog post for the details.


Unfortunately he links to the Silverlight video player for the videos which apparently doesn&#8217;t work for a lot of people.  Here are direct links to the .WMV files (hosted by Microsoft):
ScottGu&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>
Some pretty cool presentations from the ALT.NET conference by Scott Guthrie and Scott Hanselman.  Check out <a href="http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx">Scott Hanselman&#8217;s blog post</a> for the details.
</p>
<p>
Unfortunately he links to the Silverlight video player for the videos which apparently doesn&#8217;t work for a lot of people.  Here are direct links to the .WMV files (hosted by Microsoft):</p>
<p>ScottGu&#8217;s presentation on MVC:<br />
<a href="http://download.microsoft.com/download/f/0/8/f0830f07-44db-4eea-ace3-8865856c8d65/ScottGuOnMVCatALTNET.wmv">ScottGuOnMVCatALTNET.wmv</a></p>
<p>ScottHa&#8217;s presentation on MVC+DLR:<br />
<a href="http://download.microsoft.com/download/f/0/8/f0830f07-44db-4eea-ace3-8865856c8d65/ScottHaOnDLRandMVCatALTNET.wmv">ScottHaOnDLRandMVCatALTNET.wmv</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2007/10/mvc-and-dlr-presentations-at-altnet/feed/</wfw:commentRss>
<enclosure url="http://download.microsoft.com/download/f/0/8/f0830f07-44db-4eea-ace3-8865856c8d65/ScottGuOnMVCatALTNET.wmv" length="454233011" type="video/x-ms-wmv" />
<enclosure url="http://download.microsoft.com/download/f/0/8/f0830f07-44db-4eea-ace3-8865856c8d65/ScottHaOnDLRandMVCatALTNET.wmv" length="137088813" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>When open-source isn’t open</title>
		<link>http://blog.iterator.net/brannon/2007/07/when-open-source-isnt-open/</link>
		<comments>http://blog.iterator.net/brannon/2007/07/when-open-source-isnt-open/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 05:37:15 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=5</guid>
		<description><![CDATA[
Snippet from Wikipedia&#8217;s article on ZFS (http://en.wikipedia.org/wiki/Zettabyte_File_System):


Porting ZFS to Linux is complicated by the fact that the GNU General Public License, which governs the Linux kernel, prohibits linking with code under certain licenses, such as CDDL, the license ZFS is released under.[21]


I can&#8217;t understand why people still use the GPL, or even bother to incorporate [...]]]></description>
			<content:encoded><![CDATA[<p>
Snippet from Wikipedia&#8217;s article on ZFS (<a href="http://en.wikipedia.org/wiki/Zettabyte_File_System">http://en.wikipedia.org/wiki/Zettabyte_File_System</a>):
</p>
<blockquote><p>
Porting ZFS to Linux is complicated by the fact that the GNU General Public License, which governs the Linux kernel, prohibits linking with code under certain licenses, such as CDDL, the license ZFS is released under.<a href="http://en.wikipedia.org/wiki/Zettabyte_File_System#_note-kerneltrap">[21]</a>
</p></blockquote>
<p>
I can&#8217;t understand why people still use the GPL, or even bother to incorporate GPL-licensed code.  I don&#8217;t know a single developer who likes the GPL or would ever release code licensed under it.</p>
<p>Even Linus Torvalds seems to be wary of the aggressive nature of the GPL:
</p>
<p><blockquote><code>NOTE! This copyright does *not* cover user programs that use kernel
services by normal system calls - this is merely considered normal use
of the kernel, and does *not* fall under the heading of "derived work". 
Also note that the GPL below is copyrighted by the Free Software
Foundation, but the instance of code that it refers to (the linux
kernel) is copyrighted by me and others who actually wrote it.
    Linus Torvalds
</code></blockquote></p>
<p>
(snipped from the <a href="http://www.kernel.org/pub/linux/kernel/COPYING">Linux Kernel license file</a>)
</p>
<p>
I wonder what percentage of people who license their code under the GPL understand the restrictions they are imposing on other developers, or if they just choose the GPL because it&#8217;s a well known name and no one wants to take the time to read and compare a few different software licenses.    Personally I prefer the (new) <a href="http://www.opensource.org/licenses/bsd-license.php">BSD license</a>.  It&#8217;s short and sweet and doesn&#8217;t attempt to masquerade a social agenda as freedom.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2007/07/when-open-source-isnt-open/feed/</wfw:commentRss>
		</item>
		<item>
		<title>const string vs. static string</title>
		<link>http://blog.iterator.net/brannon/2007/05/const-string-vs-static-string/</link>
		<comments>http://blog.iterator.net/brannon/2007/05/const-string-vs-static-string/#comments</comments>
		<pubDate>Sun, 20 May 2007 07:44:47 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=8</guid>
		<description><![CDATA[
There was an email thread going around the office not too long ago debating whether it is more efficient to use string constants or static readonly strings (in C#).  An example was given that seemed to indicate that the static strings were better:


public class Sample
{
    static readonly string StaticString = "StaticString";
 [...]]]></description>
			<content:encoded><![CDATA[<p>
There was an email thread going around the office not too long ago debating whether it is more efficient to use string constants or static readonly strings (in C#).  An example was given that seemed to indicate that the static strings were better:
</p>
<p><code class="block">
public class Sample
{
    static readonly string StaticString = "StaticString";
    const string ConstString = "ConstString";
    
    public void SetValues(StringCollection strings)
    {
        strings[StaticString] = "foo";
        strings[ConstString] = "bar";
    }
    
    public void GetValues(StringCollection strings)
    {
        string value1 = strings[StaticString];
        string value2 = strings[ConstString];
    }
}
<!--end_raw--></code>
<p>
The disassembly of that code shows something surprising:
</p>
<code class="block"><!--start_raw-->
public class Sample
{
    // Fields
    private const string ConstString = "ConstString";
    private static readonly string StaticString = "StaticString";
    
    // Methods
    public void GetValues(NameValueCollection values)
    {
        string text1 = values[StaticString];
        string text2 = values[<strong>"ConstString"</strong>];
    }
    
    public void SetValues(NameValueCollection values)
    {
        values[StaticString] = "foo";
        values[<strong>"ConstString"</strong>] = "bar";
    }
}
<!--end_raw--></code>
<p>
It doesn't look like the const string is being used at all, while it's obvious that the static string is.  This can't be right.  Let's take a look at the IL:
</p>
<code class="block"><!--start_raw-->
.class public auto ansi beforefieldinit Sample
    extends [mscorlib]System.Object
{
    .method private hidebysig specialname rtspecialname static
        void .cctor() cil managed
    {
        .maxstack 8
        L_0000: ldstr "StaticString"
        L_0005: stsfld string TestStringConstantsLibrary.Sample::StaticString
        L_000a: ret
    }
    
    .method public hidebysig specialname rtspecialname instance
        void .ctor() cil managed
    {
        .maxstack 8
        L_0000: ldarg.0
        L_0001: call instance void [mscorlib]System.Object::.ctor()
        L_0006: ret
    }
    
    .method public hidebysig instance void GetValues(class
        [System]System.Collections.Specialized.NameValueCollection values) cil managed
    {
        .maxstack 8
        L_0000: ldarg.1
        L_0001: ldsfld string TestStringConstantsLibrary.Sample::StaticString
        L_0006: callvirt instance string [System]System.Collections.Specialized.NameValueCollection::get_Item(string)
        L_000b: pop
        L_000c: ldarg.1
        L_000d: ldstr <strong>"ConstString"</strong>
        L_0012: callvirt instance string [System]System.Collections.Specialized.NameValueCollection::get_Item(string)
        L_0017: pop
        L_0018: ret
    }
    
    .method public hidebysig instance void SetValues(class
        [System]System.Collections.Specialized.NameValueCollection values) cil managed
    {
        .maxstack 8
        L_0000: ldarg.1
        L_0001: ldsfld string TestStringConstantsLibrary.Sample::StaticString
        L_0006: ldstr "foo"
        L_000b: callvirt instance void [System]System.Collections.Specialized.NameValueCollection::set_Item(string, string)
        L_0010: ldarg.1
        L_0011: ldstr <strong>"ConstString"</strong>
        L_0016: ldstr "bar"
        L_001b: callvirt instance void [System]System.Collections.Specialized.NameValueCollection::set_Item(string, string)
        L_0020: ret
    }
    
    <strong>.field private static literal string ConstString = string('ConstString')</strong>
    .field private static initonly string StaticString
}
<!--end_raw--></code>
<p>
Same odd result, though we can see that the const string is defined as a static field (with the <code>literal</code> modifier instead of the <code>initonly</code> modifier).  What gives?  I refuse to believe that const strings are duplicated all over the assembly.  Opening the assembly in a hex editor (I used Visual Studio's Binary Editor), you can see that there are only 2 instances of the string (not the 3 you would expect):
</p>
<div>
<img src="http://blog.iterator.net/wp-content/uploads/const-string-1.png" />
</div>
<p>
In fact, if we add the following method to our class:
</p>
<code class="block"><!--start_raw-->
public void WriteConsole()
{
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
    Console.WriteLine("ConstString");
}
</code></p>
<p>
We can see that it does not add any additional strings to our assembly.  There are still only the 2 instances:
</p>
<div>
<img src="http://blog.iterator.net/wp-content/uploads/const-string-2.png" />
</div>
<p>
So, const string is not as bad as it initially looks.  I am curious why there are 2 instances of the string though, and why the field isn&#8217;t referenced&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2007/05/const-string-vs-static-string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting the name of a builtin Windows security object</title>
		<link>http://blog.iterator.net/brannon/2007/05/getting-the-name-of-a-builtin-windows-security-object/</link>
		<comments>http://blog.iterator.net/brannon/2007/05/getting-the-name-of-a-builtin-windows-security-object/#comments</comments>
		<pubDate>Tue, 15 May 2007 07:00:57 +0000</pubDate>
		<dc:creator>Brannon</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.iterator.net/?p=7</guid>
		<description><![CDATA[
It&#8217;s not obvious how to do this in .NET, but it&#8217;s actually pretty easy once you decipher the documentation.


The two classes you need are in the System.Security.Principal namespace:


SecurityIdentifier
NTAccount

You need to create a new instance of a SecurityIdentifier using the constructor that takes a WellKnownSidType enum value.  The WellKnownSidType value specifies the built-in security object [...]]]></description>
			<content:encoded><![CDATA[<p>
It&#8217;s not obvious how to do this in .NET, but it&#8217;s actually pretty easy once you decipher the documentation.
</p>
<p>
The two classes you need are in the <code><a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.aspx">System.Security.Principal</a></code> namespace:
</p>
<ul>
<li><code><a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.securityidentifier.aspx">SecurityIdentifier</a></code></li>
<li><code><a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.ntaccount.aspx">NTAccount</a></code></li>
</ul>
<p>You need to create a new instance of a <code>SecurityIdentifier</code> using the constructor that takes a <code><a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.wellknownsidtype.aspx">WellKnownSidType</a></code> enum value.  The <code>WellKnownSidType</code> value specifies the built-in security object you are interested in.
</p>
<p><code class="block">
// Assume using System.Security.Principal
SecurityIdentifier si = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
<!--end_raw--></code>
<p>
Given the instance of the <code>SecurityIdentifier</code>, you obtain the name via the <code>Translate()</code> method, passing <code>typeof(NTAccount)</code> and casting the result to an <code>NTAccount</code> instance.
</p>
<code class="block"><!--start_raw-->
NTAccount acct = (NTAccount)si.Translate(typeof(NTAccount));
<!--end_raw--></code>
<p>
The <code>Value</code> property of the <code>NTAccount</code> instance contains the name of the security group or user.
</p>
<code class="block"><!--start_raw-->
Console.WriteLine(acct.Value);
<!--end_raw--></code>
<p>
And for bonus points, here's a PowerShell function to do the same thing:
</p>
<code class="block"><!--start_raw-->
function GetWellKnownAccountName([string]$wellKnownSidType) {
    $si = new-object System.Security.Principal.SecurityIdentifier(
        [System.Security.Principal.WellKnownSidType]$wellKnownSidType, $null)
    $acct = $si.Translate([System.Security.Principal.NTAccount])
    return $acct.Value
}
<!--end_raw--></code>
<p>
Sample usage:
</p>
<code class="block"><!--start_raw-->
PS&gt; GetWellKnownAccountName("BuiltinAdministratorsSid")
BUILTIN\Administrators
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iterator.net/brannon/2007/05/getting-the-name-of-a-builtin-windows-security-object/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
