<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Initializing code</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx</link><description>A common question is how to initialize code before it is called. In the unmanaged world, this is done with a DLL_PROCESS_ATTACH notification to your DllMain routine. Managed C++ can actually use this same technique. However, it has all the usual restrictions</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>RE: Initializing code</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx#51349</link><pubDate>Wed, 16 Apr 2003 15:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51349</guid><dc:creator>Jeroen Frijters</dc:creator><description>Unfortunately, there is a (small) bug in the current implementation. Here is an example that successfully instantiates a type after the .cctor threw an exception:

using System;

class cctor
{
    static cctor()
    {
        new cctor();
        throw new Exception(&amp;quot;barf&amp;quot;);
    }
}

class Test
{
    static void Main(string[] args)
    {
        try
        {
            new cctor();
        }
        catch(Exception x)
        {
            Console.WriteLine(x);
        }
        try
        {
            new cctor();
            Console.WriteLine(&amp;quot;Hey, we got an instance!&amp;quot;);
        }
        catch(Exception x)
        {
            Console.WriteLine(x);
        }
    }
}
</description></item><item><title>RE: Initializing code</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx#51350</link><pubDate>Wed, 16 Apr 2003 17:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51350</guid><dc:creator>Chris Brumme</dc:creator><description>Yes, this is a known bug.  Unfortunately, we are too aggressive in wiring up callsites.  It's on the list to get fixed.</description></item><item><title>re: Initializing code</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx#114535</link><pubDate>Fri, 16 Apr 2004 15:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:114535</guid><dc:creator>Kenny</dc:creator><description>Great blog! Quick question: do we need to worry about multiple threads entering a cctor or does the CLR 'suspend' all threads accessing a type while it runs the class constructor? This kind of race condition with static initialization is an issue in C++. Is it the same in the CLR?</description></item><item><title>re: Initializing code</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx#114558</link><pubDate>Fri, 16 Apr 2004 16:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:114558</guid><dc:creator>Chris Brumme</dc:creator><description>Excepting the bug that Jeroen mentioned above, the CLR guards execution of a .cctor so that only one thread can proceed.  You do not need to perform any synchronization yourself.</description></item><item><title>Tidbit 2 &amp;laquo; Bug Vanquisher</title><link>http://blogs.msdn.com/cbrumme/archive/2003/04/15/51348.aspx#8996653</link><pubDate>Sun, 12 Oct 2008 17:29:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8996653</guid><dc:creator>Tidbit 2 &amp;laquo; Bug Vanquisher</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://tanveerbadar.wordpress.com/2008/10/12/tidbit-2/"&gt;http://tanveerbadar.wordpress.com/2008/10/12/tidbit-2/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>