<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEYBQH04eCp7ImA9WhRbEE4.&quot;"><id>tag:blogger.com,1999:blog-20032820</id><updated>2012-02-01T06:49:11.330+13:00</updated><category term="Performance Engineering" /><category term="Tools" /><category term="Hardware" /><category term="Process" /><category term="C# Guidelines" /><category term="Data Access Layer" /><category term="TDD" /><category term="Technology" /><category term="Presentation Layer" /><category term="Business Logic Layer" /><category term="Review" /><category term="Deployment" /><title>Manni on DotNet</title><subtitle type="html">Comments, how-to's, examples, tools, techniques and other material regarding .NET and related technologies.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://manfredlange.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>143</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/wKvdH" /><feedburner:info uri="blogspot/wkvdh" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DU8FQHw-eSp7ImA9WhRVGUg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-6689608743205824188</id><published>2012-01-19T20:22:00.001+13:00</published><updated>2012-01-19T20:23:31.251+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-19T20:23:31.251+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>ReSharper Not Showing Any Tests?</title><content type="html">&lt;p&gt;Version 6.x of ReSharper appears to have a tendency to forget about some tests in a solution once a while (at least once a day in my case). When using “Run All Tests From Solution” it can happen that it shows only a subset of them. In extreme cases it can happen that no tests are shown in the “Unit Tests Session” window.&lt;/p&gt; &lt;p&gt;I’ve noticed that the behavior becomes better after removing all other extensions. I don’t feel this is very practical. The extensions I use are AnkhSVN and Powertools and I’m using Visual Studio 2010 on a 64 bit Windows 7. All software are the latest released versions and has the most recent patches or service packs applied.&lt;/p&gt; &lt;p&gt;I reinstalled everything but that didn’t change the behavior. When I run all unit tests outside of Visual Studio, e.g. using &lt;a href="http://www.csunit.org" target="_blank"&gt;csUnit&lt;/a&gt;, it is all fine.&lt;/p&gt; &lt;p&gt;One way to resolve this is following these five steps:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Close Visual Studio&lt;/li&gt; &lt;li&gt;Delete the _ReSharper.* folder that is located in the folder containing your solution&lt;/li&gt; &lt;li&gt;Start Visual Studio&lt;/li&gt; &lt;li&gt;Reopen your solution&lt;/li&gt; &lt;li&gt;Select “Run all tests from Solution” from the ReSharper menu&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Since once in a while the web deployment functionality requires a restart of Visual Studio as well, I now have two triggers that may force me to restart Visual Studio.&lt;/p&gt; &lt;p&gt;Yes, it is annoying but at least now I have found this work around. Maybe it helps saving you some grief as well.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-6689608743205824188?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A3NJEyrMiUF1BAMBII6WanfL7Q4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A3NJEyrMiUF1BAMBII6WanfL7Q4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A3NJEyrMiUF1BAMBII6WanfL7Q4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A3NJEyrMiUF1BAMBII6WanfL7Q4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/D_f8ysnnYSI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/6689608743205824188/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2012/01/resharper-not-showing-any-tests.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6689608743205824188?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6689608743205824188?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/D_f8ysnnYSI/resharper-not-showing-any-tests.html" title="ReSharper Not Showing Any Tests?" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2012/01/resharper-not-showing-any-tests.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QBQn09cSp7ImA9WhRWEEg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-8775675133198815317</id><published>2011-12-28T18:38:00.001+13:00</published><updated>2011-12-28T18:49:13.369+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-28T18:49:13.369+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><title>Ninject, Interception and out/ref arguments/parameters</title><content type="html">&lt;p&gt;While implementing an aspect using &lt;a href="http://www.ninject.org" target="_blank"&gt;Ninject&lt;/a&gt; along with its Ninject.Extensions.Interception I found that it wouldn’t work with arguments (parameters) that are ‘out’ or ‘ref’ (‘out’ is just a special case of ‘ref’ really). I found a temporary solution at &lt;a href="http://www.codeproject.com/KB/cs/FastMethodInvoker.aspx?msg=2523854" target="_blank"&gt;CodeProject&lt;/a&gt; and in parallel submitted an issue on Github for the Ninject guys to have a look at. I expected this to take a few weeks or even months to be resolved. But they surprised me positively. Support for out/ref arguments/parameters was implemented within 5 hours. Remo, do you sleep at all?&lt;/p&gt; &lt;p&gt;Remo Gloor, one of the Ninject project contributors, responded with saying that the feature will be &lt;a href="https://github.com/ninject/ninject.extensions.interception/issues/5" target="_blank"&gt;included in Ninject 3.0&lt;/a&gt;. I checked and he had just committed the needed changes. Thank you, Remo, for the fast turn around! To confirm I updated my local sources from Github, compiled them and it all worked as expected. Sweet!&lt;/p&gt; &lt;p&gt;According to Remo, support for out / ref parameters / arguments will only be available when you use DynamicProxy2. If you want to make use of it prior to the 3.0 release of Ninject just pull the latest set of sources and build it yourself. Happy coding!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-8775675133198815317?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5Fq-hnT25Fd-SKlEJB6CVzvacf8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5Fq-hnT25Fd-SKlEJB6CVzvacf8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5Fq-hnT25Fd-SKlEJB6CVzvacf8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5Fq-hnT25Fd-SKlEJB6CVzvacf8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/aKubadv7VC4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/8775675133198815317/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/12/ninject-interception-and-outref.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8775675133198815317?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8775675133198815317?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/aKubadv7VC4/ninject-interception-and-outref.html" title="Ninject, Interception and out/ref arguments/parameters" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/12/ninject-interception-and-outref.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcER3s9eSp7ImA9WhRWEUU.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-6246739309294098745</id><published>2011-12-24T10:20:00.001+13:00</published><updated>2011-12-30T07:40:06.561+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-30T07:40:06.561+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Presentation Layer" /><title>Razor, MVC3, Client-Side Validation and Multiple Submit Buttons</title><content type="html">&lt;p&gt;In a details view for creating a new model object I wanted to replace the Cancel link with a Cancel button. I wanted both to be buttons as I felt that to be more consistent. I didn’t realize that I would be up for a surprise when I placed two submit buttons into a single form since, of course, not matter what button I would click I would always end up in the same controller method. It was even worse. As client-side validation was enabled, clicking the Cancel button would perform client-side validation and not even make it to the server.&lt;/p&gt; &lt;p&gt;I googled and found a couple of ideas for how to handle multiple submit buttons. For example one type of suggestions is based on implementing a class derived from ActionMethodSelectorAttribute, for example &lt;a href="http://stackoverflow.com/questions/6353511/mvc-razor-buttons" target="_blank"&gt;here&lt;/a&gt; or &lt;a href="http://www.dotnetcurry.com/(X(1)S(3n14c545mislet45ps2pyu55))/ShowArticle.aspx?ID=724" target="_blank"&gt;here&lt;/a&gt;. Another type of suggestions is based on implementing a class derived from ActionNameSelectorAttribute, for example &lt;a href="http://blog.maartenballiauw.be/post/2009/11/26/Supporting-multiple-submit-buttons-on-an-ASPNET-MVC-view.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I couldn’t get any of these to work the way I wanted. I found that they would work only when I disabled client-side validation or JavaScript on the client altogether. Only in these cases, and by giving the submit button a name using the ‘name’ attribute, would the button value be included in the request. Therefore this was just a partial solution as I wanted to support both scenarios (JavaScript disabled, JavaScript enabled). I tried the actionmethod attribute on the input element but either I used it incorrectly or the handling of this new HTML 5 element is not yet correctly handled by either the browsers or MVC on the server. I didn’t investigate this in more detail.&lt;/p&gt; &lt;p&gt;Here is the solution that worked for me.&lt;/p&gt; &lt;p&gt;First I implemented a JavaScript function which I placed at the end of the view (.cshtml):&lt;/p&gt;&lt;pre class="brush: js;"&gt;&amp;lt;script type="text/javascript"&amp;gt;
   function OnFormButtonClick(action, validate) {
      if (!validate) {
         document.forms[0].noValidate = true;
         document.forms[0].action = '' + action;
         document.forms[0].submit();
      }
}
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;The first parameter of this short method is the name of the action (controller method) to be invoked on the server side while the second parameter determines whether or not to validate on the client side. Of course the latter would only kick in when JavaScript is enabled on the client side. If you want to use multiple submit buttons in several place you may want to put this function in a shared file such as ‘_Layout.cshtml’ or similar.&lt;/p&gt;
&lt;p&gt;With the JavaScript function in place I then added the two submit buttons to the Razor view (HTML form) as follows:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;p&amp;gt;
   &amp;lt;input type="submit" value="Create" name="button"
    onclick="OnFormButtonClick('Create', true);" /&amp;gt;
   &amp;lt;input type="submit" value="Cancel" name="button"
    onclick="OnFormButtonClick('Cancel', false);" /&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/pre&gt;
&lt;p&gt;This would now work with JavaScript enabled on the client. How about the scenario when JavaScript was disabled? In that case submitting the form would always submit to the same action (‘Create’ in my case) no matter what button was clicked. Some server side code was required to distinguish this. This is the point I added a class which is derived from ActionNameSelectorAttribute:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;/// &amp;lt;summary&amp;gt;
/// Attribute that helps MVC with selecting the proper method when multiple submit buttons
/// exist in a single form.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;remarks&amp;gt;The implementation is partially based on  &amp;lt;/remarks&amp;gt;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultiSubmitButtonAttribute : ActionNameSelectorAttribute {
   public override bool IsValidName(ControllerContext controllerContext, 
                                    string actionName, 
                                    MethodInfo methodInfo) {
      // Implementation derived from:
      // http://blog.maartenballiauw.be/post/2009/11/26/Supporting-multiple-submit-buttons-on-an-ASPNET-MVC-view.aspx
      if (controllerContext.RequestContext.HttpContext.Request["button"] != null) {
         // JavaScript disabled.
         return controllerContext.RequestContext.HttpContext.Request["button"] == methodInfo.Name;
      }

      return actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase) 
         || actionName.Equals("Action", StringComparison.InvariantCultureIgnoreCase);
   }
}&lt;/pre&gt;
&lt;p&gt;The first if()-statement in this implementation yields to true only if JavaScript is disabled on the client. In that case the request contains the information about which submit button was clicked and this can be compared to the name of the controller method (bear with me for a little longer to see how this will work). Having this new attribute available I was now able to add it to the controller methods handling the two cases (‘Create’ and ‘Cancel’):&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[HttpPost]
[MultiSubmitButton]
public ActionResult Create(FormCollection collection) {
   // TODO: insert your 'Create' logic here
   return RedirectToAction("Index");
}

[HttpPost]
[MultiSubmitButton]
public ActionResult Cancel() {
   return RedirectToAction("Index");
}&lt;/pre&gt;
&lt;p&gt;When MVC tries to route the action to a controller method it will now also invoke the IsValidName method in the MultiSubmitButtonAttribute class. The two scenarios now work as follows:&lt;/p&gt;
&lt;p&gt;Case 1 - JavaScript enabled: The little JavaScript function is executed on the client side and an appropriate action will be requested. The action is simply routed to the controller method of the same name. Depending on the second parameter of the call to the JavaScript function (and subject to server side settings in web.config) client-side validation is executed or not.&lt;/p&gt;
&lt;p&gt;Case 2 – JavaScript disabled: The client includes the name of the submit button and the MultiSubmitButtonAttribute helps MVC to select the correct controller method.&lt;/p&gt;
&lt;h2&gt;Extending HtmlHelper to Simplify View Implementation&lt;/h2&gt;
&lt;p&gt;There is a way to simplify the view implementation by extending the HtmlHelper class as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static class HtmlHelperExtensions {
   public static MvcHtmlString SubmitButton&amp;lt;T&amp;gt;(this HtmlHelper&amp;lt;T&amp;gt; helper, string value, string action, bool validate) {
      return new MvcHtmlString(String.Format("&amp;lt;input type=\"submit\" value=\"{0}\" name=\"button\" onclick=\"OnFormButtonClick('{1}', {2});\" /&amp;gt;", value, action, validate ? "true" : "false"));
   }
}&lt;/pre&gt;
&lt;p&gt;With this the submit buttons can be coded like this:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;@* Namespace of the HtmlHelper.SubmitButton() implementation: *@
@using Web.Helpers; 

... other code for Razor based view

&amp;lt;p&amp;gt;
   @Html.SubmitButton("Create", "Create", true)
   @Html.SubmitButton("Cancel", "Cancel", false)
&amp;lt;/p&amp;gt;&lt;/pre&gt;
&lt;p&gt;Note that although it appears as if the first two parameters here are duplicated, they are not. The first parameter is the label that appears on the submit button and you may want to localize it. The second parameter is the name of the action which you typically don’t want to change. Even if everything is in the same language (e.g. English) they can be the same but don’t have to.&lt;/p&gt;
&lt;h2&gt;Automatically Injecting JavaScript&lt;/h2&gt;
&lt;p&gt;So far the solution requires manually adding the OnFormButtonClick() function either to the Razor view or to have it in some shared file. I would like to remove this by making the HtmlHelper.SubmitButton&amp;lt;T&amp;gt;() implementation a little smarter:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static class HtmlHelperExtensions {
   public static MvcHtmlString SubmitButton&amp;lt;T&amp;gt;(this HtmlHelper&amp;lt;T&amp;gt; helper, string value, string action, bool validate) {
      var javaScript = string.Empty;
      const string functionName = "_OnFormButtonClicked";
      if (!helper.ViewData.ContainsKey(functionName)) {
         helper.ViewData.Add(functionName, true);
         const string linefeed = " \n\r";
         // Inspiration for the following JavaScript function from:
         // http://www.javascript-coder.com/html-form/html-form-action.phtml
         javaScript = "&amp;lt;script type=\"text/javascript\"&amp;gt;" + linefeed
                    + "   function " + functionName + "(action, validate) {" + linefeed
                    + "      if (!validate) {" + linefeed
                    + "         document.forms[0].noValidate = true;" + linefeed
                    + "         document.forms[0].action = '' + action;" + linefeed
                    + "         document.forms[0].submit();" + linefeed
                    + "      }" + linefeed
                    + "   }" + linefeed
                    + "&amp;lt;/script&amp;gt;" + linefeed;
      }
      return new MvcHtmlString(String.Format("{0}&amp;lt;input type=\"submit\" value=\"{1}\" name=\"button\" onclick=\"{2}('{3}', {4});\" /&amp;gt;", javaScript, value, functionName, action, validate ? "true" : "false"));
   }
}&lt;/pre&gt;
&lt;p&gt;The basic idea is that if the JavaScript function doesn’t exist yet in the view this code adds it. Then it adds one key to the ViewData. If that key is already present this code assumes the JavaScript function has already been added. With this, the JavaScript function can now be removed from the view and all that is needed is this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;MultiSubmitButtonAttribute applied to appropriate controller methods 
&lt;li&gt;Use of HtmlHelper.SubmitButton() in view definition&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;The JavaScript injection is taken care of automatically. Happy coding!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-6246739309294098745?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MTu7bdH6_66qJV45qka8yj5Kf-Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MTu7bdH6_66qJV45qka8yj5Kf-Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MTu7bdH6_66qJV45qka8yj5Kf-Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MTu7bdH6_66qJV45qka8yj5Kf-Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/zhzdEMiLUh4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/6246739309294098745/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/12/razor-mvc3-client-side-validation-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6246739309294098745?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6246739309294098745?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/zhzdEMiLUh4/razor-mvc3-client-side-validation-and.html" title="Razor, MVC3, Client-Side Validation and Multiple Submit Buttons" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/12/razor-mvc3-client-side-validation-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08GRn05fCp7ImA9WhRRFEo.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-4300115420818664957</id><published>2011-11-28T22:11:00.001+13:00</published><updated>2011-11-28T22:17:07.324+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-28T22:17:07.324+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Data Access Layer" /><title>Automapping with Fluent NHibernate: ShouldMap() implementation</title><content type="html">&lt;p&gt;When you use the automapping feature of &lt;a href="http://fluentnhibernate.org/" target="_blank"&gt;Fluent NHibernate&lt;/a&gt; you will very quickly encounter a class called DefaultAutomappingConfiguration. This is the base class for your own automapping configuration class which you want to implement to control certain aspects of the automapping feature.&lt;/p&gt; &lt;p&gt;During startup of your application you have to provide &lt;a href="http://nhforge.org" target="_blank"&gt;NHibernate&lt;/a&gt; with information about how to map your domain classes to the database schema and back. Fluent NHibernate allows doing this automatically. Well, most of the time. There are cases when you want to be a little more specific with regards to those automatically created mappings.&lt;/p&gt; &lt;p&gt;The code you want to execute during startup looks similar to the following:&lt;/p&gt;&lt;pre class="brush: csharp; highlight: [9];"&gt;private static ISessionFactory CreateSessionFactory() {
  var rawConfig = new Configuration();
  rawConfig.SetNamingStrategy(new PostgresNamingStrategy());
  var sessionFactory = Fluently.Configure(rawConfig)
    .Database(PostgreSQLConfiguration.PostgreSQL82
      .ConnectionString(Common.DatabaseConnectionString))
    .Mappings(m =&amp;gt; m.AutoMappings
      .Add(AutoMap
        .AssemblyOf&amp;lt;Customer&amp;gt;(new DbMappingConfiguration())
      .Conventions.Add(ForeignKey.EndsWith("Id"))));
   return sessionFactory.BuildSessionFactory();
}
&lt;/pre&gt;
&lt;p&gt;The interesting piece in this case is line 9 where you provide the assembly that contains all your domain classes that you want to map. In this case you only need to provide one such class and Fluent NHibernate will also try to automatically map all other types that it can find in that assembly. Sometimes this is exactly what you want. In other cases you may not want to map all of the classes. Enter the DefaultMappingConfiguration class.&lt;/p&gt;
&lt;p&gt;You can implement you own mapping configuration by deriving from DefaultMappingConfiguration. You can override just the aspects that you want to change, everything else is taken care of by the default implementation.&lt;/p&gt;
&lt;p&gt;In this post I want to show one way for controlling which classes are mapped. A simplistic approach would be implementing your custom mapping configuration as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class DbMappingConfiguration 
    : DefaultAutomappingConfiguration {
  public override bool ShouldMap(Type type) {
    return type.Equals(typeof(Customer))
      || type.Equals(typeof(Order))
      || type.Equals(typeof(Address))
      || type.Equals(typeof(Invoice));
  }
}
&lt;/pre&gt;
&lt;p&gt;This works. However as you can imagine this is not very intuitive and you will have to maintain this code as you modify your domain. Each time you add, remove or rename any of your domain classes you will have to update this method (admittedly the renaming is not a problem if you use a refactoring tool).&lt;/p&gt;
&lt;p&gt;So let’s think of a better solution. The one I want to present here is based on a marker attribute. The implementation PersistentDomainClassAttribute is very simple:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[AttributeUsage(AttributeTargets.Class, 
                AllowMultiple = false, 
                Inherited = false)]
public class PersistentDomainClassAttribute 
  : Attribute {
}
&lt;/pre&gt;
&lt;p&gt;The usage is fairly simple, too. Here is an example:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[PersistentDomainClass]
public class Customer {
  public virtual Guid Id { get; private set; }
  public virtual string FirstName { get; set; }
  public virtual string LastName { get; set; }
}
&lt;/pre&gt;
&lt;p&gt;Having this in place on all domain classes the custom mapping configuration can now be simplified as follows using a generic implementation:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class DbMappingConfiguration 
   : DefaultAutomappingConfiguration {
  public override bool ShouldMap(Type type) {
    var attr = type.GetCustomAttributes(
                  typeof(PersistentDomainClassAttribute),
                  true);
    return attr.Length &amp;gt; 0;
  }
}
&lt;/pre&gt;
&lt;p&gt;As a result you now have a solution that lets you choose which domain classes to make persistent. At the same time you no longer have to maintain the ShouldMap() implementation of your custom mapping configuration either.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-4300115420818664957?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QDXfxz6M6nloVsVOIwl-gnXhr6Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QDXfxz6M6nloVsVOIwl-gnXhr6Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QDXfxz6M6nloVsVOIwl-gnXhr6Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QDXfxz6M6nloVsVOIwl-gnXhr6Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/6ahWuy4q9Wg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/4300115420818664957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/11/automapping-with-fluent-nhibernate.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4300115420818664957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4300115420818664957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/6ahWuy4q9Wg/automapping-with-fluent-nhibernate.html" title="Automapping with Fluent NHibernate: ShouldMap() implementation" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/11/automapping-with-fluent-nhibernate.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8BR3w-cCp7ImA9WhRRE0g.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-1353491214807774250</id><published>2011-11-27T13:30:00.001+13:00</published><updated>2011-11-27T13:30:56.258+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-27T13:30:56.258+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><category scheme="http://www.blogger.com/atom/ns#" term="TDD" /><title>Behavior of DirectoryInfo.Delete and Directory.Exists: Directories reappear!?</title><content type="html">&lt;p&gt;Please note that the following may be a corner case or an isolated case. If not then something is not quite right with running NUnit based test suites from within Visual Studio 2010 using ReSharper 6. Unfortunately I don’t have proof either way but I still wanted to share my observation just in case you have encountered a similar issue.&lt;/p&gt; &lt;p&gt;A couple of weeks ago I wrote some test code that cleaned up folders after tests were executed. The code looked as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static void CleanUpFolders(
                    List&amp;lt;DirectoryInfo&amp;gt; directoryInfos) {
   foreach (var directoryInfo in directoryInfos) {
      foreach (var file in directoryInfo.GetFiles("*", 
                            SearchOption.AllDirectories)) {
         file.IsReadOnly = false;
      }
      directoryInfo.Delete(true);
   }

   foreach (var directoryInfo in directoryInfos) {
      Assert.IsFalse(Directory.Exists(directoryInfo.FullName));
   }

   directoryInfos.Clear();
}
&lt;/pre&gt;
&lt;p&gt;For each directoryInfo in the collection the code iterates through all files and sets the read-only attribute to false for each of them. Then the directory is deleted with all its contents.&lt;/p&gt;
&lt;p&gt;Then I executed the test suite from within Visual Studio 2010 using ReSharper 6. It turned out that in some cases the assertion in the above code would fail. Despite the directories having been deleted the call to Directory.Exists would return true! So for some reasons the directory was deleted but then it wasn’t. When I reran the tests sometimes this assertion would fail and sometimes it wouldn’t. There were days where it was fine and there were days when the assertion would fail in 90% of the cases.&lt;/p&gt;
&lt;p&gt;In addition to this the assertions would only fail on two particular directories but not on any other. I couldn’t identify the commonality between the directories on which the assertion would fail and the directories that were successfully deleted.&lt;/p&gt;
&lt;p&gt;Initially I thought that maybe a different process or a different thread would have a handle to the directory. In that case my test would just ask the operation system (Windows 7, 64 bit) to mark the directory as deleted and as soon as the last handle was closed it would be removed. However, the tests would generate names and then create directories with that name. No other thread or process knew about the names. I didn’t have any thread in my system under test that would scan the parent directory thus ‘learning’ about the generated directory names.&lt;/p&gt;
&lt;p&gt;To diagnose this issue I tried various things including restarting of Visual Studio and rebooting the workstation. I also tried some of &lt;a href="http://technet.microsoft.com/en-us/sysinternals" target="_blank"&gt;Sysinternals&lt;/a&gt;’ tools.&lt;/p&gt;
&lt;p&gt;The biggest surprise was an observation that I made when running the tests under the debugger. I set a breakpoint just after the loop that deleted all the directories. At that point Windows Explorer would report those directories as gone. Also when continuing the execution the assertions would not fail. However, once the entire suites was complete, two directories would reappear in Windows Explorer! So despite Directory.Exists stating the Directory to be non-existent it reappeared! This is repeatable.&lt;/p&gt;
&lt;p&gt;To take elements out of the equation I got the latest revision of csUnit’s source code and upgraded it to VS2010 and .NET 4.0 (these &lt;a href="https://sourceforge.net/projects/csunit/" target="_blank"&gt;changes are available&lt;/a&gt; at Sourceforge). Then I executed the same test suite without any modification using csUnit. In this case the directories were properly deleted and did not reappear.&lt;/p&gt;
&lt;p&gt;Where does that leave me? I don’t know. All I can say is this: My test suite creates a number of directories with generated names. When I execute this suite from within VS2010 and using ReSharper 6, two folders reappear despite DirectoryInfo.Delete() being executed successfully and Directory.Exists() confirming that. However when I execute the same test suite from csUnitRunner, the code behaves as expected and the folders remain deleted. Despite searching for a long time I have not been able to find the reason for this difference in behavior.&lt;/p&gt;
&lt;p&gt;The only reasonable conclusion at this stage seem to be that as developers we always need to be suspicious about the tools we use. While they may work in almost all the cases, sometimes they may be the cause for something that doesn’t work.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-1353491214807774250?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cBxdNysBnVr4POdXYVvYvL7mg4k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cBxdNysBnVr4POdXYVvYvL7mg4k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cBxdNysBnVr4POdXYVvYvL7mg4k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cBxdNysBnVr4POdXYVvYvL7mg4k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/1KVWp-jiP90" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/1353491214807774250/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/11/behavior-of-directoryinfodelete-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/1353491214807774250?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/1353491214807774250?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/1KVWp-jiP90/behavior-of-directoryinfodelete-and.html" title="Behavior of DirectoryInfo.Delete and Directory.Exists: Directories reappear!?" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/11/behavior-of-directoryinfodelete-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkAERHg9cSp7ImA9WhRSGUg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-8765821073541177501</id><published>2011-11-22T23:45:00.001+13:00</published><updated>2011-11-22T23:45:05.669+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-22T23:45:05.669+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C# Guidelines" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Access Layer" /><title>DirectoryInfo.Delete() when files are read-only</title><content type="html">&lt;p&gt;DirectoryInfo.Delete() will fail with UnauthorizedAccessException if that directory or any of its subdirectories contains a file that is read-only. &lt;/p&gt; &lt;p&gt;One solution is to remove the read-only attribute from all files. You can do so while recursively deleting directories. This approach is mentioned in some blogs and it looks as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static void RecursivelyDeleteDirectory(
                   DirectoryInfo currentDirectory) {
   try {
      currentDirectory.Attributes = FileAttributes.Normal;
      foreach (var childDirectory in 
                        currentDirectory.GetDirectories()) {
         RecursivelyDeleteDirectory(childDirectory);
      }

      foreach (var file in currentDirectory.GetFiles()) {
         file.IsReadOnly = false;
      }

      currentDirectory.Delete(true);
   }
   catch (Exception ex) {
      Console.WriteLine(ex); // Better option: Use log4net
   }
}&lt;/pre&gt;
&lt;p&gt;While this works some people do not like recursion. So here is an option for how the same can be achieved without recursion:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static void DeleteDirectory(
                   DirectoryInfo currentDirectory) {
   try {
      foreach (var file in currentDirectory.GetFiles(
               "*", SearchOption.AllDirectories)) {
         file.IsReadOnly = false;
      }
      currentDirectory.Delete(true);
   }
   catch (Exception ex) {
      Console.WriteLine(ex); // Better option: Use log4net
   }
}&lt;/pre&gt;
&lt;p&gt;Please note that in both cases exception are reported at the console. The better option would be to use a standard logging framework like &lt;a href="http://logging.apache.org/log4net/" target="_blank"&gt;log4net&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-8765821073541177501?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Wb_QHoelLDxeCEy5U9o9IJDtQ2M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wb_QHoelLDxeCEy5U9o9IJDtQ2M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Wb_QHoelLDxeCEy5U9o9IJDtQ2M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wb_QHoelLDxeCEy5U9o9IJDtQ2M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/4Zw1U8fw5Fs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/8765821073541177501/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/11/directoryinfo.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8765821073541177501?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8765821073541177501?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/4Zw1U8fw5Fs/directoryinfo.html" title="DirectoryInfo.Delete() when files are read-only" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/11/directoryinfo.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcDRHk7fSp7ImA9WhRTF04.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-819764804757596510</id><published>2011-11-08T20:07:00.001+13:00</published><updated>2011-11-08T20:07:55.705+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-08T20:07:55.705+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><category scheme="http://www.blogger.com/atom/ns#" term="TDD" /><title>ReSharper Not Executing Your Tests?</title><content type="html">&lt;p&gt;Today I ran into a small issue as ReSharper was not willing to execute my tests. Generally it does but today it was different. Let me explain.&lt;/p&gt; &lt;p&gt;I have two assemblies, one that contains the unit tests and one that contains the code under test. In ReSharper’s session window the unit tests were properly listed. I was even able to “execute” them. However it would always show that them as not executed with a gray bullet in front of them. This was the behavior for both “Run Test” and “Debug Test”. The Output window was empty and didn’t show anything that would indicate what was wrong.&lt;/p&gt; &lt;p&gt;I also check my unit tests but all attributes were properly in place and both the class and the methods were public and the methods had the correct signature. So what was going on?&lt;/p&gt; &lt;p&gt;To diagnose the issue I launched the unit test tool as a stand-alone application. When I tried to load the assembly with the unit tests it was immediately clear what was wrong when I saw the word BadImageFormatException displayed in a message box.&lt;/p&gt; &lt;p&gt;It turned out that the assembly with the unit tests was set to build for “Any CPU” while the assembly under test was build for “x86”. Since I am using a 64 bit machine the two assemblies were compiled as per those targets. The unit tests as 64 bit while the assembly under test as 32 bit. No wonder it didn’t work.&lt;/p&gt; &lt;p&gt;This is easy to fix, in my case by setting the target for the assembly with the unit tests to “x86” as well. It would, however, be nice if ReSharper had reported the exception in some form as it would have saved time. Well, maybe in the next version? Maybe this post helps you to save some time.&lt;/p&gt; &lt;p&gt;&lt;font size="1"&gt;(Note: I’m using ReSharper version 6.0.2202.688 with Visual Studio 2010 SP1 on a 64 bit Windows 7 Enterprise Edition)&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-819764804757596510?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lRbYKbSVvGzcNcaVd6Nxk1_gIvE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lRbYKbSVvGzcNcaVd6Nxk1_gIvE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lRbYKbSVvGzcNcaVd6Nxk1_gIvE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lRbYKbSVvGzcNcaVd6Nxk1_gIvE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/B744yQi9W0A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/819764804757596510/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/11/resharper-not-executing-your-tests.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/819764804757596510?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/819764804757596510?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/B744yQi9W0A/resharper-not-executing-your-tests.html" title="ReSharper Not Executing Your Tests?" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/11/resharper-not-executing-your-tests.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8ASXc7fCp7ImA9WhRSEUs.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-3315103939602443980</id><published>2011-11-04T21:43:00.001+13:00</published><updated>2011-11-13T20:20:48.904+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-13T20:20:48.904+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Data Access Layer" /><title>Fluent NHibernate and Fluent Migrator</title><content type="html">&lt;p&gt;A &lt;a href="http://stackoverflow.com/questions/941513/do-fluent-nhibernate-and-migratordotnet-play-nicely-together" target="_blank"&gt;question&lt;/a&gt; at &lt;a href="http://www.stackoverflow.com"&gt;stack overflow&lt;/a&gt; whether &lt;a href="http://nhforge.org" target="_blank"&gt;NHibernate&lt;/a&gt; and &lt;a href="http://code.google.com/p/migratordotnet/" target="_blank"&gt;migratordotnet&lt;/a&gt; play nicely together caught my interest. So I started a little experiment to find out myself. Instead of migratordotnet, however, I wanted to use &lt;a href="http://fluentnhibernate.org/" target="_blank"&gt;Fluent Migrator&lt;/a&gt; because one of the teams I’ve been working with recently used it as well.&lt;/p&gt; &lt;p&gt;The first challenge I ran into was figuring out how to invoke and use Fluent Migrator from within an assembly. When you look at the sources of Fluent Migrator you will notice that it has several runners that can be used from the command line and from NAnt and msbuild. None of these was what I was looking for. Instead I wanted an API. I couldn’t find one so decided to implement my own API.&lt;/p&gt; &lt;p&gt;About one interface, two classes and about 150 lines of code later I had it running. During startup, e.g. a static initializer in the assembly the migrations are executed using the following statement:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;new Migrator(new MigratorContext(Console.Out) {
   Database = "postgres",
   Connection = ConnectionString,
   MigrationsAssembly = typeof(Global).Assembly
}).MigrateUp();&lt;/pre&gt;
&lt;p&gt;Migrator is one of the classes I implemented. It serves as the façade to Fluent Migrator. Within my assembly I now can write and implement regular migrations, e.g. like the following:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[Migration(201110181840)]
public class CreateUserTable : Migration {
   public override void Up() {
      Create.Table("Users");
   }

   public override void Down() {
      Delete.Table("Users");
   }
}&lt;/pre&gt;
&lt;p&gt;As a result I can now write additional migrations as needed. This approach helps with development as we no longer need to run a separate tool. Each time the startup sequence was executed, e.g. running developer tests which loads the assembly, the database schema was brought up to date. And since I used the automapping feature of Fluent NHibernate I didn’t have to write mappings either.&lt;/p&gt;
&lt;p&gt;What I noticed, though, is that although both Fluent NHibernate and Fluent Migrator now play together nicely, there appears to be code that looks similar. Take the following example of a domain class.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class InputFile {
   public virtual Guid Id { get; private set; }
   public virtual Job Job { get; set; }
   public virtual string FileName { get; set; }
}&lt;/pre&gt;
&lt;p&gt;To have a table for this I also have the following Migration in the code:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[Migration(201111040531)]
public class CreateInputFilesTable : Migration {
   public override void Up() {
      Create.Table(TableName)
         .WithColumn("Id").AsGuid().PrimaryKey()
         .WithColumn("JobId").AsGuid().Indexed()
         .WithColumn("FileName").AsString();
   }

   public override void Down() {
      Delete.Table(TableName);
   }

   private const string TableName = "InputFile";
}&lt;/pre&gt;
&lt;p&gt;As you can see there are things that should not be required. For example the domain class already specifies that the property Id is of type Guid. This is equivalent to saying that the table should have a column named “Id” of type Guid.&lt;/p&gt;
&lt;p&gt;An additional issue can arise when you add a column/property in one place but forget to add it to a different place. Of course this will be reported next time via an exception. However, it would be nice if I had to change it in a single place only.&lt;/p&gt;
&lt;p&gt;So there appears to be an opportunity to simplify the code. Maybe I could rewrite the migration using reflection? And maybe I could rewrite that migration in a kind of generic way so I could reuse at least parts of it for other migrations.&lt;/p&gt;
&lt;p&gt;Next I’ll be looking into how an improved solution might look like ideally generic or at the very least with much less duplication. Being able to avoid having to change two files when modifying one domain class would be a nice first step.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 13 Nov 2011:&lt;/strong&gt; I have created a fork of Fluent Migrator on Github. The address for the fork is &lt;a href="https://github.com/ManfredLange/fluentmigrator"&gt;https://github.com/ManfredLange/fluentmigrator&lt;/a&gt;. In that fork I have added a new project FluentMigrator.InProc that contains the sources mentioned in this post.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-3315103939602443980?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FAZbwfNmG5u14dOSB_Oo_PhtyCE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FAZbwfNmG5u14dOSB_Oo_PhtyCE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FAZbwfNmG5u14dOSB_Oo_PhtyCE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FAZbwfNmG5u14dOSB_Oo_PhtyCE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/5_nsMN5DOQk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/3315103939602443980/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/11/fluent-nhibernate-and-fluent-migrator.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3315103939602443980?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3315103939602443980?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/5_nsMN5DOQk/fluent-nhibernate-and-fluent-migrator.html" title="Fluent NHibernate and Fluent Migrator" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/11/fluent-nhibernate-and-fluent-migrator.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cGR3c-cSp7ImA9WhdaEks.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-2981412941966435267</id><published>2011-10-22T19:30:00.001+13:00</published><updated>2011-10-22T19:30:26.959+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-22T19:30:26.959+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>FluentConfigurationException: Pitfalls of Auto-Completion</title><content type="html">&lt;p&gt;Working on some code I ran into a FluentConfigurationException when trying create the session factory. With (much) more experience I probably would have been able to resolve it much faster. I’d like to share my findings with you. Maybe it’ll help you saving time.&lt;/p&gt; &lt;p&gt;The usual message I got was: “An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.” I followed the advice and checked the PotentialReasons collection. It had a count of 0. In other words it was empty. &lt;/p&gt; &lt;p&gt;Next I checked the inner exception and it was of the same type FluentConfigurationException and the message was the same. Again the PotentialReasons collections was empty. However, there was an exception inside of the inner exception. This was of the type System.InvalidOperationException. The message was: “Unsupported mapping type 'DataAccessTest.Job'”. Searching the internet didn’t yield much of an answer.&lt;/p&gt; &lt;p&gt;I tried a lot of different things and created even a new project. In the end I found that I was a victim of autocomplete. Here is the offending code:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class JobMap : ClassMap&amp;lt;JobMap&amp;gt; {
   public JobMap() {
      Id(x =&amp;gt; x.Id());
   }
}
&lt;/pre&gt;
&lt;p&gt;As I typed Job to provide the type parameter to the generic base class ClassMap&amp;lt;T&amp;gt; the autocomplete feature turned it into JobMap. Since this was just a test all I wanted to map was just the Id. Had I mapped other members I would have noticed that the line where it maps the id is incorrect as well. Have a look at the class that I wanted to map:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class Job {
   public virtual Guid Id { get; private set; }
}&lt;/pre&gt;
&lt;p&gt;You will notice that the member ‘Id’ is a property and not a method. In the mapping class above the lambda expression ‘x =&amp;gt; x.Id()’ tries to map a method ‘Id()’. The base class ClassMap&amp;lt;T&amp;gt; obviously has a method ‘Id()’ so was happily inserted by auto-completion as well. Had I mapped additional Job properties in the JobMap class I would have noticed that something was wrong. This way however, I learned that although auto-completion has made me much more productive there are times when it pays off to be very careful about what it does.&lt;/p&gt;
&lt;p&gt;To complete this post here is the correct code for the mapping:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class JobMap : ClassMap&amp;lt;Job&amp;gt; {
   public JobMap() {
      Id(x =&amp;gt; x.Id);
   }
}

&lt;/pre&gt;Notice the correct class name (‘Job’) as type parameter for the generic based class ClassMap&amp;lt;T&amp;gt; and also the correct lambda expression now mapping a property rather than a method.
  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-2981412941966435267?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1mLDV08ibugdd-Hs1hXgTL3RNZo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1mLDV08ibugdd-Hs1hXgTL3RNZo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1mLDV08ibugdd-Hs1hXgTL3RNZo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1mLDV08ibugdd-Hs1hXgTL3RNZo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/-lswx0NXOnk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/2981412941966435267/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/10/fluentconfigurationexception-pitfalls.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2981412941966435267?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2981412941966435267?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/-lswx0NXOnk/fluentconfigurationexception-pitfalls.html" title="FluentConfigurationException: Pitfalls of Auto-Completion" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/10/fluentconfigurationexception-pitfalls.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYFQ3s-eyp7ImA9WhdaEk4.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-808284525644878444</id><published>2011-10-17T11:22:00.001+13:00</published><updated>2011-10-22T11:45:12.553+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-22T11:45:12.553+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Strong Name Utility Message: "x.dll does not represent a strongly named assembly"</title><content type="html">We are in the process of migrating our code base from Visual Studio 2008 to Visual Studio 2010. To give you an indication for the size of the effort: Our product consists of multiple solutions most of them being pure C#. One of the solutions, however, contains about 70 projects most of which are C++ with a mix of both managed and unmanaged C++. Some of these projects were originally created in the 90s and upgraded multiple times to Visual Studio 2008. We are talking about over 1 million lines of C++ code.&lt;br /&gt;
To prepare for the actual upgrade we have a code branch separate to trunk. In this separate branch we run test upgrades on a regular basis. For a successful upgrade we need to eliminate all build errors that are reported after the migration. In addition to this we also endeavor to resolve all warnings although we are aware that we may not be able to resolve them completely.&lt;br /&gt;
Today I came across this warning/error message today in Visual Studio 2010 SP1 (Service Pack 1). While building I ran into a bug that was reported for Visual Studio 2010 and that was supposed to be fixed in SP1. Signing a C++/CLI assembly in VS 2008 worked but is &lt;a href="http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/61b58555-3579-40c9-9625-b17a9955e3f5" target="_blank"&gt;broken in VS2010&lt;/a&gt;. A &lt;a href="http://social.msdn.microsoft.com/Forums/en-SG/vcgeneral/thread/ce957ddc-cb6a-495f-bc9e-d601aee73970" target="_blank"&gt;work around&lt;/a&gt; has been provided for both VS2010 and VS2010 SP1.&lt;br /&gt;
When I used this work around it worked like a charm for one project but failed for the next project. In my view this indicated that there had to be at least one other factor that influences the outcome.&lt;br /&gt;
I used a diff tool to compare both project files (*.vcxproj) to see differences in the compiler and linker options but also to eliminate these differences one at a time. In my particular case I found that I was able to resolve the problem by removing the ‘/clr’ from the project settings and instead applying ‘/clr’ to each file source file (*.cpp) that requires individually.&lt;br /&gt;
&lt;strong&gt;Update&lt;/strong&gt;: It some cases switching off incremental linking seems to help.&lt;br /&gt;
(Disclaimer: This solution may not work in all cases.)&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-808284525644878444?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-hL29HAcZaNusxg1y-xfO_Yz13g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-hL29HAcZaNusxg1y-xfO_Yz13g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-hL29HAcZaNusxg1y-xfO_Yz13g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-hL29HAcZaNusxg1y-xfO_Yz13g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/m9a7xmLiSIo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/808284525644878444/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/10/strong-name-utility-message-does-not.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/808284525644878444?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/808284525644878444?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/m9a7xmLiSIo/strong-name-utility-message-does-not.html" title="Strong Name Utility Message: &amp;quot;x.dll does not represent a strongly named assembly&amp;quot;" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/10/strong-name-utility-message-does-not.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UFQn46cSp7ImA9WhdREUw.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-8272295800457391166</id><published>2011-07-31T23:11:00.001+12:00</published><updated>2011-07-31T23:20:13.019+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-31T23:20:13.019+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C# Guidelines" /><title>C# Guideline: Use String.Empty When You Can</title><content type="html">&lt;p&gt;Whenever you are tempted to write “” as a string somewhere in your C# code use String.Empty instead. What is the difference? Technically one is a constant while the other is a read-only static field. There is no difference in behavior in this case. However be aware that both are different in their implementation.&lt;/p&gt; &lt;p&gt;The inline constant “” is introduce at compile time. This means once it has been compile it cannot be changed any more.&lt;/p&gt; &lt;p&gt;With the read-only field it is a little different. During compile time only a reference to the field is added. This value of this field is then read during runtime.&lt;/p&gt; &lt;p&gt;This can be quite a difference. For example if the read-only property is define in a different assembly and then you update that assembly with the read-only property now having a different value, that new value will then be used from then on.&lt;/p&gt; &lt;p&gt;Why do I believe this is a good guideline for C#? When you add your own “constants” you typically want to define and maintain them in one place only. With a static property you can achieve that. The code then looks as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class Foo {
   public static string LastName = "Smith";
}
&lt;/pre&gt;
&lt;p&gt;And here is how you then use it:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public void Bar() {
   var address = "Mr. " + Foo.LastName;
   // ... remainder left out
}
&lt;/pre&gt;
&lt;p&gt;If you ever need to change the LastName value you only need to change it in one place. Although String.Empty is very unlikely to change, for consistency reasons you should use it rather than “”.&lt;/p&gt;
&lt;p&gt;The same guideline applies to all other types of constants as well, e.g. Type.EmptyTypes.&lt;/p&gt;
&lt;p&gt;There is (at least) one exception to the use of String.Empty. If you have a switch statement on a string and one of the cases is String.Empty you will find that it won’t compile. The ‘case’ statement requires a constant (which evaluate at compile time) and doesn’t allow for read-only fields (which evaluate at runtime). So the only option then is to write the following:&lt;pre class="brush: csharp;"&gt;switch(aString) {
   case "": // Can't write ‘case String.Empty:’ here!
      // something important to happen here
      break;
}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-8272295800457391166?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OQ7UYJrIJNSVmE4cu__w3WOtzXI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OQ7UYJrIJNSVmE4cu__w3WOtzXI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OQ7UYJrIJNSVmE4cu__w3WOtzXI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OQ7UYJrIJNSVmE4cu__w3WOtzXI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/Dmtu-S6VQIw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/8272295800457391166/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/07/c-guideline-use-stringempty-when-you.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8272295800457391166?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/8272295800457391166?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/Dmtu-S6VQIw/c-guideline-use-stringempty-when-you.html" title="C# Guideline: Use String.Empty When You Can" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/07/c-guideline-use-stringempty-when-you.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMMRHk9eip7ImA9WhZaEUs.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-4937181248325057046</id><published>2011-06-27T21:21:00.001+12:00</published><updated>2011-06-27T21:21:25.762+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-27T21:21:25.762+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Review" /><category scheme="http://www.blogger.com/atom/ns#" term="Hardware" /><title>Cannot Connect To IIS running On Windows 7</title><content type="html">&lt;p&gt;Today I tried to set up a web server connected to my wireless router. The objective was to be able to test a web site I’m working on. I have a Netgear N300 Wireless Dual Band ADSL2+ Modem Router model DGND3300v2. I am this specific for making it easier for people to find this blog post.&lt;/p&gt; &lt;p&gt;The first challenge was to set up the port forwarding. By default the wireless router blocks all connections that are initiated from the outside. Some people refer to this as incoming traffic allow this is strictly speaking not precise.&lt;/p&gt; &lt;p&gt;What you want to set up is an inbound rule for the HTTP service. There is a good description for how to do this on &lt;a href="http://support.netgear.com/app/answers/detail/a_id/8219/~/how-to-setup-inbound%2Foutbound-firewall-rules-on-netgear-modem-router%2Fgateways"&gt;Netgear’s support site&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;To make sure your web server doesn’t change it’s internal IP address you may want to assign a permanent address instead of using DHCP. Again this is easy to do. Just open the configuration tool on the router and go to the “LAN Setup” which is found under “Advanced” in the left hand menu. Don’t forget to click the “Apply” button!&lt;/p&gt; &lt;p&gt;At this point you should be able to see new entries in the log file of the router. These entries should show something like “Mon, 2011-06-27 20:51:18 - TCP Packet - Source:x1.x2.x3.x4,49402 Destination:y1.y2.y3.y4,80 - [HTTP rule match]” where x is the source IP address and y is the destination IP address. (For obvious reasons I have left them out of this post.)&lt;/p&gt; &lt;p&gt;You may still receive the “HTTP 504 error” which indicates that the web server is taking too long to responds. In my particular scenario it meant that it wasn’t answering at all. After quite some researching I found that on my Windows 7 machine the Windows Firewall had the rule “World Wide Web Services (HTTP Traffic-In)” disabled resulting in all inbound traffic on port 80 to be rejected. Since IIS is listening on port 80 by default there was no wonder it took too long …&lt;/p&gt; &lt;p&gt;After I enabled the rule thus enabling inbound traffic on port 80 all worked like a charm. I wrote this post hoping it may safe other people some time. Good luck!&lt;/p&gt; &lt;p&gt;BTW: I’m very satisfied with the &lt;a href="http://www.netgear.com/home/products/wirelessrouters/high-performance/DGND3300.aspx"&gt;Netgear N300 router&lt;/a&gt;. It works like a charm and I never had an issue with it. Prior to this I had a Linksys router, which needed a reset at least once a month and at times more than that because one of the computers at my place wouldn’t be able to connect unless I had rebooted the router. The Linksys router also didn’t have a reset button or a power button. To make it reboot I had to unplug it from the wall power outlet. The Netgear N300 router has a much better range, does 801.2n as well and support both 2.8 GHz and 5 GHz. If you look for a reliable router then I would strongly recommend to take a look at the Netgear N300. (No, I didn’t get it for free from Netgear and had to buy it like everybody else.)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-4937181248325057046?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Xth0Ty5C-LOhdUlA4oLROgXrF7I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xth0Ty5C-LOhdUlA4oLROgXrF7I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Xth0Ty5C-LOhdUlA4oLROgXrF7I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xth0Ty5C-LOhdUlA4oLROgXrF7I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/QPxU2if2Gb0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/4937181248325057046/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/06/cannot-connect-to-iis-running-on.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4937181248325057046?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4937181248325057046?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/QPxU2if2Gb0/cannot-connect-to-iis-running-on.html" title="Cannot Connect To IIS running On Windows 7" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/06/cannot-connect-to-iis-running-on.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8ESHw6fSp7ImA9WhZbFkk.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-3767997797254251559</id><published>2011-06-21T21:33:00.000+12:00</published><updated>2011-06-21T21:33:29.215+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-21T21:33:29.215+12:00</app:edited><title>BIN Deploying ASP.NET MVC 3 with Razor to a Windows Server without MVC installed</title><content type="html">&lt;p&gt;Scott Hanselman discussed &lt;a href="http://www.hanselman.com/blog/BINDeployingASPNETMVC3WithRazorToAWindowsServerWithoutMVCInstalled.aspx"&gt;in his blog&lt;/a&gt; some time ago the challenge with deploying MVC 3 applications where MVC is not installed on the server. He described several options.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I am not challenging that the different options that he offers come with different advantages and disadvantages. So it is essentially up to you to decide which option you want to use.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In this post I want to summarize the option that I used for a deployment where MVC 3 was not installed on the server. In a first step I created a web site project and inside of the project folder I created a folder that I named “mvc3”. Inside of that folder I copied the following assemblies:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;  &lt;li&gt;Microsoft.Web.Infrastructure.dll &lt;/li&gt;

  &lt;li&gt;System.Web.Helpers.dll &lt;/li&gt;

  &lt;li&gt;System.Web.Mvc.dll &lt;/li&gt;

  &lt;li&gt;System.Web.Razor.dll &lt;/li&gt;

  &lt;li&gt;System.Web.WebPages.Deployment.dll &lt;/li&gt;

  &lt;li&gt;System.Web.WebPages.dll &lt;/li&gt;

  &lt;li&gt;System.Web.WebPages.Razor.dll &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;Next I added all of these as references to the web site project. In all cases I set “Copy Local” to “true” to make it would be picked up upon publication.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Finally I build the site and then used “Publish…” to get the web site onto the server.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;With these changes is just worked like a charm.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;If at some point the server supports MVC 3 out of the box then certainly you will want to remove the MVC 3 related assemblies.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;This solution may not be the right choice for your scenario. Check &lt;a href="http://www.hanselman.com/blog/BINDeployingASPNETMVC3WithRazorToAWindowsServerWithoutMVCInstalled.aspx"&gt;Scott’s post&lt;/a&gt; for other options that may work better for you.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-3767997797254251559?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/550PJTu7E3HSB6RX9s2VLTT5b-I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/550PJTu7E3HSB6RX9s2VLTT5b-I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/550PJTu7E3HSB6RX9s2VLTT5b-I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/550PJTu7E3HSB6RX9s2VLTT5b-I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/XZyuvwxaetw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/3767997797254251559/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/06/bin-deploying-aspnet-mvc-3-with-razor.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3767997797254251559?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3767997797254251559?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/XZyuvwxaetw/bin-deploying-aspnet-mvc-3-with-razor.html" title="BIN Deploying ASP.NET MVC 3 with Razor to a Windows Server without MVC installed" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/06/bin-deploying-aspnet-mvc-3-with-razor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcARX46eSp7ImA9WhdaEkg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-3756820144815718051</id><published>2011-04-23T15:08:00.001+12:00</published><updated>2011-10-22T17:00:44.011+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-22T17:00:44.011+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Access Layer" /><title>Fluent-NHibernate, PostgreSQL and Identifiers</title><content type="html">&lt;p&gt;In &lt;a href="http://www.postgres.org"&gt;PostgreSQL&lt;/a&gt; identifiers for tables, columns, etc. are case sensitive. The problem is, though, that when you access PostgreSQL through the .NET data provider (e.g. &lt;a href="http://npgsql.projects.postgresql.org/"&gt;Npgsql&lt;/a&gt;) and don’t double-quote the identifiers, they will be interpreted as lower case. As a result PostgreSQL may tell you that it doesn’t know table ‘MyTable’ as the query is sent to PostgreSQL as ‘mytable’, which is a different identifier than ‘MyTable’.&lt;/p&gt; &lt;p&gt;When you build your SQL queries yourself this is not a major issue. Just add the double quotes. It becomes more of a challenge when you want to use &lt;a href="http://www.fluent-nhibernate.org"&gt;Fluent-NHibernate&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;I searched the internet but couldn’t find a solution that worked for me. For example one &lt;a href="http://stackoverflow.com/questions/3533847/nhibernate-criteria-table-name-has-double-quotes"&gt;answer&lt;/a&gt; at &lt;a href="http://www.stackoverflow.com"&gt;Stack Overflow&lt;/a&gt; suggested to make all identifiers lower case, e.g. have table, column names, etc lower case. While this may work in some cases it doesn’t work in others. Changing the database schema was not an option in my case.&lt;/p&gt; &lt;p&gt;Others (e.g. &lt;a href="http://stackoverflow.com/questions/3332312/quoting-column-names-with-nhibernate-and-postgresql"&gt;here&lt;/a&gt;) recommend the use of FluentConfiguration.ExposeConfiguration(cfg =&amp;gt; cfg.SetProperty("hbm2ddl.keywords","auto-quote") but according to several sources it doesn’t seem to work properly or at all. This solution didn’t work for me either.&lt;/p&gt; &lt;p&gt;Fabio Maulo describes &lt;a href="http://fabiomaulo.blogspot.com/2009/06/auto-quote-tablecolumn-names.html"&gt;the official programmatic way&lt;/a&gt; for NHibernate to enable quoting tables and columns as follows:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;SchemaMetadataUpdater.QuoteTableAndColumns(configuration);&lt;/pre&gt;
&lt;p&gt;I couldn’t get this to work in combination with Fluent-NHibernate either. NHibernate.Dialect reported a System.NotSupportedException:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_89h7TkmxRuQ/TbJIkkR_4PI/AAAAAAAAAXY/Ej5-4UQGkEA/s1600-h/image%5B4%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_89h7TkmxRuQ/TbJIlsYFJ5I/AAAAAAAAAXc/OoIDNTNAjCo/image_thumb%5B2%5D.png?imgmax=800" width="488" height="86"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A first workable option is providing the identifiers via the domain mappings. Let’s look at an example for this approach:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class User {   
   public virtual int Id { get; private set; }
   public virtual string Name { get; set; }   
   public virtual string Password { get; set; }
}
&lt;/pre&gt;
&lt;p&gt;&lt;font face="Verdana"&gt;A simple mapping for this class including specifying the names using double-quotes looks like this:&lt;/font&gt;&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class UserMapping : ClassMap&amp;lt;User&amp;gt; {
   public UserMapping() {
      Table("\"User\"");
      Id(x =&amp;gt; x.Id).Column("\"Id\"");
      Map(x =&amp;gt; x.Name).Column("\"Name\"");
      Map(x =&amp;gt; x.Password).Column("\"Password\"");
   }
}
&lt;/pre&gt;
&lt;p&gt;This works but has the draw back that you have to specify the names in every single case. Although a one-off, this could still be quite some work if you have a large database schema with over a thousand tables. I wanted to have something simpler, something that would have the logic in a single place.&lt;/p&gt;
&lt;p&gt;And I didn’t want to modify Fluent-NHibernate or NHibernate sources either. Instead I wanted to use the official interfaces.&lt;/p&gt;
&lt;p&gt;The solution that worked for me was implementing the INamingStrategy interface from the NHibernate.Cfg namespace. Before I show you the implementation, here is how you can use it:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static ISessionFactory CreateSessionFactory() {
   var rawConfig = new Configuration();
   rawConfig.SetNamingStrategy(new PostgresNamingStrategy());
   var fluentConfiguration = Fluently.Configure(rawConfig)
      .Database(PostgreSQLConfiguration.PostgreSQL82
                  .ConnectionString(ConnectionString))
      .Mappings(m =&amp;gt; m.FluentMappings.AddFromAssemblyOf&amp;lt;User&amp;gt;())
      .BuildConfiguration();
   return fluentConfiguration.BuildSessionFactory();
}
&lt;/pre&gt;
&lt;p&gt;This adds only a small amount of additional code to the creation of the session factory. First we create a raw NHibernate.Configuration() object (line 2) and set the naming strategy (line 3). From thereon I can use the fluent interface by passing the raw Configuration object as the parameter to Fluently.Configure() (see line 4). Note that to come into effect the naming strategy must be set before any mappings are added to the configuration.&lt;/p&gt;
&lt;p&gt;As a result of setting the naming strategy you can simplify the mapping to:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class UserMapping : ClassMap&amp;lt;User&amp;gt; {
   public UserMapping() {
      Id(x =&amp;gt; x.Id);
      Map(x =&amp;gt; x.Name);
      Map(x =&amp;gt; x.Password);
   }
}
&lt;/pre&gt;
&lt;p&gt;The need to specify quoted column names is gone. Equally we don’t need to provide the quoted table name anymore.&lt;/p&gt;
&lt;p&gt;And here is the implementation of the INamingStrategy interface:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;internal class PostgresNamingStrategy : INamingStrategy {
   public string ClassToTableName(string className) {
      return DoubleQuote(className);
   }
   public string PropertyToColumnName(string propertyName) {
      return DoubleQuote(propertyName);
   }
   public string TableName(string tableName) {
      return DoubleQuote(tableName);
   }
   public string ColumnName(string columnName) {
      return DoubleQuote(columnName);
   }
   public string PropertyToTableName(string className, 
                                     string propertyName) {
      return DoubleQuote(propertyName);
   }
   public string LogicalColumnName(string columnName, 
                                   string propertyName) {
      return String.IsNullOrWhiteSpace(columnName) ?
          DoubleQuote(propertyName) :
          DoubleQuote(columnName);
   }
   private static string DoubleQuote(string raw) {
      // In some cases the identifier is single-quoted.
      // We simply remove the single quotes:
      raw = raw.Replace("`", "");
      return String.Format("\"{0}\"", raw);
   }
}
&lt;/pre&gt;
&lt;p&gt;Note that in some cases you may have to remove single quotes first before you add double quotes, e.g. when an identifier is a reserved name. See implementation of the private method DoubleQuote().&lt;/p&gt;
&lt;p&gt;27 May 2011: Update this article with actually working code. Thanks for the feedback from various people.&lt;/p&gt;
&lt;p&gt;&lt;font size="1"&gt;Disclaimer: Source code is provided “as-is”. Use at your own risk. In your environment this solution may need to be adapted or may work at all. The configuration I used for my experiments was PostgreSQL 9.0 running on 64 bit Windows 7, Npgsql 2.0.11.0, Fluent-NHibernate 1.2, and Visual Studio 2010.&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-3756820144815718051?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KdVwBES2ZaifzERjBp-tiOL5nbI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KdVwBES2ZaifzERjBp-tiOL5nbI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KdVwBES2ZaifzERjBp-tiOL5nbI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KdVwBES2ZaifzERjBp-tiOL5nbI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/SHAoJHxzYEc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/3756820144815718051/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/04/fluent-nhibernate-postgresql-and.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3756820144815718051?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3756820144815718051?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/SHAoJHxzYEc/fluent-nhibernate-postgresql-and.html" title="Fluent-NHibernate, PostgreSQL and Identifiers" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/_89h7TkmxRuQ/TbJIlsYFJ5I/AAAAAAAAAXc/OoIDNTNAjCo/s72-c/image_thumb%5B2%5D.png?imgmax=800" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/04/fluent-nhibernate-postgresql-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0IFSXkzfSp7ImA9WhdbGE4.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-7734843096048725695</id><published>2011-03-28T22:12:00.001+13:00</published><updated>2011-10-17T19:05:18.785+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-17T19:05:18.785+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Access Layer" /><title>PostgreSQL and (Index) Names</title><content type="html">Creating an index in PostgreSQL can be achieved by executing the following SQL command:&lt;br /&gt;
&lt;pre class="brush: sql;"&gt;CREATE UNIQUE INDEX "&amp;lt;indexName&amp;gt;" 
ON "&amp;lt;tableName&amp;gt;" 
USING btree (&amp;lt;columnNames&amp;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;br /&gt;
There is one caveat, though. If you specify an index name that is longer than 63 characters PostgreSQL will truncate this and not tell you. By issuing the following command you can list all indexes present in the database:&lt;br /&gt;
&lt;pre class="brush: sql;"&gt;SELECT * FROM pg_catalog.pg_indexes;&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;br /&gt;
In general a limit of 63 characters should not be a problem. However, in my case I was working on a tool which generates index names and it hit this limit. Of course, now I’m using a different algorithm to generate the index names and the problem is solved.&lt;br /&gt;
I also suspect that this 63 character limit applies to other names as well. PostgreSQL has defined a type ‘name’ which has a size of 64 (including the terminating character). This type is used in several places and its definition info is available via the statement&lt;br /&gt;
&lt;pre class="brush: sql;"&gt;SELECT * 
FROM pg_catalog.pg_type
WHERE typname='name';&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;br /&gt;
Personally I would prefer if PostgreSQL would reject the CREATE INDEX statement and instead return an error message.&lt;br /&gt;
&lt;span style="font-size: xx-small;"&gt;Note: The above SQL statements may use PostgreSQL specific syntax, tables, views and functions. Other database systems may require a different syntax and may have different limitations on names. For my experiments I used PostgreSQL 9.0.2 (64bit) running on Windows 7.&lt;/span&gt;&lt;br /&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;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-7734843096048725695?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Dp-1xmX4-bAO4nhx684XsOoMR4U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dp-1xmX4-bAO4nhx684XsOoMR4U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Dp-1xmX4-bAO4nhx684XsOoMR4U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dp-1xmX4-bAO4nhx684XsOoMR4U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/BKGHb2T83pE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/7734843096048725695/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/03/postgresql-and-index-names.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/7734843096048725695?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/7734843096048725695?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/BKGHb2T83pE/postgresql-and-index-names.html" title="PostgreSQL and (Index) Names" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/03/postgresql-and-index-names.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8NQXg-eyp7ImA9WhZSEkQ.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-2889073590600224856</id><published>2011-03-28T18:39:00.001+13:00</published><updated>2011-03-28T18:41:30.653+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-28T18:41:30.653+13:00</app:edited><title>All About Agile</title><content type="html">&lt;p&gt;I just added another entry to the “Suggested Links” section. There are quite a few sites about agile approaches in particular for software development. Kelly Waters has put a lot of effort in her site – “&lt;a href="http://www.allaboutagile.com/"&gt;All About Agile&lt;/a&gt;” - over the last view years and I find the material and links to further information very valuable. Have a look and I’m sure you will find nuggets, too.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-2889073590600224856?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/51IFWWtPPegrbf9WmJqC5i5b_d8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/51IFWWtPPegrbf9WmJqC5i5b_d8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/51IFWWtPPegrbf9WmJqC5i5b_d8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/51IFWWtPPegrbf9WmJqC5i5b_d8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/qzz2KVci33w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/2889073590600224856/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/03/all-about-agile.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2889073590600224856?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2889073590600224856?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/qzz2KVci33w/all-about-agile.html" title="All About Agile" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/03/all-about-agile.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcMQH89eyp7ImA9Wx9aEk8.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-2266860464198963857</id><published>2011-03-04T21:08:00.000+13:00</published><updated>2011-03-04T21:08:01.163+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-04T21:08:01.163+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Cannot toggle breakpoint with F9 key</title><content type="html">Embarrassing but I still would like to share this in case it drives you nuts ... well I even re-installed Visual Studio to resolve this. What happened?&lt;br /&gt;
&lt;br /&gt;
All the sudden setting breakpoints using F9 stopped working. I had just finished installing service pack 1 for my OS so I had a prime suspect. Or so I thought. After removing one plug-in at a time, repairing Visual Studio 2010 and eventually reinstalling it, it still wouldn't work.&lt;br /&gt;
&lt;br /&gt;
I don't know what made me check this but for some reason I found that some function keys would still do something. After some experimentation I found that my keyboard has a special key "F Lock" and after I pressed that all was back to normal. Normally keyboards don't have that key. However, I have a Microsoft natural ergonomics keyboard and it has that key. Apparently I must have had pressed the "F Lock" key accidentally. Oh, well! I guess it's Friday night and time to get some sleep ...&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-2266860464198963857?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4_EpBf9K1XSAfe38EAP24plJqew/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4_EpBf9K1XSAfe38EAP24plJqew/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4_EpBf9K1XSAfe38EAP24plJqew/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4_EpBf9K1XSAfe38EAP24plJqew/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/62fFTp7yAqI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/2266860464198963857/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/03/cannot-toggle-breakpoint-with-f9-key.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2266860464198963857?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2266860464198963857?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/62fFTp7yAqI/cannot-toggle-breakpoint-with-f9-key.html" title="Cannot toggle breakpoint with F9 key" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/03/cannot-toggle-breakpoint-with-f9-key.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08MQnk_eip7ImA9Wx9bEkg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-2323331538362863205</id><published>2011-02-21T16:44:00.001+13:00</published><updated>2011-02-21T16:44:43.742+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-21T16:44:43.742+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Process" /><title>All About Agile</title><content type="html">&lt;p&gt;I just added another entry to the “Interesting Links” section. There are quite a few sites about agile approaches in particular for software development. Kelly Waters has put a lot of effort in her site – “&lt;a href="http://www.allaboutagile.com/"&gt;All About Agile&lt;/a&gt;” - over the last view years and I find the material and links to further information very valuable. Have a look and I’m sure you will find nuggets, too.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-2323331538362863205?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A8teZN54jHCZX6RL8zlMFRktlhU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A8teZN54jHCZX6RL8zlMFRktlhU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A8teZN54jHCZX6RL8zlMFRktlhU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A8teZN54jHCZX6RL8zlMFRktlhU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/Eqx0Jm9BppA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/2323331538362863205/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2011/02/all-about-agile.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2323331538362863205?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/2323331538362863205?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/Eqx0Jm9BppA/all-about-agile.html" title="All About Agile" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2011/02/all-about-agile.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0IDR3Y8fip7ImA9Wx5SEk8.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-6025421679559405434</id><published>2010-08-08T11:59:00.001+12:00</published><updated>2010-08-08T11:59:36.876+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-08T11:59:36.876+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><title>Partial Methods in C#</title><content type="html">&lt;p&gt;While experimenting with ASP.NET MVC 2 – I’m working through “Professional ASP.NET MVC 2” - I also took a lock at some of the generated code. I do this out of curiosity as sometimes I find something that I can use later for my own code as well.&lt;/p&gt;  &lt;p&gt;This time I discovered partial methods when I checked out the designer code for the entity framework (EF) model. In the class NerdDinnerEntities you will find the following:&lt;/p&gt;  &lt;pre class="brush: csharp; highlight: [3];"&gt;#region Partial Methods
    
partial void OnContextCreated();
    
#endregion&lt;/pre&gt;

&lt;p&gt;Partial methods work to some degree like delegate registered for an event but with less overhead for very special situations. I could have written up the details about this myself, but I found a blog that describes “&lt;a href="http://geekswithblogs.net/sdorman/archive/2007/12/24/c-3.0---partial-methods.aspx"&gt;C# 3.0 – Partial Methods&lt;/a&gt;” in a wonderful, easy-to-understand way.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-6025421679559405434?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2Cc3wlqFoZu0YOaWlp2xAu1OTI0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2Cc3wlqFoZu0YOaWlp2xAu1OTI0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2Cc3wlqFoZu0YOaWlp2xAu1OTI0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2Cc3wlqFoZu0YOaWlp2xAu1OTI0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/PwjKiaXw3Mg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/6025421679559405434/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/08/partial-methods-in-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6025421679559405434?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6025421679559405434?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/PwjKiaXw3Mg/partial-methods-in-c.html" title="Partial Methods in C#" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/08/partial-methods-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkYGQHs9cSp7ImA9Wx5TFk4.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-6638314912733836180</id><published>2010-08-01T16:48:00.001+12:00</published><updated>2010-08-01T16:48:41.569+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-01T16:48:41.569+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Presentation Layer" /><title>Using HTTP Response Filter in ASP.NET</title><content type="html">&lt;p&gt;In an ASP.NET application if you want to manipulate the HTML code after it has been rendered but before it is being sent back to the client, you can use a custom filter to intercept that stream and modify it according to your needs.&lt;/p&gt;  &lt;p&gt;One scenario is injecting elements that in turn can be used by the browser in conjunction with a CSS to modify the visual appearance. Not in all cases you have access to the source code for the pages.&lt;/p&gt;  &lt;p&gt;To demonstrate how to do that I’ll use a simple PassThroughFilter that simply forwards all method calls to the original filter.&lt;/p&gt;  &lt;p&gt;Let me show you first how you can register the filter. There are many different places, essentially everywhere where the HttpContext.Response object is accessible. Throughout the processing of a request there are multiple events that you can use to plug in your filter. You can find a list of those events in an &lt;a href="http://msdn.microsoft.com/en-us/library/ff649096.aspx"&gt;article that describes using an HTTP Module for implementing an intercepting filter&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;But you don’t have to use an HTTP Module. You can implement your filter and then register it in various places, for example in the pages OnInit(EventArgs) override:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;protected override OnInit(EventArgs e) {
   Response.Filter = new PassThroughFilter(Response.Filter);
   base.OnInit(e);
}&lt;/pre&gt;

&lt;p&gt;Another option is to use the global application object for the registration (:&lt;/p&gt;

&lt;pre class="brush: csharp; highlight: [8];"&gt;public class MvcApplication : HttpApplication {
   protected void Application_Start() {
      AreaRegistration.RegisterAllAreas();
      RegisterRoutes(RouteTable.Routes);
   }

   protected void Application_BeginRequest() {
      Response.Filter = new PassThroughFilter(Response.Filter);
   }

   private static void RegisterRoutes(RouteCollection routes) {
      routes.IgnoreRoute(&amp;quot;{resource}.axd/{*pathInfo}&amp;quot;);

      routes.MapRoute(
          &amp;quot;Default&amp;quot;, // Route name
          &amp;quot;{controller}/{action}/{id}&amp;quot;, // URL with parameters
          new { controller = &amp;quot;Home&amp;quot;, action = &amp;quot;Index&amp;quot;, id = UrlParameter.Optional } // Parameter defaults
      );

   }
}&lt;/pre&gt;

&lt;p&gt;In this example I’m showing this in an MVC 2 based application but the same works for a WebForms based application, too.&lt;/p&gt;

&lt;p&gt;Where you intercept depends on your specific requirements. Once you have the basic interception in place you can manipulate the HTML stream before it is sent back to the client.&lt;/p&gt;

&lt;p&gt;So here is the full source code for the PassThroughFilter class. Happy Coding!&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;using System.IO;

namespace WebPortal {
   internal class PassThroughFilter : Stream {
      public PassThroughFilter(Stream originalFilter) {
         _originalFilter = originalFilter;
      }

      #region Overrides of Stream

      public override void Flush() {
         _originalFilter.Flush();
      }

      public override long Seek(long offset, SeekOrigin origin) {
         return _originalFilter.Seek(offset, origin);
      }

      public override void SetLength(long value) {
         _originalFilter.SetLength(value);
      }

      public override int Read(byte[] buffer, int offset, int count) {
         return _originalFilter.Read(buffer, offset, count);
      }

      public override void Write(byte[] buffer, int offset, int count) {
         _originalFilter.Write(buffer, offset, count);
      }

      public override bool CanRead {
         get { return _originalFilter.CanRead; }
      }

      public override bool CanSeek {
         get { return _originalFilter.CanSeek; }
      }

      public override bool CanWrite {
         get { return _originalFilter.CanWrite; }
      }

      public override long Length {
         get { return _originalFilter.Length; }
      }

      public override long Position {
         get { return _originalFilter.Position; }
         set { _originalFilter.Position = value; }
      }

      #endregion

      private readonly Stream _originalFilter;
   }
}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-6638314912733836180?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UAMp5qcfXyAF-b7t8vcEng9oEmY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UAMp5qcfXyAF-b7t8vcEng9oEmY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UAMp5qcfXyAF-b7t8vcEng9oEmY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UAMp5qcfXyAF-b7t8vcEng9oEmY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/CNgfrKNqO18" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/6638314912733836180/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/using-http-response-filter-in-aspnet.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6638314912733836180?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/6638314912733836180?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/CNgfrKNqO18/using-http-response-filter-in-aspnet.html" title="Using HTTP Response Filter in ASP.NET" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/using-http-response-filter-in-aspnet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkIERHwycCp7ImA9Wx5TFUg.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-4083275470092119414</id><published>2010-07-31T17:11:00.001+12:00</published><updated>2010-07-31T17:35:05.298+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-31T17:35:05.298+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Updating a Lucene Index – The “Green” Version</title><content type="html">&lt;p&gt;There are plenty of examples available on the internet that are good introductions into the basics of a &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; index. They explain how to create an index and then how to use it for a search.&lt;/p&gt;  &lt;p&gt;At some point you’ll find yourself in the situation that you want to update the index. Furthermore you want to update certain elements only.&lt;/p&gt;  &lt;p&gt;One option is to throw away the entire index and then recreate it from the sources. For some scenarios this might be the best choices. For example you may have a lot of changes in your data and a high latency for updating the index is acceptable. In that case it might be the cheapest to do a full re-index each time. The trade-off is at different points, e.g. when less than 10% have changed updating can be more time efficient. In some cases you probably want to experiment with this a little.&lt;/p&gt;  &lt;p&gt;If you go for recreating the entire index then you probably want to build the new index first (in a different directory if file based) and to replace the index in use only once the new index is complete.&lt;/p&gt;  &lt;p&gt;Another option is to update in the index only the documents that have changed (The “green” option as we are re-using the index). This of course would require you to be able to identify the documents that need to be updated. Depending on your application and your design this might be relatively easy to achieve.&lt;/p&gt;  &lt;p&gt;If you opt for updating in the index just the documents that have changed then some blogs are suggesting to remove the existing version of the document first and then insert/add the new version of the document. For example the code from the discussion on the question “&lt;a href="http://stackoverflow.com/questions/476231/how-to-update-a-lucene-net-index"&gt;How to Update a Lucene.NET Index&lt;/a&gt;” at &lt;a href="http://stackoverflow.com"&gt;Stackoverflow&lt;/a&gt;:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;int patientID = 12;
IndexReader indexReader = IndexReader.Open( indexDirectory );
indexReader.DeleteDocuments( new Term( &amp;quot;patient_id&amp;quot;, patientID ) );&lt;/pre&gt;

&lt;p&gt;There is, however, another option. Lucene.NET (I’m using version 2.9.2) can update an existing document. Here is the code:&lt;/p&gt;

&lt;pre class="brush: csharp; highlight: [9];"&gt;readonly Lucene.Net.Util.Version LuceneVersion = Lucene.Net.Util.Version.LUCENE_29;
var IndexLocationPath = &amp;quot;...&amp;quot; // Set to your location
var directoryInfo = new DirectoryInfo(IndexLocationPath);
var directory = FSDirectory.Open(directoryInfo);
var writer = new IndexWriter(directory, 
            new StandardAnalyzer(LuceneVersion),
            false, // Don't create index
            IndexWriter.MaxFieldLength.LIMITED);
writer.UpdateDocument(new Term(&amp;quot;patient_id&amp;quot;, document.Get(&amp;quot;patient_id&amp;quot;)), document);
writer.Optimize(); // Should be done with low load only ...
writer.Close();&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Be aware that the field you are using for identifying the document needs to be unique. Also when you add the document, the field has to be added as follows:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;doc.Add(new Field(&amp;quot;patient_id&amp;quot;, id.ToString(), 
                  Field.Store.YES, 
                  Field.Index.NOT_ANALYZED));&lt;/pre&gt;

&lt;p&gt;The good thing about this option is that you don’t have to find or remove the old version. IndexWriter.UpdateDocument() takes care of that.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-4083275470092119414?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pmrRV7yFqDgKUIw0lmrueAaaQ28/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pmrRV7yFqDgKUIw0lmrueAaaQ28/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pmrRV7yFqDgKUIw0lmrueAaaQ28/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pmrRV7yFqDgKUIw0lmrueAaaQ28/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/QwLkp55O9z0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/4083275470092119414/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/updating-lucene-index-green-version.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4083275470092119414?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/4083275470092119414?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/QwLkp55O9z0/updating-lucene-index-green-version.html" title="Updating a Lucene Index – The “Green” Version" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/updating-lucene-index-green-version.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcEQnk6fyp7ImA9Wx5TFU8.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-5304744462868484326</id><published>2010-07-30T00:09:00.000+12:00</published><updated>2010-07-31T09:56:43.717+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-31T09:56:43.717+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Configuring log4net for ASP.NET</title><content type="html">&lt;p&gt;Yes, there are already a few posts out there, and yet I think there is value in providing just a recipe to make it work in your ASP.NET project without too many further details. So here you go (in C# where code is used):&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: &lt;a href="http://archive.apache.org/dist/incubator/log4net/1.2.10/incubating-log4net-1.2.10.zip"&gt;Download log4net&lt;/a&gt;, version 1.2.10 or later, and unzip the archive&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: In your project add a reference to the assembly log4net.dll.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh3.ggpht.com/_89h7TkmxRuQ/TE7Mg099wII/AAAAAAAAAWM/HqBRxH3N8XE/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_89h7TkmxRuQ/TE7Mhs4_fyI/AAAAAAAAAWQ/0ITObvJTlGA/image_thumb.png?imgmax=800" width="166" height="111" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Create a file log4net.config at the root of your project (same folder as the root web.config). The following content will log everything to the trace window, e.g. “Output” in Visual Studio:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;&amp;lt;configuration&amp;gt;
   &amp;lt;configSections&amp;gt;
      &amp;lt;section name=&amp;quot;log4net&amp;quot; type=&amp;quot;log4net.Config.Log4NetConfigurationSectionHandler, log4net&amp;quot; /&amp;gt;
   &amp;lt;/configSections&amp;gt;

   &amp;lt;log4net&amp;gt;
      &amp;lt;appender name=&amp;quot;TraceAppender&amp;quot; type=&amp;quot;log4net.Appender.TraceAppender&amp;quot; &amp;gt;
         &amp;lt;layout type=&amp;quot;log4net.Layout.PatternLayout&amp;quot;&amp;gt;
            &amp;lt;param name=&amp;quot;ConversionPattern&amp;quot; value=&amp;quot;%d %-5p- %m%n&amp;quot; /&amp;gt;
         &amp;lt;/layout&amp;gt;
      &amp;lt;/appender&amp;gt;
      &amp;lt;root&amp;gt;
         &amp;lt;level value=&amp;quot;ALL&amp;quot; /&amp;gt;
         &amp;lt;appender-ref ref=&amp;quot;TraceAppender&amp;quot; /&amp;gt;
      &amp;lt;/root&amp;gt;
   &amp;lt;/log4net&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: In AssemblyInfo.cs add the following to make the resulting assembly aware of the configuration file:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;// Tell log4net to watch the following file for modifications:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = &amp;quot;log4net.config&amp;quot;, Watch = true)]&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: In all files in which you want to log add the following as a private member variable:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;private static readonly log4net.ILog Log =
   log4net.LogManager.GetLogger(
      MethodBase.GetCurrentMethod().DeclaringType);&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: Log as needed. For example for testing that steps 1 to 5 were successful, add the following in file Global.asax.cs:&lt;/p&gt;

&lt;pre class="brush: csharp; highlight: [3];"&gt;public class Global : HttpApplication {
   protected void Application_Start(object sender, EventArgs e) {
      Log.Info(&amp;quot;Application Server starting...&amp;quot;);
   }
}&lt;/pre&gt;

&lt;p&gt;For more information about &lt;a href="http://logging.apache.org/log4net/release/config-examples.html"&gt;configuring log4net&lt;/a&gt;, e.g. logging to files, see &lt;a href="http://logging.apache.org/log4net/"&gt;log4net’s web site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As always, if you find a problem with this recipe, please let me know. Happy coding!&lt;/p&gt;

&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-5304744462868484326?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pGobMbIRkMRmS9RWAyR7HICs_Wc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pGobMbIRkMRmS9RWAyR7HICs_Wc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pGobMbIRkMRmS9RWAyR7HICs_Wc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pGobMbIRkMRmS9RWAyR7HICs_Wc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/zwTPmJP0OUo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/5304744462868484326/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/configuring-log4net-for-aspnet.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/5304744462868484326?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/5304744462868484326?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/zwTPmJP0OUo/configuring-log4net-for-aspnet.html" title="Configuring log4net for ASP.NET" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_89h7TkmxRuQ/TE7Mhs4_fyI/AAAAAAAAAWQ/0ITObvJTlGA/s72-c/image_thumb.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/configuring-log4net-for-aspnet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8EQX09fSp7ImA9Wx5TE0w.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-3752199882232383350</id><published>2010-07-28T23:50:00.000+12:00</published><updated>2010-07-28T23:50:00.365+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-28T23:50:00.365+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance Engineering" /><title>Wildcard Searches in Lucene.NET</title><content type="html">&lt;p&gt;Yes, you can do wild card searches with &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.Net&lt;/a&gt;. For example you can search for the term “Mc*” in a database with names it will then return names such as “McNamara” or “McLoud”. When you read more details about the &lt;a href="http://lucene.apache.org/java/3_0_2/queryparsersyntax.html"&gt;query parser syntax&lt;/a&gt; (version 3.0.2) you will notice that the wildcard characters * (any number of characters) and ? (one character) are only allowed in the middle or at the end of the search term but not at the beginning.&lt;/p&gt;  &lt;p&gt;But how about using wildcards at the beginning? Well you can but you should be aware of the consequences. You have to explicitly switch this on in your code as it comes with an additional performance hit with large indexes. So be careful and see whether the resulting performance is acceptable for your users.&lt;/p&gt;  &lt;p&gt;And here is the code (C# in this case):&lt;/p&gt;  &lt;pre class="brush: csharp; highlight: [4.5];"&gt;var index = FSDirectory.Open(new DirectoryInfo(IndexLocationPath));
var searcher = new IndexSearcher(index, true);
var queryParser = new QueryParser(LuceneVersion, &amp;quot;content&amp;quot;, new StandardAnalyzer(LuceneVersion));
queryParser.SetAllowLeadingWildcard(true);
var query = queryParser.Parse(&amp;quot;*&amp;quot; + searchterm + &amp;quot;*&amp;quot;); // Using wildcard at the beginning&lt;/pre&gt;
Happy coding!

  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-3752199882232383350?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AUS1kiyXsyXGdjfzAf7ZUmPfliA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AUS1kiyXsyXGdjfzAf7ZUmPfliA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AUS1kiyXsyXGdjfzAf7ZUmPfliA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AUS1kiyXsyXGdjfzAf7ZUmPfliA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/oLD5IZ-wJ00" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/3752199882232383350/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/wildcard-searches-in-lucenenet.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3752199882232383350?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/3752199882232383350?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/oLD5IZ-wJ00/wildcard-searches-in-lucenenet.html" title="Wildcard Searches in Lucene.NET" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/wildcard-searches-in-lucenenet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4HSHg_fCp7ImA9Wx5TEUk.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-9016419793672244543</id><published>2010-07-26T23:38:00.001+12:00</published><updated>2010-07-26T23:48:59.644+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-26T23:48:59.644+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Lucene Index Toolbox</title><content type="html">&lt;p&gt;After you have succesfully created your first index with &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.Net&lt;/a&gt; you might wonder whether the index was actually created as you wanted. Well, such a tool exists, thanks to the binary compatibility between the Java version and the .NET version of &lt;a href="http://lucene.apache.org/"&gt;Lucene&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The tool is called &lt;a href="http://code.google.com/p/luke/"&gt;Lucene Index Toolbox&lt;/a&gt;. It is a Java based tool that allows inspecting file base indexes. To use it:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Download the &lt;a href="http://luke.googlecode.com/files/lukeall-1.0.1.jar"&gt;Lucene Index Toolbox&lt;/a&gt;. (This download version 1.0.1, please check for newer versions) &lt;/li&gt;    &lt;li&gt;Make sure you have a recent Java runtime installed. &lt;/li&gt;    &lt;li&gt;Open a command line for the directory containing the downloaded jar file &lt;/li&gt;    &lt;li&gt;Use “java -jar lukeall-x.y.z.jar” to start the tool. Replace x.y.z with the version you downloaded. I used 1.0.1 so the command line for me is: “java -jar lukeall-1.0.1.jar” &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Once started you can try out queries against your Lucene index. Or you can have a look at the files of your index and their meaning. Here is an example:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_89h7TkmxRuQ/TE1zurp2OsI/AAAAAAAAAWA/-I35zaPUCwo/s1600-h/image%5B5%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_89h7TkmxRuQ/TE1zvnIA3bI/AAAAAAAAAWI/TN9GFGG1k-g/image_thumb%5B3%5D.png?imgmax=800" width="546" height="307" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A very useful tool in particular for the beginner. Happy coding!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-9016419793672244543?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S4801Z1fLs_hIaPSSHVe8ngribM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S4801Z1fLs_hIaPSSHVe8ngribM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S4801Z1fLs_hIaPSSHVe8ngribM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S4801Z1fLs_hIaPSSHVe8ngribM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/KCpoCgpDIO4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/9016419793672244543/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/lucene-index-toolbox.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/9016419793672244543?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/9016419793672244543?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/KCpoCgpDIO4/lucene-index-toolbox.html" title="Lucene Index Toolbox" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_89h7TkmxRuQ/TE1zvnIA3bI/AAAAAAAAAWI/TN9GFGG1k-g/s72-c/image_thumb%5B3%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/lucene-index-toolbox.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUCRX06fip7ImA9Wx5TEUw.&quot;"><id>tag:blogger.com,1999:blog-20032820.post-5991510787740635025</id><published>2010-07-25T10:26:00.001+12:00</published><updated>2010-07-26T16:24:24.316+12:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-26T16:24:24.316+12:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Tools" /><title>Visual Studio 2010 and WCF: Hard-to-read Error Message</title><content type="html">&lt;p&gt;Just ran into the following error/failure when updating a service reference to a WCF based service:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_89h7TkmxRuQ/TEtohcJJXsI/AAAAAAAAAVg/ceoHz06MY_o/s1600-h/image%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_89h7TkmxRuQ/TEtoirFnsPI/AAAAAAAAAVk/aZ3OrtgqWN8/image_thumb%5B2%5D.png?imgmax=800" width="528" height="405" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The challenge I had was that I couldn’t see the remainder of the message. Furthermore nothing was selectable in this message box. Ideally the control used for displaying the message should allow for selecting the text and also allow for a scrollbar. I suspect this is the default error message box of the OS. If that is case I think it could be solved by either the Visual Studio or the Windows team.&lt;/p&gt;  &lt;p&gt;In my case I launched the ASP.NET application hosting the WCF service and typed in the URL in a browser. That way I got access to the same but now complete error information. “The request failed with the error message:” and “The type ‘xyz’, provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.” now made sense.&lt;/p&gt;  &lt;p&gt;And here is the root cause: Since there was an increasing number of services in the ASP.NET app I decided to create a folder in that project and move the UserManagementService into that folder. With some refactoring I also updated the namespaces and it happily compiled. I even remembered to update the entries in the web.config file. What I did overlook was the markup in the .svc files. So here is a simple example:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_89h7TkmxRuQ/TEtojWr6FfI/AAAAAAAAAVo/7cY2hZY1BzM/s1600-h/image%5B14%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_89h7TkmxRuQ/TEtokBcLARI/AAAAAAAAAVs/LkIDmRHvFE8/image_thumb%5B8%5D.png?imgmax=800" width="364" height="80" /&gt;&lt;/a&gt;Note the highlighted part: Initially when I created the service it was sitting in the root and the name of the implementation including the namespace was “Server.UserManagementService”. When moved it into a folder name UserManagement, I forgot to update this markup to “Server.UserManagement.UserManagementService”.&lt;/p&gt;  &lt;p&gt;So keep in mind the following when you rename or move a service implementation:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Rename the service &lt;/li&gt;    &lt;li&gt;Update the web.config file (this is also mentioned in the comments generated when you use the wizard to add the service) &lt;/li&gt;    &lt;li&gt;Update the markup in the associated svc-file. &lt;/li&gt;    &lt;li&gt;Update/configure the service references in all service clients. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The last one can be done in two ways: First you remove the service reference and then re-add it. Alternatively you can choose to reconfigure the reference:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_89h7TkmxRuQ/TEtvoDKBclI/AAAAAAAAAVw/u0JM6Az1wjk/s1600-h/image%5B8%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_89h7TkmxRuQ/TEtvpXzBI7I/AAAAAAAAAV0/Mf5kQ5nASs8/image_thumb%5B3%5D.png?imgmax=800" width="282" height="114" /&gt;&lt;/a&gt; Next, update the address to the service:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_89h7TkmxRuQ/TEtvql_cE8I/AAAAAAAAAV4/4P9QdY_Z1Hw/s1600-h/image%5B12%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_89h7TkmxRuQ/TEtvrk5Bq-I/AAAAAAAAAV8/4bmVQVg2mD4/image_thumb%5B5%5D.png?imgmax=800" width="491" height="139" /&gt;&lt;/a&gt; Happy coding!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2808695142842813";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al";
//2007-02-24: csUnit
google_ad_channel = "6588413627";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20032820-5991510787740635025?l=manfredlange.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Am9UyiLxtNzovqK0pfhkBZ94uUE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Am9UyiLxtNzovqK0pfhkBZ94uUE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Am9UyiLxtNzovqK0pfhkBZ94uUE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Am9UyiLxtNzovqK0pfhkBZ94uUE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/wKvdH/~4/KnsJtQjo0OI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manfredlange.blogspot.com/feeds/5991510787740635025/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://manfredlange.blogspot.com/2010/07/visual-studio-2010-and-wcf-hard-to-read.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/5991510787740635025?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/20032820/posts/default/5991510787740635025?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/wKvdH/~3/KnsJtQjo0OI/visual-studio-2010-and-wcf-hard-to-read.html" title="Visual Studio 2010 and WCF: Hard-to-read Error Message" /><author><name>Manfred</name><uri>http://www.blogger.com/profile/01100831606055102208</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://www.manfred-lange.com/pictures/ManfredLange279x371.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_89h7TkmxRuQ/TEtoirFnsPI/AAAAAAAAAVk/aZ3OrtgqWN8/s72-c/image_thumb%5B2%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://manfredlange.blogspot.com/2010/07/visual-studio-2010-and-wcf-hard-to-read.html</feedburner:origLink></entry></feed>

