<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://vladimirkofman.com/cs/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>Vladimir Kofman&amp;#39;s Blog</title><link>http://vladimirkofman.com/cs/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>IIS Crash</title><link>http://vladimirkofman.com/cs/archive/2008/06/01/iis-crash.aspx</link><pubDate>Sun, 01 Jun 2008 11:52:44 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:57</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=57</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2008/06/01/iis-crash.aspx#comments</comments><description>&lt;p&gt;It took about two long weeks of headaches... Long night talks with MS Support, frustrated customer, angry CEO... One simple hint in event viewer could save all that, but no, the error (or actually warning) didn't say much, and we had to find it the hard way. Those were the warnings in System event log:&lt;/p&gt; &lt;p&gt;&lt;em&gt;A process serving application pool '...' suffered a fatal communication error with the World Wide Web Publishing Service (IIS6)&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;A process serving application pool '...' suffered a fatal communication error with the Windows Process Activation Service (IIS7)&lt;/em&gt;&lt;/p&gt; &lt;p&gt;It seemed that after that warning, the IIS process just crashed. And we had to find the reason why:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@Page Language="C#"%&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;='server'&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;void&lt;/span&gt; Crash()
    {
        Crash();
    }
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&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;html&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;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Crashing Your IIS&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&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;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;Crash();&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&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;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&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;p&gt;Yes, it's definitely a bug, but why to crash all the process? Furthermore, isn't it that hard to put 'Stack overflow' error into event log?&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=57" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/.NET/default.aspx">.NET</category></item><item><title>An interceptor registered for ... doesnt implement the IMethodInterceptor interface</title><link>http://vladimirkofman.com/cs/archive/2008/03/11/an-interceptor-registered-for-doesnt-implement-the-imethodinterceptor-interface.aspx</link><pubDate>Tue, 11 Mar 2008 12:21:13 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:52</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=52</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2008/03/11/an-interceptor-registered-for-doesnt-implement-the-imethodinterceptor-interface.aspx#comments</comments><description>&lt;p&gt;That was the exception I was getting when tried to implement interceptors in &lt;a href="http://castleproject.org/container/index.html" target="_blank"&gt;Windsor&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I had no problem with "doesnt" (I wouldn't write this post because of it), my problem was &lt;strong&gt;IMethodInterceptor&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;It all started from samples I was trying to run. All samples on web clearly showed that I need to implement &lt;em&gt;IMethodInterceptor&lt;/em&gt;, but I couldn't find this interface in any of Castle's assemblies... After googling I've realized that the interface now (R3) has a new name: &lt;em&gt;IInterceptor&lt;/em&gt;. OK, that's easy - I just replaced the interface name with the new one, the app successfully compiled, but then at runtime I got the above exception...&lt;/p&gt; &lt;p&gt;Hmm... I thought I had the old Castle's version installed somewhere - but I didn't...&lt;/p&gt; &lt;p&gt;Then I've opened Reflector:&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; IInterceptor[] ObtainInterceptors(IKernel kernel, ComponentModel model)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;    IInterceptor[] interceptorArray = &lt;span class="kwrd"&gt;new&lt;/span&gt; IInterceptor[model.Interceptors.Count];&lt;/pre&gt;&lt;pre&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; num = 0;&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="rem"&gt;/*&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="rem"&gt;        Omitting the code for clarity...&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="rem"&gt;    */&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;        &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;        {&lt;/pre&gt;&lt;pre&gt;            IInterceptor interceptor = (IInterceptor) handler.Resolve(CreationContext.Empty);&lt;/pre&gt;&lt;pre class="alt"&gt;            interceptorArray[num++] = interceptor;&lt;/pre&gt;&lt;pre&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.SetOnBehalfAware(interceptor &lt;span class="kwrd"&gt;as&lt;/span&gt; IOnBehalfAware, model);&lt;/pre&gt;&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;continue&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;        }&lt;/pre&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (InvalidCastException)&lt;/pre&gt;&lt;pre&gt;        {&lt;/pre&gt;&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ApplicationException(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;/pre&gt;&lt;pre&gt;           &lt;span class="str"&gt;"An interceptor registered for {0} doesnt implement the IMethodInterceptor interface"&lt;/span&gt;,&lt;/pre&gt;&lt;pre class="alt"&gt;            model.Name));&lt;/pre&gt;&lt;pre&gt;        }&lt;/pre&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;pre&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; interceptorArray;&lt;/pre&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;&lt;font face="Tahoma"&gt;Aha, they've just forgot to change the message after changing the name of the interface! (Resharper would help with that :) ) &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma"&gt;Now it's clear, but still... what's wrong with my code, and why do I get this exception?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma"&gt;After looking at it for a while, I've finally realized what was the problem: There're actually two(!) &lt;em&gt;IInterceptor&lt;/em&gt; interfaces:&lt;/font&gt;&lt;/p&gt;&lt;pre&gt;&lt;font face="Tahoma" size="4"&gt;&lt;em&gt;Castle.DynamicProxy.IInterceptor&lt;/em&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre&gt;&lt;em&gt;&lt;font face="Tahoma" size="4"&gt;&lt;/font&gt;&lt;/em&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;font face="Tahoma" size="4"&gt;&lt;em&gt;Castle.Core.Interceptor.IInterceptor&lt;/em&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;&lt;font face="Tahoma"&gt;And I was using the wrong one :)&lt;/font&gt;&lt;/p&gt;&lt;pre&gt;&lt;font face="Tahoma"&gt;So, when defining interceptors for Windsor, you need to implement &lt;font size="4"&gt;&lt;em&gt;Castle.Core.Interceptor.IInterceptor&lt;/em&gt;&lt;/font&gt;.&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/div&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;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=52" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/IoC/default.aspx">IoC</category><category domain="http://vladimirkofman.com/cs/archive/tags/Fun/default.aspx">Fun</category><category domain="http://vladimirkofman.com/cs/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Developing native iPhone application on Windows</title><link>http://vladimirkofman.com/cs/archive/2007/12/07/developing-native-iphone-application-in-windows.aspx</link><pubDate>Fri, 07 Dec 2007 15:38:48 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:51</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=51</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/12/07/developing-native-iphone-application-in-windows.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;table cellspacing="0" cellpadding="2" width="644" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="306"&gt;I've built the development environment using the &lt;a href="http://iphone.fiveforty.net/wiki/index.php/Toolchain_installation_-_Windows#Toolchain" target="_blank"&gt;following link&lt;/a&gt;.&lt;br&gt;&lt;br&gt;It took me two sleepless nights,&lt;br&gt;but eventually it worked! Whew...&lt;br&gt;&lt;br&gt;This is the first time I'm dealing with Mac and Objective-C; Actually, it wasn't on my &lt;em&gt;must learn list, &lt;/em&gt;but it' so cool that I guess I'll just have to spend some time playing with this toy...&lt;/td&gt; &lt;td valign="top" width="339"&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/DevelopingnativeiPhoneapplicationinWindo_12254/snap_192838_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="My First iPhone Application" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/DevelopingnativeiPhoneapplicationinWindo_12254/snap_192838_thumb.jpg" width="324" align="right" border="0"&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/DevelopingnativeiPhoneapplicationinWindo_12254/snap_192838_2.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=51" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/iPhone/default.aspx">iPhone</category></item><item><title>My iPhone</title><link>http://vladimirkofman.com/cs/archive/2007/11/03/my-iphone.aspx</link><pubDate>Sat, 03 Nov 2007 21:13:44 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:50</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=50</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/11/03/my-iphone.aspx#comments</comments><description>&lt;p&gt;Here's how my blog looks from my new iPhone:&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/MyiPhone_1152/iPhone.jpg" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="346" alt="iPhone" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/MyiPhone_1152/iPhone_thumb.jpg" width="461" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Cool! (I mean the iPhone, not the blog)&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=50" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Fun/default.aspx">Fun</category></item><item><title>Automatic Properties in C# Orcas</title><link>http://vladimirkofman.com/cs/archive/2007/10/16/automatic-properties-in-c-orcas.aspx</link><pubDate>Tue, 16 Oct 2007 18:57:22 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:49</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=49</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/16/automatic-properties-in-c-orcas.aspx#comments</comments><description>&lt;p&gt;Quite often there's just a straightforward implementation for a property: private variable and getter/setter:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _MyInt;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MyInt
{
    get
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; _MyInt;
    }

    set
    {
        _MyInt = &lt;span class="kwrd"&gt;value&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;In C# Orcas it's possible to&amp;nbsp;express the above code as simple as:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MyInt { get; set; }&lt;/pre&gt;
&lt;p&gt;Couple of points: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;If we would look at generated IL code we would see that internally the (hidden) private variable and appropriate&amp;nbsp;get/set methods are generated (no magic here).&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Later on it's possible to add a specific implementation for get/set without recompiling client's code (that would be the case if we would move from an&amp;nbsp;instance variable to a property).&lt;/div&gt;&lt;/li&gt;&lt;/ul&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;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=49" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Iterators with C# 2.0</title><link>http://vladimirkofman.com/cs/archive/2007/10/14/iterators-with-c-2-0.aspx</link><pubDate>Sun, 14 Oct 2007 06:58:32 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:48</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=48</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/14/iterators-with-c-2-0.aspx#comments</comments><description>&lt;p&gt;Today I needed to implement an iterator for a custom collection. I remembered the&amp;nbsp;.NET 1.1 (tedious) experience&amp;nbsp;of implementing IEnumerator&amp;nbsp;manually, and was pleasantly surprised that with .NET 2.0 (or actually with C# 2.0)&amp;nbsp;it became much easier (and I'm not talking about Generics support that I would naturally expect anyway): all the boring stuff is created behind the scenes (and now at last I know what this &lt;strong&gt;yield&lt;/strong&gt; keyword does!):&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; MyCollection:IEnumerable
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt;[] stringArray = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[]{&lt;span class="str"&gt;"A"&lt;/span&gt;,&lt;span class="str"&gt;"B"&lt;/span&gt;,&lt;span class="str"&gt;"C"&lt;/span&gt;};

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerator GetEnumerator()
    {
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; str &lt;span class="kwrd"&gt;in&lt;/span&gt; stringArray)
        {
            &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; str;
        }
    }     
}

&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
    {
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;object&lt;/span&gt; x &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; MyCollection())
        {
            Console.WriteLine(x);
        }
    }
}&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;p&gt;So all that's needed is to "collect" the items using&amp;nbsp;&lt;em&gt;&lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt;&lt;/em&gt; statement. It looked like magic at first, but when I've checked the generated IL it contained the implementation of IEnumerator (so compiler generates it for us). &lt;/p&gt;
&lt;p&gt;It's important to understand that the GetEnumerator method above is not evaluated in a way that you would normally expect (all because of the &lt;em&gt;yield return&lt;/em&gt;), behind the scenes this language structure is "translated" into concrete IEnumerator class implementation with familiar &lt;em&gt;.MoveNext()&lt;/em&gt;, &lt;em&gt;.Current&lt;/em&gt;, &lt;em&gt;.Reset&lt;/em&gt; (which is deprecated now). So for example the following implementation is 100% valid:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerator GetEnumerator()
{
   &lt;span class="kwrd"&gt;while&lt;/span&gt;(&lt;span class="kwrd"&gt;true&lt;/span&gt;)
   {
       &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Random().Next();
   }
}&lt;/pre&gt;
&lt;p&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;
There's no infinite loop here, since the values will be "evaluated" one-by-one using &lt;em&gt;.MoveNext()&lt;/em&gt; during &lt;em&gt;foreach &lt;/em&gt;loop in the calling code (and that &lt;em&gt;foreach&lt;/em&gt; loop will actually control the exit criteria).&lt;/p&gt;
&lt;p&gt;There's another related statement: &lt;em&gt;yield break&lt;/em&gt;. At first I wondered why it is needed: OK, I read documentation that saying&amp;nbsp;that&amp;nbsp;it's needed to tell the client to stop looping, but why would I need a new structure for this? Couldn't I just use a regular return statement? It turns out that I couldn't: the &lt;em&gt;GetEnumerator()&amp;nbsp;&amp;nbsp;&lt;/em&gt;returns IEnumerator (which is created behind the scenes), so I can't just use return.&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=48" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/.NET/default.aspx">.NET</category></item><item><title>The easy way to run .sql scripts from .NET</title><link>http://vladimirkofman.com/cs/archive/2007/10/10/the-easy-way-to-run-sql-scripts-from-net.aspx</link><pubDate>Wed, 10 Oct 2007 17:52:01 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:45</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=45</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/10/the-easy-way-to-run-sql-scripts-from-net.aspx#comments</comments><description>&lt;p&gt;No need "to&amp;nbsp;shell" osql [via &lt;a href="http://weblogs.asp.net/jgalloway/default.aspx" target="_blank"&gt;Jon Galloway&lt;/a&gt;]:&lt;/p&gt; &lt;p&gt;&lt;a title="http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-_2D00_-the-easy-way.aspx" href="http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-_2D00_-the-easy-way.aspx"&gt;http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-_2D00_-the-easy-way.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=45" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>Synchronization Direction and Download Only Conflict Resolver</title><link>http://vladimirkofman.com/cs/archive/2007/10/10/synchronization-direction-and-download-only-conflict-resolver.aspx</link><pubDate>Wed, 10 Oct 2007 17:12:15 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:44</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=44</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/10/synchronization-direction-and-download-only-conflict-resolver.aspx#comments</comments><description>&lt;p&gt;I found no differences between the following two options:&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/SynchronizationDirectionandDownloadOnlyC_13819/DownloadOnly_1.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="115" alt="DownloadOnly" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/SynchronizationDirectionandDownloadOnlyC_13819/DownloadOnly_thumb_1.png" width="517" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/SynchronizationDirectionandDownloadOnlyC_13819/DownloadOnly2.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="117" alt="DownloadOnly2" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/SynchronizationDirectionandDownloadOnlyC_13819/DownloadOnly2_thumb.png" width="361" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;It&amp;nbsp;seems&amp;nbsp;just as&amp;nbsp;two different&amp;nbsp;ways to achieve exactly the same thing...&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=44" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Replication/default.aspx">Replication</category><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>BCP Error When Applying a Snapshot</title><link>http://vladimirkofman.com/cs/archive/2007/10/10/bcp-error-when-applying-a-snapshot.aspx</link><pubDate>Wed, 10 Oct 2007 16:29:03 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:42</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=42</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/10/bcp-error-when-applying-a-snapshot.aspx#comments</comments><description>&lt;p&gt;If the schemas on publisher and subscriber are the essentially the same, but only differ by order of columns:&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/BCPErrorwhenapplyinginitialsnapshot_14A17/DifferentSchemas_1.jpg" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="111" alt="DifferentSchemas" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/BCPErrorwhenapplyinginitialsnapshot_14A17/DifferentSchemas_thumb_1.jpg" width="444" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Then when applying a snapshot, if &lt;a href="http://vladimirkofman.com/archive/2007/09/15/mss2005-merge-replication-error-incorrect-syntax-near.aspx" target="_blank"&gt;'Action if name in use'&lt;/a&gt; option is set to anything other than &lt;em&gt;'Drop existing object and create a new one'&lt;/em&gt;,&amp;nbsp;the&amp;nbsp;BCP will throw &lt;em&gt;'Field size too large'&lt;/em&gt; exception. That's just another "meaningful" replication-related error from Microsoft... So, if you want to use BCP (snapshots) publisher's and subscribers' schemas should be &lt;em&gt;&lt;strong&gt;exactly&lt;/strong&gt; &lt;/em&gt;the same.&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=42" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Replication/default.aspx">Replication</category><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>Reinitialize Subscription Error</title><link>http://vladimirkofman.com/cs/archive/2007/10/07/reinitialize-subscription-error.aspx</link><pubDate>Sun, 07 Oct 2007 18:25:29 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:40</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=40</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/10/07/reinitialize-subscription-error.aspx#comments</comments><description>&lt;p&gt;When I was trying to reinitialize a subscription I was constantly getting a "PK violation error" on one of the tables. &lt;/p&gt; &lt;p&gt;At first I thought there was a problem with that specific table: I suspected that&amp;nbsp;"Unique key" join option for that table was wrong, but the error was still there when I&amp;nbsp;unchecked&amp;nbsp;the "Unique key" option.&amp;nbsp;When I removed&amp;nbsp;the PK for that table&amp;nbsp;on a subscriber, the synchronization failed with the same PK violation error but for another table... &lt;/p&gt; &lt;p&gt;After exploring it a bit more I've found that the problem was related to "&lt;a href="http://vladimirkofman.com/archive/2007/09/15/mss2005-merge-replication-error-incorrect-syntax-near.aspx" target="_blank"&gt;Action if name in use&lt;/a&gt;" option: if "Keep existing objects unchanged" is selected, during the synchronization process already existing rows are rewritten into a subscribers' table&amp;nbsp;- which&amp;nbsp;causes PK violation. So with that option,&amp;nbsp;there's actually no way to reinitialize a subscription (I would actually expect a&amp;nbsp;meaningful warning in that case... - and not just PK violation error). So, when I selected "Truncate data..." option, the PK error disappeared and sync finished OK.&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=40" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Replication/default.aspx">Replication</category><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>Microsoft Replication Conflict Viewer Exception</title><link>http://vladimirkofman.com/cs/archive/2007/09/18/microsoft-replication-conflict-viewer-exception.aspx</link><pubDate>Tue, 18 Sep 2007 13:50:58 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:39</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=39</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/09/18/microsoft-replication-conflict-viewer-exception.aspx#comments</comments><description>&lt;p&gt;I didn't use Photoshop (well... in fact I did, but only to hide the real DB/Servers details):&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/MicrosoftReplicationConflictViewerExcept_1177D/ConflictViewerErrorSmall_1.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="499" alt="ConflictViewerErrorSmall" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/MicrosoftReplicationConflictViewerExcept_1177D/ConflictViewerErrorSmall_thumb_1.png" width="666" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=39" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Replication/default.aspx">Replication</category><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category><category domain="http://vladimirkofman.com/cs/archive/tags/Fun/default.aspx">Fun</category></item><item><title>MSS2005 Merge Replication Error: 'Incorrect syntax near...'</title><link>http://vladimirkofman.com/cs/archive/2007/09/15/mss2005-merge-replication-error-incorrect-syntax-near.aspx</link><pubDate>Sat, 15 Sep 2007 16:26:43 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:38</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=38</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/09/15/mss2005-merge-replication-error-incorrect-syntax-near.aspx#comments</comments><description>&lt;p&gt;I've&amp;nbsp;received a new requirement: publisher and subscriber should use different sets of triggers (for a specific table). I thought it wouldn't be a problem:&amp;nbsp;I remembered that there was an option to &lt;em&gt;'Copy user triggers'&lt;/em&gt;, so I just needed to set it to 'False':&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_4.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="298" alt="image" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_thumb_4.png" width="455" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;But, for some reason the triggers at&amp;nbsp;a&amp;nbsp;subscriber were always deleted after synchronization... Then I've noticed another option: '&lt;em&gt;Action if name is in use'&lt;/em&gt;: &lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_5.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="330" alt="image" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_thumb_5.png" width="587" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The default value for the above option is&amp;nbsp;&lt;em&gt;'Drop existing object and create a new one'&lt;/em&gt;', and that explains why the triggers at subscriber disappear:&amp;nbsp;they're deleted since the table is&amp;nbsp;dropped and recreated. Previously publisher's&amp;nbsp;triggers were copied to the subscriber, but now&amp;nbsp;after I've changed the '&lt;em&gt;Copy user triggers&lt;/em&gt;' option it doesn't happen anymore. So, I just needed to avoid that &lt;em&gt;Drop &lt;/em&gt;option (any other option should leave the subscriber's triggers intact). But, when I fixed&amp;nbsp;that and tried to synchronize I've got the following error:&lt;/p&gt;&lt;pre class="csharpcode"&gt;{&lt;span class="kwrd"&gt;call&lt;/span&gt; sp_MSsetconflicttable 
      (N&lt;span class="str"&gt;'table3'&lt;/span&gt;,
       N&lt;span class="str"&gt;'MSmerge_conflict_MyTestPublication_table3'&lt;/span&gt;,
       N&lt;span class="str"&gt;'VLADIMIR'&lt;/span&gt;,
       N&lt;span class="str"&gt;'TestDB'&lt;/span&gt;,
       N&lt;span class="str"&gt;'MyTestPublication'&lt;/span&gt;)}
... &lt;em&gt;Incorrect syntax near 'id':&lt;/em&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_6.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="139" alt="image" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/AnothercrazyReplicationException_8CD4/image_thumb_6.png" width="615" border="0"&gt;&lt;/a&gt; &lt;/p&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;Incorrect syntax? Syntax error in Microsoft's internal procedure? What have I done wrong?&lt;/p&gt;
&lt;p&gt;At least I had a problematic table name. After looking at the table schema both on publisher and subscriber I've noticed that rowguid column (which tracks merge replication changes) was missing from subscriber's schema: (in my case the subscriber's schema is generated offline, not through initial sync from publisher; so&amp;nbsp;there was a bug in that script). Well, I would expect an error in this case, but something more informative than 'Incorrect syntax near...'. &lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=38" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Replication/default.aspx">Replication</category><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>Deleting duplicate rows from a table in SQL Server 2005</title><link>http://vladimirkofman.com/cs/archive/2007/09/01/deleting-duplicate-rows-from-a-table-in-sql-server-2005.aspx</link><pubDate>Sat, 01 Sep 2007 15:53:09 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:37</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=37</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/09/01/deleting-duplicate-rows-from-a-table-in-sql-server-2005.aspx#comments</comments><description>&lt;p&gt;Here's the situation: I have a table without a primary key (or any other unique constraint). Don't ask me why, since I have no control over the database in this case. To make it even worse, there's a business-logic bug&amp;nbsp;that&amp;nbsp;inserts identical rows in that table (all columns have identical values). OK you fix the bug, but how&amp;nbsp;do you cleanup the table&amp;nbsp;not to contain those duplicate rows? It's not that easy as it sounds at first...&amp;nbsp;&amp;nbsp;Here's the concrete example:&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; TableWithoutPK(col1 &lt;span class="kwrd"&gt;int&lt;/span&gt;, col2 &lt;span class="kwrd"&gt;int&lt;/span&gt;, col3 &lt;span class="kwrd"&gt;char&lt;/span&gt;(10))
insert &lt;span class="kwrd"&gt;into&lt;/span&gt; TableWithoutPK &lt;span class="kwrd"&gt;values&lt;/span&gt; (1, 1, &lt;span class="str"&gt;'ABC'&lt;/span&gt;)
insert &lt;span class="kwrd"&gt;into&lt;/span&gt; TableWithoutPK &lt;span class="kwrd"&gt;values&lt;/span&gt; (1, 1, &lt;span class="str"&gt;'ABC'&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;I've tried to use my own&amp;nbsp;SQL knowledge to resolve this puzzle, but with no much success. So I've started googling: at first I've found &lt;a href="http://support.microsoft.com/kb/139444" target="_blank"&gt;this&lt;/a&gt; KB article, but it seemed too cumbersome. Actually, I was going in that direction, but creating temporary tables and detailing every column for&amp;nbsp;&lt;em&gt;GROUP BY &lt;/em&gt;clause was not&amp;nbsp;something I wanted to do; I was looking for a more generic solution.&amp;nbsp;&amp;nbsp;And then in one of the forums (unfortunately now I can't find the original one... otherwise I would share&amp;nbsp;the link) I saw how people are using&amp;nbsp;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms189461.aspx" target="_blank"&gt;OVER TSQL Clause&lt;/a&gt; (which is new in SQL2005), and that brought me to a more&amp;nbsp;elegant solution:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;DELETE&lt;/span&gt; tmp &lt;span class="kwrd"&gt;FROM&lt;/span&gt; ( 
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; ROW_NUMBER() 
    &lt;span class="kwrd"&gt;OVER&lt;/span&gt; (&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; col1) &lt;span class="kwrd"&gt;AS&lt;/span&gt; rownum 
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt; TableWithoutPK
) &lt;span class="kwrd"&gt;AS&lt;/span&gt; tmp &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; rownum &amp;gt; 1&lt;/pre&gt;
&lt;p&gt;So, at last Oracle's rownum cousin is available in MSS as well! (and at last paging functionality could be properly implemented with MSS - but that's already a different story).&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=37" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/MSSQL/default.aspx">MSSQL</category></item><item><title>.NET Exception at EUROSPORT.RU</title><link>http://vladimirkofman.com/cs/archive/2007/09/01/net-exception-at-eurosport-ru.aspx</link><pubDate>Sat, 01 Sep 2007 04:07:47 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:36</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=36</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/09/01/net-exception-at-eurosport-ru.aspx#comments</comments><description>&lt;p&gt;Here's a good example of bad error handling:&lt;/p&gt; &lt;p&gt;&lt;a href="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/.NETExceptionatEUROSPORT.RU_8EF5/EurosportError.gif" atomicselection="true"&gt;&lt;img height="319" alt="EurosportError" src="http://vladimirkofman.com/images/myblog/WindowsLiveWriter/.NETExceptionatEUROSPORT.RU_8EF5/EurosportError_thumb.gif" width="622"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=36" width="1" height="1"&gt;</description><category domain="http://vladimirkofman.com/cs/archive/tags/Fun/default.aspx">Fun</category></item><item><title>HAS-A relationships in Visual Studio Class Diagram</title><link>http://vladimirkofman.com/cs/archive/2007/07/07/has-a-relationships-in-visual-studio-class-diagram.aspx</link><pubDate>Sat, 07 Jul 2007 18:32:08 GMT</pubDate><guid isPermaLink="false">c6974423-eee6-405f-ad43-26e2febcfffe:6</guid><dc:creator>VladimirKofman</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://vladimirkofman.com/cs/rsscomments.aspx?PostID=6</wfw:commentRss><comments>http://vladimirkofman.com/cs/archive/2007/07/07/has-a-relationships-in-visual-studio-class-diagram.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve just found a cool feature in Visual Studio Class Diagram designer that I wasn&amp;#39;t aware of: I didn&amp;#39;t know that there&amp;#39;s a way to represent a composition relationship (HAS-A) in the diagram! More than once I felt it was missing, but instead of looking under my nose I&amp;#39;ve always returned to Visio to draw my class diagrams. So if we have the following class structure (here I&amp;#39;m using fields just to be concise&amp;nbsp;- but the same works for properties as well):&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;class&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt; &lt;span style="color:#2b91af;"&gt;Blog&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;{&lt;span style="color:#2b91af;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Post&lt;/span&gt;&amp;gt; _Posts;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;class&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt; &lt;span style="color:#2b91af;"&gt;Post&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Blog&lt;/span&gt; _Blog;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Comment&lt;/span&gt;&amp;gt; _Comments;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;class&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt; &lt;span style="color:#2b91af;"&gt;Comment&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom:0pt;line-height:normal;mso-layout-grid-align:none;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Post&lt;/span&gt; _Post;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;mso-bidi-language:he;mso-no-proof:yes;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;In the class diagram it looks like this:&lt;/p&gt; &lt;p&gt;&lt;a title="ClassDiagram" href="http://www.flickr.com/photos/8921196@N06/727900822/"&gt;&lt;img alt="ClassDiagram" src="http://static.flickr.com/1288/727900822_b361728782.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And all that&amp;#39;s needed is to define per Field/Property to show it as a(Collection) Association.&lt;/p&gt; &lt;p&gt;&lt;a title="ClassDiagram2" href="http://www.flickr.com/photos/8921196@N06/727133053/"&gt;&lt;img alt="ClassDiagram2" src="http://static.flickr.com/1241/727133053_7b1eed5a07.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Cool :)&lt;/p&gt;&lt;img src="http://vladimirkofman.com/cs/aggbug.aspx?PostID=6" width="1" height="1"&gt;</description></item></channel></rss>