﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>https://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>I tell you, that thing is a bona fide ZEBRA, or a tale of being utterly stupid</title><description>&lt;p&gt;&lt;img style="float: right; display: inline" alt="" src="https://s-media-cache-ak0.pinimg.com/736x/d9/b7/2f/d9b72f5a1367b9650304a60b6d3b8705.jpg" width="189" align="right" height="240"&gt;We run our test suite in a loop to discover any race conditions, timing issues, errors, etc. When doing so, we got a hard crash from the dotnet.exe, and investigating the issue produced a stack trace inside the GC.&lt;/p&gt; &lt;p&gt;So I took a dump of the process memory, and created an &lt;a href="https://github.com/dotnet/coreclr/issues/6160#issuecomment-231883756"&gt;issue about that&lt;/a&gt; with the CoreCLR repository, while giving it a very high priority internally, and having someone look at that very closely. We are using unsafe code extensively, so it was either a real GC bug or we messed up somewhere are corrupted our own state.&lt;/p&gt; &lt;p&gt;Very quickly &lt;a href="https://github.com/jkotas"&gt;Jan Kotas&lt;/a&gt; was able to point out that it was a heap corruption issue as well as the likely avenues for investigation.&lt;/p&gt; &lt;p&gt;After looking at this, we found that the problem was in our tests. In particular, in one specific test. In order to test the memory corruption, we changed it to add markers on where it overwrote the buffer, and the test passed.&lt;/p&gt; &lt;p&gt;This caused us additional concern, because the only thing we could think about was that maybe there is some invariant that is being broken. Our suspicion focused on the fixed statement in C# not working properly. Yes, I know, “hoof beats, horses, not zebras”.&lt;/p&gt; &lt;p&gt;So I went to the issue again and reported my finding, and &lt;a href="https://github.com/AndyAyersMS"&gt;Andy Ayers&lt;/a&gt; was kind enough to find the problem, and point it to me.&lt;/p&gt; &lt;p&gt;Here is the relevant test code:&lt;/p&gt; &lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/I-tell-you-that-thing-is-a-bona-fide_2692/image_2.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/I-tell-you-that-thing-is-a-bona-fide_2692/image_thumb.png" width="1076" height="479"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is during debugging, so you can see what the problem is. We defined size to be 40, and we defined an input buffer, whose size is &lt;em&gt;100&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;A little bit below, we created an output buffer based on the size variable (40), and then wrote to it with the expected size of input.Length, which is 100. Everything behaved as it should, and we had a buffer overrun in the test, the heap was corrupted, and sometimes the GC died.&lt;/p&gt; &lt;p&gt;Also, I feel very stupid about spouting all sort of nonsense about bugs in the CLR when our code is unable to do simple arithmetic.&lt;/p&gt; &lt;p&gt;The good news, the bug was only in the tests, and the kind of support that you get from Microsoft on the CoreCLR is absolutely &lt;em&gt;phenomenal&lt;/em&gt;. Thank you very much guys.&lt;/p&gt;</description><link>https://ayende.com/blog/174947/i-tell-you-that-thing-is-a-bona-fide-zebra-or-a-tale-of-being-utterly-stupid?Key=c43b9ab1-a04f-43e3-b175-6f3755b0cf4a</link><guid>https://ayende.com/blog/174947/i-tell-you-that-thing-is-a-bona-fide-zebra-or-a-tale-of-being-utterly-stupid?Key=c43b9ab1-a04f-43e3-b175-6f3755b0cf4a</guid><pubDate>Tue, 09 Aug 2016 09:00:00 GMT</pubDate></item><item><title>Answering a code test like a literature pop quiz</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Windows-Live-Writer/Answering-a-code-test-like-a-literature-_BC1A/image_5.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: right; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://ayende.com/blog/Images/Windows-Live-Writer/Answering-a-code-test-like-a-literature-_BC1A/image_thumb_1.png" width="240" align="right" height="211"&gt;&lt;/a&gt;We get some… fascinating replies from candidates to our code tests. Some of them are so bad that I really wish that I could revoke some people’s keyboard access:&lt;/p&gt; &lt;p&gt;Case in point, we had a promising candidate from Israel’s equivalent of MIT (Technion, which is in the top 25 engineering schools in the world).&lt;/p&gt; &lt;p&gt;He submitted code that went something like this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var nameFirstChar = &lt;span class="kwrd"&gt;char&lt;/span&gt;.Parse(name.Substring(0,1).ToLower());

&lt;span class="kwrd"&gt;switch&lt;/span&gt; (nameFirstChar)
{                                
    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;'a'&lt;/span&gt;:
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (StreamWriter indexFile = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamWriter(Path.Combine(basePath, &lt;span class="str"&gt;"Name_IndeX_A.csv"&lt;/span&gt;), &lt;span class="kwrd"&gt;true&lt;/span&gt;))
        {
            indexFile.WriteLine(name);
        }
        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;'b'&lt;/span&gt;:
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (StreamWriter indexFile = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamWriter(Path.Combine(basePath, &lt;span class="str"&gt;"Name_IndeX_B.csv"&lt;/span&gt;), &lt;span class="kwrd"&gt;true&lt;/span&gt;))
        {
            indexFile.WriteLine(name);
        }
        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    &lt;span class="rem"&gt;// ...&lt;/span&gt;
    &lt;span class="rem"&gt;// you can guess :-(&lt;/span&gt;
    &lt;span class="rem"&gt;// ...&lt;/span&gt;
    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;'y'&lt;/span&gt;:
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (StreamWriter indexFile = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamWriter(Path.Combine(basePath, &lt;span class="str"&gt;"Name_IndeX_Y.csv"&lt;/span&gt;), &lt;span class="kwrd"&gt;true&lt;/span&gt;))
        {
            indexFile.WriteLine(name);
        }
        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;'z'&lt;/span&gt;:
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (StreamWriter indexFile = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamWriter(Path.Combine(basePath, &lt;span class="str"&gt;"Name_IndeX_Z.csv"&lt;/span&gt;), &lt;span class="kwrd"&gt;true&lt;/span&gt;))
        {
            indexFile.WriteLine(name);
        }
        &lt;span class="kwrd"&gt;break&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;/blockquote&gt;
&lt;p&gt;And yes, he had the full A-Z there. This was part of a 1475 lines methods. And no, he didn’t handle all the cases for Unicode.&lt;/p&gt;
&lt;p&gt;Yes, he just graduated, but &lt;em&gt;some&lt;/em&gt; things are expected. Like knowing about loops.&lt;/p&gt;</description><link>https://ayende.com/blog/173186/answering-a-code-test-like-a-literature-pop-quiz?Key=8b78f307-e491-4a43-903b-4049dcc2ca8c</link><guid>https://ayende.com/blog/173186/answering-a-code-test-like-a-literature-pop-quiz?Key=8b78f307-e491-4a43-903b-4049dcc2ca8c</guid><pubDate>Tue, 09 Feb 2016 10:00:00 GMT</pubDate></item><item><title>How to ensure that you won’t get hired, quickly</title><description>&lt;p&gt;I’m currently reviewing CVs, seemingly by the hundreds*. And I run into a guy which has a Github profile link in the CV. Such links are &lt;em&gt;always &lt;/em&gt;followed, because seeing someone’s actual work is so much better than just reading some document about it.&lt;/p&gt; &lt;p&gt;But then I saw this:&lt;/p&gt; &lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Windows-Live-Writer/How-to-ensure-that-you-wont-get-hired-qu_928B/image_2.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://ayende.com/blog/Images/Windows-Live-Writer/How-to-ensure-that-you-wont-get-hired-qu_928B/image_thumb.png" width="348" height="89"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And looking into the actual repository we have:&lt;/p&gt; &lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Windows-Live-Writer/How-to-ensure-that-you-wont-get-hired-qu_928B/image_4.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://ayende.com/blog/Images/Windows-Live-Writer/How-to-ensure-that-you-wont-get-hired-qu_928B/image_thumb_1.png" width="421" height="89"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;While this isn’t quite enough to give you a Darwin Award in the job hunting department (sadly, I saw worse), how could anyone think that having a publicly visible repository that &lt;em&gt;says&lt;/em&gt; “I do illegal things to software” is a good idea. Leaving aside that you &lt;em&gt;link that from your CV&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;* It isn’t that many, it is just annoying.&lt;/p&gt;</description><link>https://ayende.com/blog/172771/how-to-ensure-that-you-wont-get-hired-quickly?Key=1930bc53-6e88-4dc4-9ce0-a5106ff523d9</link><guid>https://ayende.com/blog/172771/how-to-ensure-that-you-wont-get-hired-quickly?Key=1930bc53-6e88-4dc4-9ce0-a5106ff523d9</guid><pubDate>Tue, 19 Jan 2016 10:00:00 GMT</pubDate></item><item><title>Production postmortem: The case of the man in the middle</title><description>&lt;p&gt;One of the most frustrating things when you dealing with production issues is when the problem is not in our product, but elsewhere. In particular, this post is dedicated to the hard work done by many anti virus products, in particular, to make our life harder.&lt;/p&gt; &lt;p&gt;Let us take a look at the following quote, taken from the &lt;a href="http://kb.eset.com/esetkb/index?page=content&amp;amp;id=SOLN939"&gt;ESET NOD32 Anti Virus knowledge base&lt;/a&gt; (emphasis mine):&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;By default, your ESET product automatically detects programs that are used as web browsers and email clients, and adds them to the list of programs that the internal proxy scans. &lt;strong&gt;This can cause loss of internet connectivity or other undesired results with applications that use network features&lt;/strong&gt; but are not web browsers/email clients.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Yes, it can. In fact, it very often does. &lt;/p&gt; &lt;p&gt;Previously, we looked at a similar issue with &lt;a href="http://ayende.com/blog/171074/production-postmortem-the-case-of-the-infected-cluster"&gt;Anti Virus slowing down I/O&lt;/a&gt; enough to cause us to slowly die. But in this case, the issue is a lot more subtle.&lt;/p&gt; &lt;p&gt;Because it is doing content filtering, it tends to put a much higher overhead on the system resources, which means that as far as the user is concerned, RavenDB is slow. We actually developed features specifically to handle this scenario. The &lt;a href="http://ayende.com/blog/168516/what-is-new-in-ravendb-3-0-operations-production-view"&gt;traffic watch&lt;/a&gt; mode will tell you how much time you spend on the server side, and we have added a feature that will make RavenDB account for the internal work each query is doing, so we can tell where the actual cost is.&lt;/p&gt; &lt;p&gt;You can enable that by issuing:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;GET databases/Northwind/debug/enable-query-timing&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;And one that is setup, you can get a good idea about what is costly in the query, as far as RavenDB is concerned. Here is an example of a very slow query:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Production-postmortem_1306F/image_2.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Production-postmortem_1306F/image_thumb.png" width="429" height="190"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;You can see that the issue is that we are issuing a very wide range query, so most of the time is spent in inside Lucene. Other examples might be ridicilously complex queries, which result in high parsing time (we have seen &lt;em&gt;queries&lt;/em&gt; in the hundreds of KB range). Or loading a lot of big documents, or… you get the drift. If we see that the server thinks that a query is fast, but the overall time is slow, we know to blame the network.&lt;/p&gt; &lt;p&gt;But an even more insidious issue is that this would drop requests,&amp;nbsp; consistently and randomly (and yes, I know that those are contradictions, it was consistently dropping requests in a random pattern that seemed explicitly designed to thwart figuring out what is going on). Leading to things breaking, and escalated support calls. “RavenDB is broken” leads to a lot of headache, and a burning desire to hit something when you figure out that not only isn’t it your fault, but the underlying reason is actively trying to &lt;em&gt;prevent&lt;/em&gt; you from figuring it out (I assume it is to deal with viruses that try to shut it off), which lead to really complex find facting sessions.&lt;/p&gt; &lt;p&gt;That is more annoying because it seems that the issue there was a bug in respecting keep alive sessions for authenticated requests under some scenarios, in the AV product in question! Absolutely not fun!&lt;/p&gt;</description><link>https://ayende.com/blog/171683/production-postmortem-the-case-of-the-man-in-the-middle?Key=508ba398-8457-4ff4-8f4f-f964b0283dde</link><guid>https://ayende.com/blog/171683/production-postmortem-the-case-of-the-man-in-the-middle?Key=508ba398-8457-4ff4-8f4f-f964b0283dde</guid><pubDate>Fri, 14 Aug 2015 09:00:00 GMT</pubDate></item><item><title>Is select() broken? Memory mapped files with unbufferred writes == race condition?</title><description>&lt;p&gt;Let me start this post by stating that I am not even sure if what I am trying to do is legal here. But from reading the docs, it does appear to be a valid use of the API, and it does work, most of the time.&lt;/p&gt; &lt;p&gt;The full code can be found here: &lt;a href="https://gist.github.com/ayende/7495987"&gt;https://gist.github.com/ayende/7495987&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The gist of it is that I am trying to do two things:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Write to a file opened with FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING.&lt;/li&gt; &lt;li&gt;Read from this file using a memory map.&lt;/li&gt; &lt;li&gt;Occasionally, I get into situations where after I wrote to the file, I am not reading what I wrote.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;I have a repro&lt;/strong&gt;, and we reproduced this on multiple machines. Both Windows 7 and Windows 8.&lt;/p&gt; &lt;p&gt;Here is the relevant code (the full code is in the link), explanation on it below:&lt;/p&gt; &lt;blockquote&gt; &lt;div id="codeSnippetWrapper"&gt; &lt;div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum1" style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; nNumberOfBytesToWrite = 4096*3;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum2" style="color: #606060"&gt;   2:&lt;/span&gt; var buffer = (&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;*)(VirtualAlloc(IntPtr.Zero, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UIntPtr(nNumberOfBytesToWrite), AllocationType.COMMIT, MemoryProtection.READWRITE)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum3" style="color: #606060"&gt;   3:&lt;/span&gt;             .ToPointer());&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum4" style="color: #606060"&gt;   4:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum5" style="color: #606060"&gt;   5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; nNumberOfBytesToWrite; i++)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum6" style="color: #606060"&gt;   6:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum7" style="color: #606060"&gt;   7:&lt;/span&gt;     *(buffer + i) = 137;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum8" style="color: #606060"&gt;   8:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum9" style="color: #606060"&gt;   9:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum10" style="color: #606060"&gt;  10:&lt;/span&gt; var g = Guid.NewGuid().ToString();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum11" style="color: #606060"&gt;  11:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum12" style="color: #606060"&gt;  12:&lt;/span&gt; var safeHandle = CreateFile(g,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum13" style="color: #606060"&gt;  13:&lt;/span&gt;     NativeFileAccess.GenericRead | NativeFileAccess.GenericWrite,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum14" style="color: #606060"&gt;  14:&lt;/span&gt;     NativeFileShare.Read, IntPtr.Zero,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum15" style="color: #606060"&gt;  15:&lt;/span&gt;     NativeFileCreationDisposition.OpenAlways,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum16" style="color: #606060"&gt;  16:&lt;/span&gt;     NativeFileAttributes.Write_Through | NativeFileAttributes.NoBuffering | NativeFileAttributes.DeleteOnClose,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum17" style="color: #606060"&gt;  17:&lt;/span&gt;     IntPtr.Zero);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum18" style="color: #606060"&gt;  18:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum19" style="color: #606060"&gt;  19:&lt;/span&gt; var fileStream = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileStream(safeHandle, FileAccess.ReadWrite);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum20" style="color: #606060"&gt;  20:&lt;/span&gt; fileStream.SetLength(1024 * 1024 * 1024); &lt;span style="color: #008000"&gt;// 1gb&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum21" style="color: #606060"&gt;  21:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum22" style="color: #606060"&gt;  22:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (safeHandle.IsInvalid)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum23" style="color: #606060"&gt;  23:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum24" style="color: #606060"&gt;  24:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Win32Exception();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum25" style="color: #606060"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum26" style="color: #606060"&gt;  26:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum27" style="color: #606060"&gt;  27:&lt;/span&gt; FileStream mms = fileStream;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum28" style="color: #606060"&gt;  28:&lt;/span&gt; &lt;span style="color: #008000"&gt;//mms = new FileStream(g, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum29" style="color: #606060"&gt;  29:&lt;/span&gt; var mmf = MemoryMappedFile.CreateFromFile(mms, Guid.NewGuid().ToString(), fileStream.Length,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum30" style="color: #606060"&gt;  30:&lt;/span&gt;     MemoryMappedFileAccess.Read, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, HandleInheritability.None, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum31" style="color: #606060"&gt;  31:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum32" style="color: #606060"&gt;  32:&lt;/span&gt; MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(0, fileStream.Length, MemoryMappedFileAccess.Read);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum33" style="color: #606060"&gt;  33:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;* ptr = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum34" style="color: #606060"&gt;  34:&lt;/span&gt; accessor.SafeMemoryMappedViewHandle.AcquirePointer(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; ptr);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum35" style="color: #606060"&gt;  35:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum36" style="color: #606060"&gt;  36:&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum37" style="color: #606060"&gt;  37:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum38" style="color: #606060"&gt;  38:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; lastPos = 0;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum39" style="color: #606060"&gt;  39:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum40" style="color: #606060"&gt;  40:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum41" style="color: #606060"&gt;  41:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; count = 0;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum42" style="color: #606060"&gt;  42:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum43" style="color: #606060"&gt;  43:&lt;/span&gt;         {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum44" style="color: #606060"&gt;  44:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (*(ptr + lastPos) != 137)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum45" style="color: #606060"&gt;  45:&lt;/span&gt;             {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum46" style="color: #606060"&gt;  46:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum47" style="color: #606060"&gt;  47:&lt;/span&gt;             }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum48" style="color: #606060"&gt;  48:&lt;/span&gt;             lastPos += 4096;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum49" style="color: #606060"&gt;  49:&lt;/span&gt;             count ++;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum50" style="color: #606060"&gt;  50:&lt;/span&gt;         }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum51" style="color: #606060"&gt;  51:&lt;/span&gt;         Console.WriteLine();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum52" style="color: #606060"&gt;  52:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: #006080"&gt;"Verified {0} MB"&lt;/span&gt;, count * 4 / 1024);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum53" style="color: #606060"&gt;  53:&lt;/span&gt;         Console.WriteLine();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum54" style="color: #606060"&gt;  54:&lt;/span&gt;         Thread.Sleep(2000);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum55" style="color: #606060"&gt;  55:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum56" style="color: #606060"&gt;  56:&lt;/span&gt; });&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum57" style="color: #606060"&gt;  57:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum58" style="color: #606060"&gt;  58:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 1024*64; i++)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum59" style="color: #606060"&gt;  59:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum60" style="color: #606060"&gt;  60:&lt;/span&gt;     var pos = i*nNumberOfBytesToWrite;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum61" style="color: #606060"&gt;  61:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i%100 == 0)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum62" style="color: #606060"&gt;  62:&lt;/span&gt;         Console.Write(&lt;span style="color: #006080"&gt;"\r{0,10:#,#} kb"&lt;/span&gt;, pos/1024);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum63" style="color: #606060"&gt;  63:&lt;/span&gt;     var nativeOverlapped = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NativeOverlapped&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum64" style="color: #606060"&gt;  64:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum65" style="color: #606060"&gt;  65:&lt;/span&gt;         OffsetHigh = 0,&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum66" style="color: #606060"&gt;  66:&lt;/span&gt;         OffsetLow = (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;) pos&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum67" style="color: #606060"&gt;  67:&lt;/span&gt;     };&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum68" style="color: #606060"&gt;  68:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum69" style="color: #606060"&gt;  69:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; written;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum70" style="color: #606060"&gt;  70:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (WriteFile(safeHandle, buffer, nNumberOfBytesToWrite, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; written, &amp;amp;nativeOverlapped) == &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum71" style="color: #606060"&gt;  71:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Win32Exception();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum72" style="color: #606060"&gt;  72:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum73" style="color: #606060"&gt;  73:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; j = 0; j &amp;lt; 3; j++)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum74" style="color: #606060"&gt;  74:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum75" style="color: #606060"&gt;  75:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (*(ptr + pos) != 137)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum76" style="color: #606060"&gt;  76:&lt;/span&gt;         {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum77" style="color: #606060"&gt;  77:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #006080"&gt;"WTF?!"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum78" style="color: #606060"&gt;  78:&lt;/span&gt;         }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum79" style="color: #606060"&gt;  79:&lt;/span&gt;         pos += 4096;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"&gt;&lt;span id="lnum80" style="color: #606060"&gt;  80:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"&gt;&lt;span id="lnum81" style="color: #606060"&gt;  81:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;This code is doing the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We setup a file handle using NoBuffering | Write_Through, and we also map the file using memory map.&lt;/li&gt;
&lt;li&gt;We write 3 pages (12Kb) at a time to the file.&lt;/li&gt;
&lt;li&gt;After the write, we are using memory map to verify that we actually wrote what we wanted to the file.&lt;/li&gt;
&lt;li&gt;_At the same time_ we are reading from the same memory in another thread.&lt;/li&gt;
&lt;li&gt;Occasionally, we get an error where the data we just wrote to the file cannot be read back.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now, here is what I think is actually happening:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When we do an unbuffered write, Windows has to mark the relevant pages as invalid.&lt;/li&gt;
&lt;li&gt;I _think_ that it does so before it actually perform the write.&lt;/li&gt;
&lt;li&gt;If you have another thread that access that particular range of memory at the same time, it can load the _previously_ written data.&lt;/li&gt;
&lt;li&gt;The WriteFile actually perform the write, but the pages that map to that portion of the file have already been marked as loaded.&lt;/li&gt;
&lt;li&gt;At that point, when we use the memory mapped pointer to access the data, we get the data that was there &lt;em&gt;before&lt;/em&gt; the write.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;As I said, the code above can reproduce this issue (you might have to run it multiple times).&lt;/p&gt;
&lt;p&gt;I am not sure if this is something that is valid issue or just me misusing the code. The docs are pretty clear about using regular i/o &amp;amp; memory mapped i/o. The OS is responsible to keeping them coherent with respect to one another. However, that is certainly not the case here.&lt;/p&gt;
&lt;p&gt;It might be that I am using a single handle for both, and Windows does less checking when that happens? For what it is worth, I have also tried it using &lt;em&gt;different &lt;/em&gt;handles, and I don’t see the problem in the code above, but I have a more complex scenario where I do see the same issue.&lt;/p&gt;
&lt;p&gt;Of course, FILE_FLAG_OVERLAPPED is &lt;em&gt;not&lt;/em&gt; specified, so what I would actually expect here is serialization of the I/O, according to the docs. But mostly I need a sanity check to tell me if I am crazy.&lt;/p&gt;</description><link>https://ayende.com/blog/164577/is-select-broken-memory-mapped-files-with-unbufferred-writes-race-condition?Key=edf0a32b-d498-4be4-83e7-c1d2ee95d177</link><guid>https://ayende.com/blog/164577/is-select-broken-memory-mapped-files-with-unbufferred-writes-race-condition?Key=edf0a32b-d498-4be4-83e7-c1d2ee95d177</guid><pubDate>Sat, 16 Nov 2013 03:03:00 GMT</pubDate></item><item><title>And some people will INSIST on shooting them own foot off</title><description>&lt;p&gt;Because, clearly, that is what is missing. &lt;a href="http://geekswithblogs.net/Nettuce/archive/2013/06/12/ravendb-getall-extension-method.aspx"&gt;RavenDB GetAll extension method&lt;/a&gt; &lt;p&gt;&lt;img src="http://www.vegansoapbox.com/wordpress/wp-content/uploads/2009/02/shoot_self_in_foot.jpg"&gt;</description><link>https://ayende.com/blog/162465/and-some-people-will-insist-on-shooting-them-own-foot-off?Key=19577d99-74c9-49ac-b5a6-4c748f76ac66</link><guid>https://ayende.com/blog/162465/and-some-people-will-insist-on-shooting-them-own-foot-off?Key=19577d99-74c9-49ac-b5a6-4c748f76ac66</guid><pubDate>Fri, 14 Jun 2013 09:00:00 GMT</pubDate></item><item><title>Don’t play peekaboo with support, damn it!</title><description>&lt;p&gt;One of the things that we really pride ourselves with Hibernating Rhinos is the level of support. Just to give you some idea, today &amp;amp; yesterday we had core team members on the phone with people (not customers, yes) who are having problems with RavenDB for quite some time.&lt;/p&gt; &lt;p&gt;Now, I understand that you may not always have the information to give, but what you have, give me! So I can help you.&lt;/p&gt; &lt;p&gt;From a recent exchange in the mailing list:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;var clickCount = session.Query&amp;lt;TrackerRequest&amp;gt;().Where(t =&amp;gt; t.TrackerCreated == doc.Created).Where(t =&amp;gt; t.Type == Type.Click).Count();  &lt;p&gt;This gives:  &lt;p&gt;"Non-static method requires a target"&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;To which I replied:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;What is the full error that you get? Compile time? Runtime?&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The answer I got:  &lt;blockquote&gt; &lt;p&gt;This is a document I'm trying to 'Count':  &lt;p&gt;{  &lt;p&gt;&amp;nbsp; "Created": "2012-11-15T16:12:42.1775747",  &lt;p&gt;&amp;nbsp; "IP": "127.0.0.1",  &lt;p&gt;&amp;nbsp; "TrackerCreated": "2012-11-15T14:12:16.3951000Z",  &lt;p&gt;&amp;nbsp; "Referrer": "&lt;a href="http://example.com/"&gt;http://example.com&lt;/a&gt;",  &lt;p&gt;&amp;nbsp; "Type": "Click"  &lt;p&gt;}  &lt;p&gt;Raven terminal gives:  &lt;p&gt;Request # 172: GET&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 ms - &amp;lt;system&amp;gt;&amp;nbsp;&amp;nbsp; - 200 - /indexes/Raven/DocumentsByEntityName?query=Tag%253ATrackerRequests&amp;amp;start=0&amp;amp;pageSize=30&amp;amp;aggregation=None&amp;amp;noCache=-1129797484  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Query: Tag:TrackerRequests  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time: 2 ms  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Index: Raven/DocumentsByEntityName  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Results: 3 returned out of 3 total.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;By the way, you might note that this ISN’T related in any way to his issue. This query (and document) were gotten from the Studio. I can tell by the URL.  &lt;p&gt;Then there was this: &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Dont-play-peekaboo-with-support-damn-it_FD5E/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Dont-play-peekaboo-with-support-damn-it_FD5E/image_thumb.png" width="748" height="317"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I mean, seriously, I am happy to provide support, even if you aren’t a customer yet, but don’t give me some random bit of information that has absolutely nothing to do to the problem at hand and expect me to guess what the issue is.  &lt;p&gt;Relevant information like the stack trace, what build you are on, what classes are involved, etc are expected.&lt;/p&gt;</description><link>https://ayende.com/blog/159905/dont-play-peekaboo-with-support-damn-it?Key=8404e2a7-a95c-4d70-af92-920b57df2b63</link><guid>https://ayende.com/blog/159905/dont-play-peekaboo-with-support-damn-it?Key=8404e2a7-a95c-4d70-af92-920b57df2b63</guid><pubDate>Tue, 20 Nov 2012 10:00:00 GMT</pubDate></item><item><title>Negative hiring decisions, Part I</title><description>&lt;p&gt;One of the things that I &lt;em&gt;really&lt;/em&gt; hate is to be reminded anew how stupid some people are. Or maybe it is how stupid they think I am.&amp;nbsp; One of the things that we are doing during interviews is to ask candidates to do some fairly simple code tasks. Usually, I give them an hour or two to complete that (using VS and a laptop), and if they don’t complete everything, they can do that at home and send me the results.&lt;/p&gt; &lt;p&gt;This is a piece of code that one such candidate has sent. To be clear, this is something that the candidate has worked on at &lt;em&gt;home&lt;/em&gt; and had as much time for as she wanted:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; GetTaxs(&lt;span class="kwrd"&gt;int&lt;/span&gt; salary)
{
    &lt;span class="kwrd"&gt;double&lt;/span&gt;  net, tax;

    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (salary)
    {
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;lt; 5070:
            tax = salary  * 0.1;
            net=  salary  - tax ;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;

        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;lt; 8660:
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;gt; 5071:
            tax = (salary - 5071)*0.14;
            tax+= 5070 * 0.1;
            net = salary-tax;   
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;lt; 14070:
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;gt; 8661:
            tax=  (salary - 8661)*0.23;
            tax+= (8661 - 5071 )*0.14;
            tax+= 5070 *0.1;
            net=  salary - tax;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;lt;21240:
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;gt;14071:
            tax=  (salary- 14071)*0.3;
            tax+= (14070 - 8661)*0.23;
            tax+= (8661 - 5071 )*0.14;
            tax+= 5070 *0.1;
            net= salary - tax;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;lt;40230:
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;gt;21241:
            tax=  (salary- 21241)*0.33;
            tax+= (21240 - 14071)*0.3;
            tax+= (14070 - 8661)*0.23;
            tax+= (8661 - 5071 )*0.14;
            tax+= 5070 *0.1;
            net= salary - tax;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; &amp;gt; 40230:
            tax= (salary - 40230)*0.45;
            tax+=  (40230- 21241)*0.33;
            tax+= (21240 - 14071)*0.3;
            tax+= (14070 - 8661)*0.23;
            tax+= (8661 - 5071 )*0.14;
            tax+= 5070 *0.1;
            net= salary - tax;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;default&lt;/span&gt;:
            &lt;span class="kwrd"&gt;break&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;/blockquote&gt;
&lt;p&gt;Submitting code that &lt;em&gt;doesn’t actually compiles&lt;/em&gt; is a great way to pretty much &lt;em&gt;ensures&lt;/em&gt; that I won’t hire you.&lt;/p&gt;</description><link>https://ayende.com/blog/102401/negative-hiring-decisions-part-i?Key=b63a56cb-924d-409b-bcc2-fe956d1f36a4</link><guid>https://ayende.com/blog/102401/negative-hiring-decisions-part-i?Key=b63a56cb-924d-409b-bcc2-fe956d1f36a4</guid><pubDate>Thu, 22 Sep 2011 09:00:00 GMT</pubDate></item><item><title>Tales from a code review gone wrong</title><description>&lt;blockquote&gt;Originally posted at 2/23/2011&lt;/blockquote&gt;&lt;p&gt;Yes, I know that the NHibernate documentation says that you should override Equals and GetHashCode, but I get the feeling that this wasn’t what the documentation authors intended:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/Tales-from-a-code-review-gone-wrong_DB95/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/Tales-from-a-code-review-gone-wrong_DB95/image_thumb.png" width="244" height="66" /&gt;&lt;/a&gt;&lt;/p&gt;</description><link>https://ayende.com/blog/4772/tales-from-a-code-review-gone-wrong?Key=6c477238-b6e8-4914-bea2-d2948d7b7b71</link><guid>https://ayende.com/blog/4772/tales-from-a-code-review-gone-wrong?Key=6c477238-b6e8-4914-bea2-d2948d7b7b71</guid><pubDate>Thu, 24 Feb 2011 10:00:00 GMT</pubDate></item><item><title>You saved 5 cents, and your code is not readable, congrats!</title><description>&lt;p&gt;I found myself reading &lt;a href="http://blog.boxedice.com/2009/07/25/choosing-a-non-relational-database-why-we-migrated-from-mysql-to-mongodb/"&gt;this post&lt;/a&gt;, and at some point, I really wanted to cry:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;We had relatively long, descriptive names in MySQL such as timeAdded or valueCached. For a small number of rows, this extra storage only amounts to a few bytes per row, but when you have 10 million rows, each with maybe 100 bytes of field names, then you quickly eat up disk space unnecessarily. 100 * 10,000,000 = ~900MB just for field names!&lt;/p&gt;    &lt;p&gt;We cut down the names to 2-3 characters. This is a little more confusing in the code but the disk storage savings are worth it. And if you use sensible names then it isn’t that bad e.g. timeAdded -&amp;gt; tA. A reduction to about 15 bytes per row at 10,000,000 rows means ~140MB for field names – a massive saving.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Let me do the math for a second, okay?&lt;/p&gt;  &lt;p&gt;A &lt;em&gt;two terabyte hard drive &lt;/em&gt;now costs &lt;a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822136344"&gt;120 USD&lt;/a&gt;. By my math, that makes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;1 TB = 60 USD&lt;/li&gt;    &lt;li&gt;1 GB = 0.058 USD&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In other words, that &lt;em&gt;massive&lt;/em&gt; saving that they are talking about? 5 cents!&lt;/p&gt;  &lt;p&gt;Let me do another math problem, oaky?&lt;/p&gt;  &lt;p&gt;Developer costs about &lt;a href="http://www.payscale.com/research/US/Job=C%2523_Developer/Salary"&gt;75,000 USD per year&lt;/a&gt;.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;(52 weeks – 2 vacation weeks) x 40 work hours = 2,000 work hours per year.&lt;/li&gt;    &lt;li&gt;75,000 / 2,000 = 37.5 $ / hr&lt;/li&gt;    &lt;li&gt;37.5 / 60 minutes = 62 cents per minutes.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In other words, assuming that this change cost a &lt;em&gt;single minute of developer time, &lt;/em&gt;the entire saving is worse than moot.&lt;/p&gt;  &lt;p&gt;And it is going to take a &lt;em&gt;lot&lt;/em&gt; more than one minute.&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; Fixed decimal placement error in the cost per minute. Fixed mute/moot issue. 
&lt;/p&gt;
&lt;p&gt;
To those of you pointing out that real server storage space is much higher. You are correct, of course. I am trying to make a &lt;i&gt;point&lt;/i&gt;. Even assuming that it costs &lt;i&gt;two orders of magnitudes&lt;/i&gt; higher than what I said, that is still only 5$. Are you going to tell me that saving the price of a single cup of coffee is actually meaningful?
&lt;/p&gt;
&lt;p&gt;To those of you pointing out that MongoDB effectively stores the entire DB in memory. The post talked about disk size, not about memory, but even so, that is still not relevant. Mostly because MongoDB only requires indexes to fit in memory, and (presumably) indexes don't really need to store the field name per each indexed entry. If they do, then there is something very wrong with the impl.
&lt;/p&gt;</description><link>https://ayende.com/blog/4669/you-saved-5-cents-and-your-code-is-not-readable-congrats?Key=50f5fd63-7817-4505-82ea-f0036cb955c2</link><guid>https://ayende.com/blog/4669/you-saved-5-cents-and-your-code-is-not-readable-congrats?Key=50f5fd63-7817-4505-82ea-f0036cb955c2</guid><pubDate>Fri, 22 Oct 2010 10:00:00 GMT</pubDate></item><item><title>How to pay 3 times for the same flight ticket</title><description>&lt;p&gt;My current mood is somewhere between mad, pissed off, frustrated and exhausted.&lt;/p&gt;  &lt;p&gt;All I want to do it arrive home, but dark forces has conspired against me. It works like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I got a ticket both ways to London, and I left to London quite happily, taking the train to the airport. At that point things started going horribly wrong. An idiot has suicided on the train trucks, leading to about 2 hours of delays, which, naturally, caused me to miss my flight. We will leave that aside and just point out that I somehow managed to get to London without being late to my course the next morning. &lt;/li&gt;    &lt;li&gt;That is when I heard that since I was a no show for the outgoing flight, the airline cancelled my flight back.  I had to order a new one, but because I was busy actually doing the course, I asked the company to order that for me.&lt;/li&gt;    &lt;li&gt;They did, and I went to the airport quite satisfied, except that on arrival, the stupid machine told me that my booking is invalid, which is the point that I discovered that the ticket was ordered on Ayende Rahien. Unfortunately, legally speaking, that guy doesn’t exists. The airline was quite insistent that they can’t put me on board with the different name. And they made me buy a new ticket.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That was the point (&lt;em&gt;after&lt;/em&gt; I paid for the &lt;em&gt;same bloody seat for &lt;/em&gt;&lt;strong&gt;the third time&lt;/strong&gt;&lt;em&gt;) &lt;/em&gt;that they told me that they oversold the flight, and that they put me on waiting list. &lt;/p&gt;  &lt;p&gt;I tried to explain that they could use the &lt;em&gt;second&lt;/em&gt; ticket that I bought, and just give me the same seat, but they told me that they already sold that to someone else. &lt;/p&gt;  &lt;p&gt;I am currently waiting to hear whatever I’ll get to go home tonight or not. &lt;/p&gt;  &lt;p&gt;Your truly,&lt;/p&gt;  &lt;p&gt;Pissed off,&lt;/p&gt;  &lt;p&gt;Oren Eini (because being Ayende is currently dangerous, given my mood)&lt;/p&gt;</description><link>https://ayende.com/blog/4587/how-to-pay-3-times-for-the-same-flight-ticket?Key=49f250e6-193d-4f73-ad9c-8e01b72106c9</link><guid>https://ayende.com/blog/4587/how-to-pay-3-times-for-the-same-flight-ticket?Key=49f250e6-193d-4f73-ad9c-8e01b72106c9</guid><pubDate>Fri, 13 Aug 2010 19:39:00 GMT</pubDate></item><item><title>WTF?! Google Groups really hates me!</title><description>&lt;p&gt;There are no other owners for the group, I have no idea what is going on…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/WTFGoogleGroupsreallyhatesme_76BD/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/WTFGoogleGroupsreallyhatesme_76BD/image_thumb.png" width="679" height="357" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Looks like Google disabled my account, for reasons known only to it. I had to go through a “send me an SMS to activate it” loop, but now it is working.&lt;/p&gt;</description><link>https://ayende.com/blog/4536/wtf-google-groups-really-hates-me?Key=2a278de4-5ae1-4cec-a68a-786ddbc070b7</link><guid>https://ayende.com/blog/4536/wtf-google-groups-really-hates-me?Key=2a278de4-5ae1-4cec-a68a-786ddbc070b7</guid><pubDate>Fri, 04 Jun 2010 05:26:00 GMT</pubDate></item><item><title>Some code just make me queasy</title><description>&lt;p&gt;And this one hits a lot of the high notes in that regard:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Somecodejustmakemequeasy_144C3/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Somecodejustmakemequeasy_144C3/image_thumb.png" width="452" height="118" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Three properties to say the same thing?!&lt;/em&gt;&lt;/p&gt;</description><link>https://ayende.com/blog/4501/some-code-just-make-me-queasy?Key=95e49f1d-c436-41f0-9de7-4ceed887b36e</link><guid>https://ayende.com/blog/4501/some-code-just-make-me-queasy?Key=95e49f1d-c436-41f0-9de7-4ceed887b36e</guid><pubDate>Fri, 14 May 2010 19:41:00 GMT</pubDate></item><item><title>Help requests that make me want to cry</title><description>&lt;p&gt;This showed up on my mail box, with the following text:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;When i try to insert an item to db, VS gives a stackoverflow exception. is it because of that i am using generic classes?? &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Helprequeststhatmakemewanttocry_311B/image_4.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="247" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Helprequeststhatmakemewanttocry_311B/image_thumb_1.png" width="726" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I am not going to comment further, I am stepping away from the keyboard and going to have a lie down.&lt;/p&gt;</description><link>https://ayende.com/blog/4134/help-requests-that-make-me-want-to-cry?Key=6886c5ba-bf41-40d0-a477-a4655c6fb148</link><guid>https://ayende.com/blog/4134/help-requests-that-make-me-want-to-cry?Key=6886c5ba-bf41-40d0-a477-a4655c6fb148</guid><pubDate>Fri, 21 Aug 2009 00:27:00 GMT</pubDate></item><item><title>NHibernate – Get Thou Out Of My Database</title><description>&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/NHibernateGetThouOutOfMyDatabase_D659/image_2.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin-left: 0px; margin-right: 0px; border-right-width: 0px" height="301" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/NHibernateGetThouOutOfMyDatabase_D659/image_thumb.png" width="166" align="right" border="0" /&gt;&lt;/a&gt; There are evil people in this world, and some of them want access to my database. Unfortunately, they are often part of that nasty integration team and they try to integrate directly into my database. I tried beating them with clubs and lobbing arguments about letting other people mess with my implementation details, but they have been persistent. That is when I reached out to a technological solution for the problem.&lt;/p&gt;  &lt;p&gt;I want to emphasize that this is the &lt;em&gt;nuclear option &lt;/em&gt;and  you want to really consider it before going that route.&lt;/p&gt;  &lt;p&gt;We are going to use NHibernate to do that, naturally. Here is how:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/NHibernateGetThouOutOfMyDatabase_D659/image_4.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="295" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/NHibernateGetThouOutOfMyDatabase_D659/image_thumb_1.png" width="816" border="0" /&gt;&lt;/a&gt; &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which results in the following schema:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;create&lt;/span&gt; &lt;span style="color: #0000ff"&gt;table&lt;/span&gt; [tbl_-1434067361] (
   [col_287061521] &lt;span style="color: #0000ff"&gt;INT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;IDENTITY&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,
   [col_4699698] &lt;span style="color: #0000ff"&gt;INT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;not&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_-1966747349] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_-649855325] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_-649855326] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_775690683] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_-2127361396] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   [col_-1334581412] NVARCHAR(255) &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
   &lt;span style="color: #0000ff"&gt;primary&lt;/span&gt; &lt;span style="color: #0000ff"&gt;key&lt;/span&gt; ([col_287061521])
)&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;To make sure that we follow procedure, we are even using the naming convention of the organization! Lovely, isn’t it? It is obvious that this is my people table, right?&lt;/p&gt;

&lt;p&gt;All arguments against this schema can be answered using: “It is more secured”.&lt;/p&gt;

&lt;p&gt;It might be the nuclear option, but it tend to work :-)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Nitpicker corner: No, I don’t suggest you would do this, that is why the code is an image. This is just an example of how to programmatically modify the configuration and mapping. I only used it once, during a demo to the integration people, to get them to leave my DB alone. If you push something like that for production you should probably be shot.&lt;/p&gt;&lt;/blockquote&gt;</description><link>https://ayende.com/blog/4048/nhibernate-get-thou-out-of-my-database?Key=ea1c8644-0921-490d-98d2-aab012d261c5</link><guid>https://ayende.com/blog/4048/nhibernate-get-thou-out-of-my-database?Key=ea1c8644-0921-490d-98d2-aab012d261c5</guid><pubDate>Sat, 06 Jun 2009 12:13:00 GMT</pubDate></item><item><title>PayPal: It may be your account, but you aren’t going to use it</title><description>&lt;p&gt;In general, I have been very happy with PayPal over the years. Recently, however, I have become quite frustrated with it. I am using it quite often to send and accept money to people I am working with, and for a while now, I have been unable to do so.&lt;/p&gt;  &lt;p&gt;Apparently, my actions has been caught by some automated security systems and they decided to ban any transactions on my account. That is actually acceptable from my point of view. I feel better knowing that there are active attempts to protect me from fraud or theft. &lt;/p&gt;  &lt;p&gt;What I &lt;strong&gt;&lt;em&gt;don’t&lt;/em&gt;&lt;/strong&gt; find acceptable is that when I called PayPal to try to resolve that, the response that I got was: It is an act of God, nothing we mere mortals can do about it.&lt;/p&gt;  &lt;p&gt;I understand all about false positives, and aside from the annoyance factor, they are acceptable if they aren’t happening very often. What I am not able to comprehend is responses such as: No one in PayPal can help you. And that is after I already escalated to a supervisor!&lt;/p&gt;  &lt;p&gt;I recorded my conversation with PayPal, you can download it &lt;a href="http://ayende-backup.s3.amazonaws.com/paypal-support-is-useless.mp3"&gt;here&lt;/a&gt; or just listen:&lt;/p&gt; &lt;object type="application/x-shockwave-flash" data="http://ayende.com/blog/audio/player.swf" id="audioplayer1" height="24" width="290"&gt; &lt;param name="movie" value="http://ayende.com/blog/audio/player.swf" /&gt; &lt;param name="FlashVars" value="playerID=1&amp;amp;soundFile=http://ayende-backup.s3.amazonaws.com/paypal-support-is-useless.mp3" /&gt; &lt;param name="quality" value="high" /&gt; &lt;param name="menu" value="false" /&gt; &lt;param name="wmode" value="transparent" /&gt; &lt;/object&gt;  &lt;p&gt;I find the whole thing utterly infuriating, and totally unacceptable.&lt;/p&gt;</description><link>https://ayende.com/blog/4015/paypal-it-may-be-your-account-but-you-arent-going-to-use-it?Key=445f24cd-efcf-41d0-95dc-934a71def3b0</link><guid>https://ayende.com/blog/4015/paypal-it-may-be-your-account-but-you-arent-going-to-use-it?Key=445f24cd-efcf-41d0-95dc-934a71def3b0</guid><pubDate>Fri, 15 May 2009 15:43:09 GMT</pubDate></item><item><title>Kobe – Architectural Overview</title><description>&lt;p&gt;Sometimes, you have to make a distinction between the system architecture and the system implementation. It is possible to have a great architecture and have the implementers butcher it by not paying attention at some points.&lt;/p&gt;  &lt;p&gt;Sometimes, the problem in the code implementation is so bad that it becomes an architectural problem. Kobe is one such example.&lt;/p&gt;  &lt;p&gt;We can start with the pervasive Primitive obsession that is all over the map. The common use of “string thisIsReallyGuid”, Copy &amp;amp; paste programming, horrible Exception Handling and total lack of respect for the fundamentals of OO.&lt;/p&gt;  &lt;p&gt;All of those tie back together to the lack of architectural oversight over the project. I have the feeling that at no point someone stopped and said: “there has &lt;em&gt;got&lt;/em&gt; to be a better way of doing this.”&lt;/p&gt;  &lt;p&gt;DRY is a true principle in development, it transcend programming languages and paradigms, about the only one that I can think of that does so. If you violate DRY, you are in for a world of trouble, sooner than later.&lt;/p&gt;  &lt;p&gt;SOLID is a set of principles used to build good OO applications. If you are using OO language and paradigms and fail to pay attention to SOLID, it will hurt you at some point. Not as soon as if you have violated DRY, but soon enough.&lt;/p&gt;  &lt;p&gt;8.5% of Kobe is copy &amp;amp; pasted code. And that is with the sensitivity dialed high, if we set the threshold to 3, which is what I commonly do, is goes up to 12.5%. A lot of the duplicated code relates to exception handling and caching. Those are classic cases for using an aspect to handle cross cutting concerns. That would reduce a lot of the duplicated code.&lt;/p&gt;  &lt;p&gt;The other problems that I have with Kobe is its total lack of respect for SOLID principles. You know what, let us throw solid out the window, I am going to focus on a single principle, Single Responsibility Principle. Just about any method that you care to name does more than one thing, in many cases, they do a &lt;em&gt;lot&lt;/em&gt; more than one thing.&lt;/p&gt;  &lt;p&gt;This is absolutely wrong.&lt;/p&gt;  &lt;p&gt;The “repositories” in Kobe has so many responsibilities that they are just shy of having a singularity around them.&lt;/p&gt;  &lt;p&gt;Overall, Kobe feels very amaturish, as if it was written without true understanding of what is expected of quality code, and without really understanding the underlying platform, frameworks or the infrastructure that they are using.&lt;/p&gt;  &lt;p&gt;I don’t like it at all, and it is a horrible sample application. In my considered opinioned, it should be pulled from the site, rewritten, and only then published again.&lt;/p&gt;</description><link>https://ayende.com/blog/3953/kobe-architectural-overview?Key=85df010e-15db-4d68-9914-45d341fc6e40</link><guid>https://ayende.com/blog/3953/kobe-architectural-overview?Key=85df010e-15db-4d68-9914-45d341fc6e40</guid><pubDate>Fri, 17 Apr 2009 07:57:55 GMT</pubDate></item><item><title>Kobe – an example of exception handling done wrong</title><description>&lt;p&gt;In Kobe, pretty much all exception handling is this:&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)
{
    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; rethrow = ExceptionPolicy.HandleException(ex, "&lt;span style="color: #8b0000"&gt;Service Policy&lt;/span&gt;");
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (rethrow &amp;amp;&amp;amp; WebOperationContext.Current == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt;;
    }
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;These lines appear in just about any method in the application.&lt;/p&gt;

&lt;p&gt;They are wrong. In fact, they are wrong on more than one level. Violating DRY is a big offence, but even ignoring that, they are still wrong.&lt;/p&gt;

&lt;p&gt;Exception handling is not something that you should take lightly, and there is a strong tie between the way that you write the code and the way errors are handled. The whole purpose of this exception handling is to avoid throwing an exception by setting some configuration parameter.&lt;/p&gt;

&lt;p&gt;The problem with this is that this purpose is &lt;em&gt;wrong&lt;/em&gt;. This is a case of writing the code without actually trying to understand what the implications are. You cannot do this sort of thing, because the calling code never expects a null, it expect a valid result or an exception.&lt;/p&gt;

&lt;p&gt;This approach bring us back to the bad old days of error codes. Not to mention that even if we actually checked for a null return value, what the hell is the error that actually caused this to happen.  Oh, it was put in the log, so now we need to go and look at the log file and try to match timestamps (if we even can).&lt;/p&gt;

&lt;p&gt;Exception handling should appear in exactly two places:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;When an error is expected (making a web request call, for example) and there is some meaningful behavior to be done in the case of a failure (such as retrying after some delay)&lt;/li&gt;

  &lt;li&gt;On a system boundary, in which case you need to make a decision about how you are going to expose the error to the outside world.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to note that I explicitly used the term system boundary, instead of service boundary, which is more commonly used. Exception handling within a system should &lt;em&gt;not&lt;/em&gt; try to hide errors. Error should propagate all the way to the system boundary, because otherwise we lose a lot of important information.&lt;/p&gt;

&lt;p&gt;System boundary is defined as whatever is visible to the actual user or other systems.&lt;/p&gt;

&lt;p&gt;Oh, and exception handling in the system boundary is a &lt;em&gt;system infrastructure problem&lt;/em&gt;, it is not something that you have to write code for all over the place.&lt;/p&gt;</description><link>https://ayende.com/blog/3952/kobe-an-example-of-exception-handling-done-wrong?Key=15d35d88-214b-47d9-b98c-f266b04745e6</link><guid>https://ayende.com/blog/3952/kobe-an-example-of-exception-handling-done-wrong?Key=15d35d88-214b-47d9-b98c-f266b04745e6</guid><pubDate>Fri, 17 Apr 2009 07:46:35 GMT</pubDate></item><item><title>Kobe – When the documentation is the only delivery that matters</title><description>&lt;p&gt;When comparing the Kobe code base to the Kobe documentation, I am starting to get a sinking feeling. The documentation is &lt;em&gt;really&lt;/em&gt; nice, the code is anything but.&lt;/p&gt;  &lt;p&gt;When you put out guidance, the documentation is nice, but it is the code that people are going to look it, learn and try to emulate. And when you put out something that doesn’t meet basic parameters for good software, that is a huge problem.&lt;/p&gt;  &lt;p&gt;With Oxite, Microsoft had the excuse of it being slipped out without anyone noticing. This time it is official, it &lt;em&gt;has &lt;/em&gt;passed the proper review procedure, and is explicitly marketed as “intended to guide you with the planning, architecting, and implementing of Web 2.0 applications and services.”&lt;/p&gt;  &lt;p&gt;Sorry, that is entirely unacceptable.&lt;/p&gt;  &lt;p&gt;Putting something like that out there as guidance is actively doing &lt;em&gt;harm&lt;/em&gt; to the community as a whole. It means that people who would look at that and try to use what they see there are going to get bitten by bad practices, bad architecture and overly complex and redundant approaches.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://haacked.com/"&gt;Phil Haack&lt;/a&gt; &lt;a href="http://weblogs.asp.net/rashid/archive/2009/04/16/kobe-ms-new-web-2-0-resource-kit-in-asp-net-mvc-and-my-thoughts.aspx#7048352"&gt;said&lt;/a&gt; that: “I was part of a high-level review and I felt most of the app that I saw was reasonably put together.”&lt;/p&gt;  &lt;p&gt;I submit that high level review of such guidance packages is &lt;em&gt;absolutely &lt;/em&gt;not sufficient. You have to get people to do a full review cycle of that, which include the code, the documentation, the reasoning and anything else that is going out there.&lt;/p&gt;</description><link>https://ayende.com/blog/3951/kobe-when-the-documentation-is-the-only-delivery-that-matters?Key=1f77da42-00ea-4d51-95d0-373456ba4ecd</link><guid>https://ayende.com/blog/3951/kobe-when-the-documentation-is-the-only-delivery-that-matters?Key=1f77da42-00ea-4d51-95d0-373456ba4ecd</guid><pubDate>Fri, 17 Apr 2009 07:23:44 GMT</pubDate></item><item><title>Kobe – Data Access done wrong</title><description>&lt;p&gt;From the Kobe documentation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Repository pattern is applied to mediate access to the data store through a Repository provider. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;From &lt;a href="http://martinfowler.com/eaaCatalog/repository.html"&gt;PoEAA&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper (165), that isolates domain objects from details of the database access code. In such systems it can be worthwhile to build another layer of abstraction over the mapping layer where query construction code is concentrated. This becomes more important when there are a large number of domain classes or heavy querying. In these cases particularly, adding this layer helps minimize duplicate query logic.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I think that Repository is a fad, which is why I don’t use it much anymore myself, and looking at the usage semantics of the “repositories” in Kobe, they certainly don’t fit the bill.&lt;/p&gt;  &lt;p&gt;Repositories are here to encapsulate query logic, that is not the case with Kobe. Here is a partial view of some of the repositories that it have:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/KobeDataAccessdonewrong_891D/image_2.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="200" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/KobeDataAccessdonewrong_891D/image_thumb.png" width="609" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In general, looking at the any of the repositories in detail, I really want to cry. I mean, just take a look:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/KobeDataAccessdonewrong_891D/image_4.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="1195" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/KobeDataAccessdonewrong_891D/image_thumb_1.png" width="331" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;More to the point, let us look at GroupRepository.AcceptGroupInvite (I removed all the copy &amp;amp; paste crap to concentrate on the actual code):&lt;/p&gt;  &lt;pre&gt;GroupInvite groupInvite = _context.GroupInviteSet
                                 .Where(gi =&amp;gt; gi.GroupInviteId == groupInviteId)
                                 .FirstOrDefault();

&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (groupInvite == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
    &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataException("&lt;span style="color: #8b0000"&gt;Invalid Invite Id&lt;/span&gt;", &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);

groupInvite.InvitationStatuses = _context.InvitationStatusSet
                                        .Where(s =&amp;gt; s.InvitationStatusName == "&lt;span style="color: #8b0000"&gt;Accepted&lt;/span&gt;")
                                        .FirstOrDefault(); ;

_context.SaveChanges(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;There are so many things wrong with this approach that I don’t even know where to &lt;em&gt;start&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You can &lt;em&gt;see&lt;/em&gt; how the architects or developers resented having to use an ORM. If they couldn’t have stored procedures in the database, then by Jove and his keyboard, they will write stored procedures in code.&lt;/p&gt;

&lt;p&gt;Kobe uses Entity Framework for data access, and they treat it as if it was a dataset. As an OR/M aficionado, I am insolated. This shows complete lack of understanding how Entity Framework work, doing a lot more work than you should, brute force &amp;amp; big hammer approach.&lt;/p&gt;

&lt;p&gt;From an architectural perspective, most of what Kobe is doing is calling down to the repository to perform the data access details. Business logic, such as there is, is spread between the data access, the controllers and the service layer, in such a way that make is very hard to have a good idea about what is actually happening in the application.&lt;/p&gt;

&lt;p&gt;Data access details are quite pervasive throughout the application, and the whole &lt;em&gt;feeling&lt;/em&gt; of the application is of a circa 2001 sample app using stored procedures and hand rolled data access layers.&lt;/p&gt;</description><link>https://ayende.com/blog/3950/kobe-data-access-done-wrong?Key=f8ca863e-f373-4ec9-8bec-6050c4c144dd</link><guid>https://ayende.com/blog/3950/kobe-data-access-done-wrong?Key=f8ca863e-f373-4ec9-8bec-6050c4c144dd</guid><pubDate>Fri, 17 Apr 2009 06:45:08 GMT</pubDate></item></channel></rss>