<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-30888820</id><updated>2012-01-29T23:41:41.614-06:00</updated><title type='text'>Code Goes Here</title><subtitle type='html'>everything in its right place</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-30888820.post-5671099147347790436</id><published>2010-05-18T15:17:00.002-05:00</published><updated>2010-05-18T15:20:02.608-05:00</updated><title type='text'>DataContext OnDelete partial method doesn't delete</title><content type='html'>When using the OnDelete or OnUpdate partial methods in the DataContext (to say, cascade deletes to a child object) you may find that the object itself doesn't get deleted.&lt;br /&gt;&lt;br /&gt;This was surprising to me.  The reasoning makes sense, though.  These partial methods totally replace the regular delete processing.  They aren't a "pre" or "post" delete; they are "instead of" delete.&lt;br /&gt;&lt;br /&gt;To make the original object actually get deleted, you should call ExecuteDynamicDelete(instance).&lt;br /&gt;&lt;br /&gt;As seen &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/289561/extending-partial-method-on-datacontext-causes-action-not-to-be-passed-to-database"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5671099147347790436?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5671099147347790436/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5671099147347790436' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5671099147347790436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5671099147347790436'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2010/05/datacontext-ondelete-partial-method.html' title='DataContext OnDelete partial method doesn&apos;t delete'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-7416398326787255559</id><published>2010-05-04T20:13:00.003-05:00</published><updated>2010-05-04T20:18:21.784-05:00</updated><title type='text'>Rhino Expectations should be hit but aren't</title><content type='html'>I was writing a unit test for a method implemented as a linq query returning IEnumerable and using RhinoMocks to stub out a dependency.  Despite all my best debugging efforts where it appeared obvious that the expectations I set should have been met, VerifyAll was throwing with Expected #1 Actual #0.&lt;br /&gt;&lt;br /&gt;After lots of head scratching I realized that it's because when calling VerifyAll, nothing had yet enumerated the result of the method call.  Linq's laziness had prevented my code from running and therefore meeting my expectations.&lt;br /&gt;&lt;br /&gt;After further head scratching, it turns out I've already hit the same problem once before and blogged about it &lt;a href="http://codegoeshere.blogspot.com/2009/08/stepping-into-methods-with-yield-return.html"&gt;here&lt;/a&gt;, so I'm just going to leave this up as a reminder to read your own blog.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-7416398326787255559?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/7416398326787255559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=7416398326787255559' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7416398326787255559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7416398326787255559'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2010/05/rhino-expectations-should-be-hit-but.html' title='Rhino Expectations should be hit but aren&apos;t'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-5438283610317658757</id><published>2009-11-29T14:20:00.003-06:00</published><updated>2009-11-29T14:39:20.951-06:00</updated><title type='text'>VSIX with the VS2010 Beta 2 SDK</title><content type='html'>I'm working on an extension for VS2010 that I'll definitely be talking more about in the future, but I wanted to start by discussing the difficulties involved in even getting started.&lt;br /&gt;&lt;br /&gt;I'd heard a lot about how VS2010 was much easier to extend than previous versions, particularly due to the use of MEF for writing extensions.  What I didn't take into account before coming up with my idea is that MEF is only used for extensions to the editor (which my idea doesn't involve).  That's how I found myself writing a regular extension.&lt;br /&gt;&lt;br /&gt;Optimizing the Editor extension experience seems to have influenced the available project templates as well.  The Beta 2 SDK comes with project templates for Editor Viewport Adornment, Editor Margin, Editor Classifier, Editor this and that, WPF and Winforms controls, and then a default VSIX Project.  You'd think, then, that the one most applicable to my extension would be the VSIX Project, but that thought was where the difficulty began.&lt;br /&gt;&lt;br /&gt;I'm going to suggest up front that the best way to write a non-Editor extension is to find a sample that most closely matches what you want to do on the &lt;a href="http://code.msdn.microsoft.com/vsx"&gt;MSDN Code Gallery for VSX&lt;/a&gt; and just modify it instead of starting with the blank project like I did.  The main issues seem to stem from the SDK providing UI to edit many of the involved files, but in a totally incomplete way leaving many of the necessary settings only discoverable via editing the files in the XML editor or something.&lt;br /&gt;&lt;br /&gt;The first thing you'll find when comparing the VSIX Project to any of the samples is that the VSIX Project has a special project type that gets you another tab in project properties.  While this tab does have a few useful options, it doesn't expose the settings necessary for making sure a PkgDef file gets generated and that it contains your assembly dll and pdb and that they all get deployed to the right place for the Experimental Instance of VS to find them for debugging.  The way I got all this to work was to manually edit my csproj file and change the following elements from "false" to "true".&lt;br /&gt;&lt;br /&gt;&lt;span style="font-face: Courier;font-size:small"&gt;&lt;br /&gt;&amp;lt;GeneratePkgDefFile&amp;gt;true&amp;lt;/GeneratePkgDefFile&amp;gt;&lt;br /&gt;&amp;lt;IncludeAssemblyInVSIXContainer&amp;gt;true&amp;lt;/IncludeAssemblyInVSIXContainer&amp;gt;&lt;br /&gt;&amp;lt;IncludeDebugSymbolsInVSIXContainer&amp;gt;true&amp;lt;/IncludeDebugSymbolsInVSIXContainer&amp;gt;&lt;br /&gt;    &amp;lt;IncludeDebugSymbolsInLocalVSIXDeployment&amp;gt;true&amp;lt;/IncludeDebugSymbolsInLocalVSIXDeployment&amp;gt;&lt;br /&gt;&amp;lt;CopyBuildOutputToOutputDirectory&amp;gt;true&amp;lt;/CopyBuildOutputToOutputDirectory&amp;gt;&lt;br /&gt;&amp;lt;CopyOutputSymbolsToOutputDirectory&amp;gt;true&amp;lt;/CopyOutputSymbolsToOutputDirectory&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In order to make sure your package actually gets registered with the Experimental Instance and that the dlls are referenced out of the local folder instead of the GAC you have to add this PropertyGroup section to your csproj as well&lt;br /&gt;&lt;br /&gt;&lt;span style="font-face:Courier;font-size:small"&gt;&lt;br /&gt;&amp;lt;PropertyGroup&amp;gt;&lt;br /&gt;  &amp;lt;RegisterOutputPackage&amp;gt;true&amp;lt;/RegisterOutputPackage&amp;gt;&lt;br /&gt;  &amp;lt;RegisterWithCodebase&amp;gt;true&amp;lt;/RegisterWithCodebase&amp;gt;&lt;br /&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next thing you'll notice is that the samples all have .vsct files in them that define all the Menus, Groups, Buttons, Bitmaps, etc.  These files basically control how your extension is integrated with Visual Studio.  Since your project doesn't have this, you'll have to add it.  Unfortunately there isn't an item template for this, so the closest match is just an XML file.  Of course it can't be that easy.  There's actually a compilation step that happens against this file, too (it isn't just data).  No problem, let's just change the Build Action to the same thing the sample has.  Wait, why isn't it in the dropdown?  Time to open the csproj file manually again and look for your newly added vsct project.  In the ItemGroup, instead of a Content or None element, you want a VSCTCompile element that looks like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-face:Courier;font-size:small"&gt;&lt;br /&gt;&amp;lt;VSCTCompile Include="Filename.vsct"&amp;gt;&lt;br /&gt;  &amp;lt;ResourceName&amp;gt;1000&amp;lt;/ResourceName&amp;gt;&lt;br /&gt;&amp;lt;/VSCTCompile&amp;gt;&lt;br /&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;That magic number in the ResourceName element &lt;em&gt;must&lt;/em&gt; match up with the value you put in the ProvideMenuResourceAttribute you put on your package.&lt;br /&gt;&lt;br /&gt;Now the VSCT is set, the project is configured properly, and everything works, right?  Not yet.  If you compile now, you'll get a weird error in the VS SDK targets file like "No resource file set the resource merger".  I guessed that this meant we needed a resource file so I added one. That didn't quite fix it so I had to go back into the csproj and change how the resource file was listed there.  Underneath the EmbeddedResource element, add an element called "MergeWithCTO" with the text "true" and that problem should go away.&lt;br /&gt;&lt;br /&gt;Ok now everything should run, the breakpoints set in the package will be hit and the real work can begin.  See why I suggested starting with a sample and just changing it?&lt;br /&gt;&lt;br /&gt;I went ahead and created connect items for these: &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=515483"&gt;VSCT&lt;/a&gt;, &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=515487#details"&gt;Incomplete Properties UI&lt;/a&gt;, and &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=515485"&gt;Resource files&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5438283610317658757?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5438283610317658757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5438283610317658757' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5438283610317658757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5438283610317658757'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/11/vsix-with-vs2010-beta-2-sdk.html' title='VSIX with the VS2010 Beta 2 SDK'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-4477406654140761669</id><published>2009-11-20T23:22:00.004-06:00</published><updated>2009-11-20T23:30:42.372-06:00</updated><title type='text'>Back from PDC</title><content type='html'>The PDC was fun (who doesn't like free laptops), but not as energizing as previous years.  Many of the announcements were just refinements of things previously announced.&lt;br /&gt;&lt;br /&gt;The new Silverlight 4 stuff looks promising, as do the new features in Entity Framework 4.0.  I'm also interested in trying to pry the IQueryable serialization stuff out of RIA so I can make use of it in a more typical distributed system situation.  RIA is explicitly designed to try and hide the distribution tier (which I understand for the scenarios they are targeting), but the data services stuff is too cool to leave it limited to that.&lt;br /&gt;&lt;br /&gt;I had several good talks with different Microsoft folks about EF, MVC, and F# among other things.  Now that all the session videos are online almost immediately, these in-person interactions are the main draw of the conference (well, that and the laptop).&lt;br /&gt;&lt;br /&gt;Having the conference end later in the day Thursday was good, since it made me stay until Friday and gave us a chance to head to Santa Monica Thursday night and dip my toes in the ocean.  We arrived right as the sun was setting and immediately forgot about all the stupid traffic on the way there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-4477406654140761669?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/4477406654140761669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=4477406654140761669' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4477406654140761669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4477406654140761669'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/11/back-from-pdc.html' title='Back from PDC'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-2274894073760989715</id><published>2009-08-19T10:36:00.002-05:00</published><updated>2009-08-19T10:40:54.937-05:00</updated><title type='text'>Stepping into methods with yield return</title><content type='html'>I had a failing unit test (Rhino Expected Call wasn't happening) so I ran with the debugger to try and investigate. When I got to the method in question I tried to step into it but the debugger acted like I had pressed Step Over.  The output window had something like this in it: "Step into: Stepping over method without symbols".&lt;br /&gt;&lt;br /&gt;After some investigation I figured out the issue.  The method in question was returning an IEnumerable and was implemented using "yield return". My test had code like:&lt;br /&gt;&lt;br /&gt;var result = callTheMethodInQuestion();&lt;br /&gt;repository.VerifyAll();&lt;br /&gt;&lt;br /&gt;Can you see the issue yet?&lt;br /&gt;&lt;br /&gt;I was never enumerating result, so the method in question was never actually running, which is why my expected call didn't happen.  Slapping a .ToList() onto result triggered the method evaluation and everything worked fine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-2274894073760989715?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/2274894073760989715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=2274894073760989715' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2274894073760989715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2274894073760989715'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/08/stepping-into-methods-with-yield-return.html' title='Stepping into methods with yield return'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-4354146046346504117</id><published>2009-06-30T16:53:00.002-05:00</published><updated>2009-06-30T17:00:14.356-05:00</updated><title type='text'>AddFromTemplate has misleading documentation</title><content type='html'>When building a custom solution template, it's sometimes useful to programmatically execute other templates.  In our case, we have a unit test project template that we'd like to call from the domain template.  To do this, you use a method off of ENVDTE90.Solution3 called AddFromTemplate, which takes among other things, the path to the template, the output directory, and the new project name.&lt;br /&gt;&lt;br /&gt;The documentation for this method says this about the project name parameter:&lt;br /&gt;"The name of the project file in the destination directory. This should include the extension."&lt;br /&gt;&lt;br /&gt;Seems pretty clear about whether or not to include the extension, right?&lt;br /&gt;&lt;br /&gt;The first version of our wizard included the extension. Unfortunately, this resulted in the $safeprojectname$ parameter ending up with the extension in it as well.  Since this parameter is also used to define the default namespace, we ended up with test classes whose full names were something like MyApplication.MyProjectTests.csproj.MyClassTests.  Yuck.&lt;br /&gt;&lt;br /&gt;The solution appears to be to completely disregard the documentation and don't include the extension. So far this appears to be working.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-4354146046346504117?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/4354146046346504117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=4354146046346504117' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4354146046346504117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4354146046346504117'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/06/addfromtemplate-has-misleading.html' title='AddFromTemplate has misleading documentation'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1701928177919577171</id><published>2009-06-03T20:39:00.002-05:00</published><updated>2009-06-03T20:42:03.493-05:00</updated><title type='text'>How to access a Virtual PC from the Host</title><content type='html'>Most of the documentation I've seen for Virtual PC describes how to setup the virtual machine itself to be able to access the network.  I have an application server installed on a virtual, though, that I'd really like to be able to access from the host machine.&lt;br /&gt;&lt;br /&gt;This took some digging to find, but &lt;a href="http://www.andornot.com/about/developerblog/2007/07/connect-to-virtual-machine-from-host.aspx"&gt;this article&lt;/a&gt; was exceptionally helpful. The only extra step I had to take was to disable Windows Firewall on the virtual machine so it would let the network traffic through.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1701928177919577171?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1701928177919577171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1701928177919577171' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1701928177919577171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1701928177919577171'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/06/how-to-access-virtual-pc-from-host.html' title='How to access a Virtual PC from the Host'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1132339404676146483</id><published>2009-04-15T09:23:00.006-05:00</published><updated>2009-04-15T15:36:20.536-05:00</updated><title type='text'>SSRS 2005 in Vista with IIS 7</title><content type='html'>There are many articles online covering getting Sql Server Reporting Services 2005 working on Vista with IIS 7, but none that I found covered the particular problem I was having. Everything installed ok and the configuration manager was giving me all green checks, but accessing /Reports gave me an error about "unable to connect to the remote server" and accessing /ReportServer gave me a 403.1 Forbidden.&lt;br /&gt;&lt;br /&gt;While poking around the IIS Management tool I noticed that in the Http Handlers section, virtually nothing was listed for the ReportServer web application.  No ASP.NET, no nothing. I clicked "Revert to Inherited", causing it to pick up the settings of the parent site (that had ASP.NET enabled), and everything started working fine.  Who knows how the handlers got overridden, but at least it's working now.&lt;br /&gt;&lt;br /&gt;EDIT: Also, to fix some other nastiness, you have to follow the advice of "rmeans" &lt;a href="http://forums.asp.net/t/1180524.aspx"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Without the wildcard mapping you get a fun "For security reasons DTD is prohibited in this XML document" error.&lt;br /&gt;&lt;br /&gt;EDIT2: And to actually call the web services via WCF you have to take the obvious step of switching the generated basicHttpBinding to pass the windows credentials, like this:&lt;br /&gt;&lt;br /&gt;&amp;lt;binding name="ReportingService2005Soap" ... &amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;security mode="&lt;b&gt;TransportCredentialOnly&lt;/b&gt;"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transport clientCredentialType="&lt;b&gt;Windows&lt;/b&gt;" proxyCredentialType="None" realm="" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;message clientCredentialType="UserName" algorithmSuite="Default" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/security&amp;gt;&lt;br /&gt;&amp;lt;/binding&amp;gt;&lt;br /&gt;&lt;br /&gt;but also the totally not obvious step of allowing the client credentials to impersonate, even if you're using a shared data source with a defined id and all that.  You add a behavior to the endpoint for the SSRS web service like this:&lt;br /&gt;&lt;br /&gt;&amp;lt;endpointBehaviors&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;behavior name="allowImpersonate"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;clientCredentials&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;windows allowedImpersonationLevel="Impersonation"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/clientCredentials&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/behavior&amp;gt;&lt;br /&gt;&amp;lt;/endpointBehaviors&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1132339404676146483?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1132339404676146483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1132339404676146483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1132339404676146483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1132339404676146483'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/04/ssrs-2005-in-vista-with-iis-7.html' title='SSRS 2005 in Vista with IIS 7'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-5657280998672922890</id><published>2009-04-11T17:19:00.002-05:00</published><updated>2009-04-11T17:51:44.901-05:00</updated><title type='text'>Writing a Compiler with F# Part 4</title><content type='html'>&lt;p&gt;Now that we've defined the AST for our language and written a simple evaluator, let's make it easier to construct ASTs. Obviously we don't create C# programs by directly constructing the syntax trees; instead, we type in text which is lexed and then parsed into the tree.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;It turns out that creating lexers and parsers is such a common language task that there are many tools available to generate them for us from some basic definitions. One common lexer generator is called Lex and F# ships with a version of it called fslex. Likewise, fsyacc is the F# variant of the Yacc parser generators. I'm not going to talk about the different types of grammars as those are well documented elsewhere, suffice to say that fsyacc is capable of generating parsers that can handle languages you're probably familiar with.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Recall from last time that lexers take a stream of characters and produce tokens. The do this by matching a regular expression against the input to identify each character. If we assume we have some tokens defined for the elements of our language like PRINT, INT, SEMI (for a ; to separate statements in a statement list), PLUS, MINUS, LPAREN, and RPAREN, we can easily define the regular expressions that produce these tokens from the input.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Adding an .fsl file to the project allows us to define the lexer rules. When the project is built, fslex will run against our file and produce a generated F# file that contains our lexer. Here's what the definition looks like:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;{&lt;br /&gt;open System&lt;br /&gt;open Parser&lt;br /&gt;open Lexing&lt;br /&gt;}&lt;br /&gt;let num         = ['0'-'9']+&lt;br /&gt;let integer     = '-'? num&lt;br /&gt;let whitespace  = ' ' | '\t'&lt;br /&gt;let newline     = '\n' | '\r' '\n'&lt;br /&gt;&lt;br /&gt;rule token = parse&lt;br /&gt;  | whitespace  { token lexbuf }&lt;br /&gt;  | newline     { (lexbuf: lexbuf).EndPos &amp;lt;- lexbuf.EndPos.NextLine; token lexbuf }&lt;br /&gt;  | "("         { LPAREN }&lt;br /&gt;  | ")"         { RPAREN }&lt;br /&gt;  | "+"         { PLUS }&lt;br /&gt;  | "-"         { MINUS }&lt;br /&gt;  | ";"         { SEMI }&lt;br /&gt;  | integer     { INT (Int32.Parse(lexeme lexbuf)) }&lt;br /&gt;  | eof         { EOF }&lt;br /&gt;  | "print"     { PRINT }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The initial { } contains F# code that is directly inserted into our generated file. The tokens themselves (anything in all caps) are defined in the parser which we'll see in a minute so we have to "open Parser" to be able to see them. Next we set up some basic patterns including "num" for strings of digits. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Then, we define the token production rules. The left side (immediately following "|") defines the pattern we are matching, while the braces contain the action to execute (and token to return) should the pattern be matched. Note that "whitespace" results in simply calling our "token" function again with the remaining input, effectively ignoring the whitespace. Also, "newline" updates the current line number so should there be a problem the error can correctly report the line it was on. The only other point of interest is that the INT token carries along a piece of integer data (the actual number that was typed).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Armed with our lexer, we can now create an fsy file and build our parser. It looks like this:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;%{&lt;br /&gt;open Ast&lt;br /&gt;%}&lt;br /&gt;&lt;br /&gt;%start start&lt;br /&gt;&lt;br /&gt;%token &amp;lt;int&amp;gt; INT&lt;br /&gt;%token PLUS MINUS LPAREN RPAREN&lt;br /&gt;%token PRINT SEMI EOF&lt;br /&gt;&lt;br /&gt;%left PLUS MINUS&lt;br /&gt;&lt;br /&gt;%type &amp;lt;stmt&amp;gt; start&lt;br /&gt;&lt;br /&gt;%%&lt;br /&gt;&lt;br /&gt;start: StmtList EOF        { Seq(List.rev $1) }&lt;br /&gt;&lt;br /&gt;Expr: &lt;br /&gt;    | INT                 { Int $1 }&lt;br /&gt;    | Expr PLUS Expr      { BinOp (Plus, $1, $3) }&lt;br /&gt;    | Expr MINUS Expr     { BinOp (Minus, $1, $3) }&lt;br /&gt;    | LPAREN Expr RPAREN  { $2 }&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;Stmt: &lt;br /&gt;    | PRINT Expr            { Print $2 }    &lt;br /&gt;&lt;br /&gt;StmtList:&lt;br /&gt;    | Stmt                { [$1] }&lt;br /&gt;    | StmtList SEMI Stmt  { $3 :: $1 }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Like the lexer, the parser starts with a code block that simply opens the Ast module with the Ast types defined in it. "%start" indicates the name given to the generated parsing function, while "%type" later on indicates that the function will return a "stmt". Next we have a list of tokens (note that INT is defined to carry a piece of data of type int) and an indication that PLUS and MINUS are left associative. This also defines precedence so we can do things like correct multiplication and division later. Finally we have a list of patterns to match. Like the lexer, the left side matches the input (although now we're matching tokens rather than raw characters) and the right side (in the braces) indicates which type defined in Ast should be returned. The "$x" escapes refer to the tokens matched. For example, Expr PLUS Expr results in a BinOp where the left hand side is the value of the first token ($1), i.e., the first "Expr" and the right hand side is the value of the third token ($3), or the second "Expr". The PLUS token itself is "$2". The last trick is that we end up building the StmtList backwards, for efficiency sake (prepending an element to a list is O(1) while adding to the end is O(n)), so in the "start:" pattern we have to reverse $1 before returning the Seq.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now we can use our parser with something like this:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;let parseText text =&lt;br /&gt;    let lexbuf = Lexing.from_string text&lt;br /&gt;    Parser.start Lexer.token lexbuf&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Calling "parseText" with a valid program ("print (1 + 1)") will result in an instance of "stmt" that we can pass to the evaluator we build in the last article.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now we have a pretty stable base to work from. Next time we'll add variables and functions and then after that we'll add types other than "int" so we can start to worry about type checking.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5657280998672922890?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5657280998672922890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5657280998672922890' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5657280998672922890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5657280998672922890'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/04/writing-compiler-with-f-part-4.html' title='Writing a Compiler with F# Part 4'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-725781669464669013</id><published>2009-03-26T08:31:00.003-05:00</published><updated>2009-08-26T07:06:07.737-05:00</updated><title type='text'>The C# coalesce operator short circuits</title><content type='html'>Though it isn't mentioned in the help, the C# coalesce operator ( ?? ) does short circuit.  If the left hand side isn't null, then the right hand side isn't evaluated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-725781669464669013?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/725781669464669013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=725781669464669013' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/725781669464669013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/725781669464669013'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/c-coalesce-operator-short-circuits.html' title='The C# coalesce operator short circuits'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1693334620376343708</id><published>2009-03-25T10:14:00.003-05:00</published><updated>2009-03-25T12:42:32.552-05:00</updated><title type='text'>F# Steals Show Smart Tag Keyboard Shortcut</title><content type='html'>Over the last few days I've noticed that pressing Ctrl-. no longer expanded the Smart Tags in the text editor (used to Refactor Rename or implement interfaces).  It turns out FSI steals this combination for Canceling Evaluation.&lt;br /&gt;&lt;br /&gt;To rebind it, find View.ShowSmartTag in the keyboard options and set it back to Ctrl-.&lt;br /&gt;&lt;br /&gt;Edit: It turns out this is mentioned in the release notes that I neglected to read.  Oops.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1693334620376343708?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1693334620376343708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1693334620376343708' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1693334620376343708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1693334620376343708'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/f-steals-show-smart-tag-keyboard.html' title='F# Steals Show Smart Tag Keyboard Shortcut'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-5791105563273938350</id><published>2009-03-23T15:31:00.003-05:00</published><updated>2009-03-23T16:18:34.249-05:00</updated><title type='text'>Writing a Compiler with F# Part 3</title><content type='html'>&lt;p&gt;Now that we can read user input and pipe it into our evaluator, we need to start implementing the main parts of the compiler.  First it's helpful to understand what compilers actually do.  In a rough sense, they take the text files containing the code and output an exe or a dll or something, i.e., they transform human readable text into machine code.  This is a simplified definition, but it will suffice for our purposes.&lt;/p&gt;&lt;p&gt;It may be tempting to go directly from text into code, but for anything beyond the simplest of languages this ends up being very difficult both to write and maintain.  Most compilers divide up the work into several stages that form a pipeline of sorts.  Some common stages are:&lt;br /&gt;&lt;dl&gt;&lt;dt&gt;Lexing&lt;/dt&gt;&lt;dd&gt;The raw sequence of characters is transformed into a sequence of Tokens.  For example, the Lexer would consume 'w' 'h' 'i' 'l' 'e' from the input file and return the WHILE token&lt;/dd&gt;&lt;br /&gt;&lt;dt&gt;Parsing&lt;/dt&gt;&lt;dd&gt;The tokens from the Lexer are consumed to produce an Abstract Syntax Tree.  An AST is a convenient in-memory representation of the program. More on these in a moment. For example, the Parser might consume VAR IDENTIFIER('i') COLON TYPENAME('int') and produce an instance of our VariableDeclaration class with the Name property set to 'i' and the type set to 'int'&lt;br /&gt;&lt;/dd&gt;&lt;dt&gt;Type Checking&lt;/dt&gt;&lt;dd&gt;Once we have the AST, we can make several passes over it to check the semantics of the language, including that programs are well typed.  For example, when looking at an IfStatement we'd want to make sure that the Expression for the if clause was of type bool.&lt;br /&gt;&lt;/dd&gt;&lt;dt&gt;Other backend phases&lt;/dt&gt;&lt;dd&gt;We'll talk more about backend phases like instruction selection, register allocation, and optimizations if we ever get to building the backend. Ultimately these phases involve walking over the AST and finally spitting out machine code (assembly language, IL for .NET, etc.)&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;/p&gt;&lt;p&gt;What you should see here is that the actual textual representation of the language plays a very small part in this whole process. A large portion of the compiler depends solely on the AST.  Only the Lexer and Parser really care whether you end statements with semicolons or have syntactically significant whitespace, for example.  Because of this, it's useful to start thinking about the AST first, and then worry about Lexing and Parsing.&lt;/p&gt;&lt;p&gt;In F#, the most common way to model ASTs is through the use of discriminated unions.  These are roughly the functional programming equivalent of a polymorphic class hierarchy, although much simplified.  Let's look at an AST for a very simple language that lets you print arithmetic expressions (provided you only want to use parentheses and addition/subtraction).&lt;/p&gt;&lt;pre&gt;type binop =&lt;br /&gt;    | Plus&lt;br /&gt;    | Minus&lt;br /&gt;&lt;br /&gt;type expr =&lt;br /&gt;    | Int   of int&lt;br /&gt;    | BinOp of binop * expr * expr&lt;br /&gt;    &lt;br /&gt;type stmt =&lt;br /&gt;    | Print of expr&lt;br /&gt;    | Seq of stmt list&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The keyword 'type' introduces the declaration of a discriminated union.  Each option is followed by a |.  binop, for example, resembles an Enum that can either be Plus or Minus.  The main difference between these unions and enums becomes apparent when you look at 'expr': each of the options can carry data.  We can have an expr Int that contains an integer value, or a BinOp that contains a binop (remember Plus or Minus) and two other expressions.  We would represent "print 5 + 3" in our AST as Print(BinOp(Plus, Int(5), Int(3)))&lt;/p&gt;&lt;p&gt;Discriminated unions really become powerful when combined with pattern matching.  Given the AST above we can easily build a simple evaluator.  Here's all we need:&lt;/p&gt;&lt;pre&gt;let rec evalE (env,fenv) = function&lt;br /&gt;    | Int i -&gt; i&lt;br /&gt;    | BinOp(Plus, l, r) -&gt; (evalE (env,fenv) l) + (evalE (env,fenv) r)&lt;br /&gt;    | BinOp(Minus, l, r) -&gt; (evalE (env,fenv) l) - (evalE (env,fenv) r)&lt;br /&gt;    &lt;br /&gt;and eval (env,fenv) = function   &lt;br /&gt;    | Seq stmts -&gt; List.fold_left eval (env,fenv) stmts&lt;br /&gt;    | Print e -&gt; printfn "%d" (evalE (env,fenv) e); (env,fenv)    &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Ok what's going on here?  We've defined two mutually recursive functions, 'eval' for evaluating statements, and 'evalE' for evaluating expressions.  We can safely ignore (env,fenv) for now; those will be useful when we add variables and functions. The body of 'eval' says: If I'm handed a Seq of statements, fold the eval function over each statement.  Since we don't have variables yet this is could easily just be 'for each statement, evaluate it'.  It also says: If I'm handed a Print of some expression, evaluate the expression and then print it out.  Evaluating expressions works similarly.  If I'm handed a BinOp(Plus) of two expressions, evaluate each one and then add them together.&lt;/p&gt;&lt;p&gt;In these relatively few lines of code, we've built a simple arithmetic evaluator.  If you type this stuff into fsi, you can call the evaluator by doing something like:&lt;/p&gt;&lt;pre&gt;eval (0,0) (Print(BinOp(Plus,Int(5),Int(6))))&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Which will evaluate 5 + 6 and print out 11.  Next time we see how to build a simple Lexer and Parser for the language so we don't have to type the AST out manually any more.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5791105563273938350?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5791105563273938350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5791105563273938350' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5791105563273938350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5791105563273938350'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/writing-compiler-with-f-part-3.html' title='Writing a Compiler with F# Part 3'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-4201477307548946694</id><published>2009-03-20T09:56:00.002-05:00</published><updated>2009-03-20T09:59:25.977-05:00</updated><title type='text'>Using a custom base class for a generated ObjectContext</title><content type='html'>We're adapting our framework to support the Entity Framework in addition to its current support for Linq to SQL and running into issues.  The Linq to SQL approach involved, among other things, a Base Data Context class that we could easily instruct the built in code generator to use.  The LINQ to SQL designer has first class support for specifying that we want the generated data context to inherit from our BaseDataContext instead of the built-in DataContext directly.&lt;br /&gt;&lt;br /&gt;Not only does the Entity Framework designer not have first class support for this, it appears that the Entity Framework tool chain itself has no support for this at all. I hope I'm wrong about this, but thus far I've been completely unable to find a way to specify that I want my generated ObjectContext to inherit from my BaseObjectContext instead of just ObjectContext.&lt;br /&gt;&lt;br /&gt;Not impressed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-4201477307548946694?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/4201477307548946694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=4201477307548946694' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4201477307548946694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4201477307548946694'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/using-custom-base-class-for-generated.html' title='Using a custom base class for a generated ObjectContext'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-5369466039953704945</id><published>2009-03-15T16:32:00.002-05:00</published><updated>2009-03-15T16:44:14.647-05:00</updated><title type='text'>Writing a Compiler with F# Part 2</title><content type='html'>&lt;p&gt;Since the ideas I want to mess with are more related to type systems than, say, instruction selection or optimizing passes, I'm going to completely neglect the backend of the compiler for awhile. Initially I'm not going to compile the language at all. Instead I'll just build a simple interpreter to evaluate the type-checked parse tree.&lt;/p&gt;  &lt;p&gt;The easiest way to play with this is to make a basic REPL (Read Evaluate Print Loop). Basically a prompt that you can type language snippets into and have them run and the results printed. For F#, the REPL is called fsi.exe. Other languages have this feature as well (in Ruby it's irb.exe).&lt;/p&gt;  &lt;p&gt;To get started, I'm going to forget about all the lexing and parsing stuff and get my feet wet with F# by building the framework for a simple REPL.&lt;/p&gt;  &lt;p&gt;First, I'll need to print a prompt and get some input. Here's an F# function to handle that:&lt;/p&gt;  &lt;pre&gt;let getInput (prompt:string) =&lt;br /&gt; (Console.Write(prompt); Console.ReadLine())&lt;/pre&gt;&lt;p&gt;Pretty basic stuff. I had to specify the type for "prompt" since Console.Write is overloaded.&lt;/p&gt;&lt;p&gt;Next, I want a basic loop to get input and evaluate it. Functional programming and F# in particular work naturally with sequences as a first class element. To that end, I'm going to model the user input as a sequence of lines. The F# Seq type has a generate method for this purpose. It takes 3 functions: an initializer that returns any data you might need, a generator that given the initial data produces either another element or None to signify the sequence has ended, and a cleanup function. Initially, I don't need any supporting data so both the initialize and cleanup functions can do nothing. Here's what it looks like:&lt;/p&gt;&lt;pre&gt;let input = Seq.generate&lt;br /&gt; (fun () -&amp;gt; ()) // init&lt;br /&gt; (fun () -&amp;gt;&lt;br /&gt;   match getInput("&amp;gt;") with&lt;br /&gt;   | "#quit" -&amp;gt; None&lt;br /&gt;   | inp -&amp;gt; Some(inp))&lt;br /&gt; (fun () -&amp;gt; ()) // cleanup&lt;/pre&gt;&lt;p&gt;The middle function uses getInput that was defined above and asks the user for input. If they type "#quit" then the sequence ends, otherwise the input is returned.&lt;/p&gt;&lt;p&gt;Now we'll take this sequence and do something with it. Ultimately we'll want to evaluate the input and then keep prompting. Since the statement run might result in new variables being declared or existing ones modified, we'll need some way to remember what happened. The state of our world is referred to as an environment, so we'll write a dummy eval function that takes an environment, evaluates input, and returns the new environment to pass along to the next statement. For now let's use this:&lt;/p&gt;&lt;pre&gt;let eval (env:int) (x:string) =&lt;br /&gt; (Console.WriteLine("Evaluating: {0}", x);env)&lt;/pre&gt;&lt;p&gt;We ignore the environment, just print out the input, and return the environment unchanged.&lt;/p&gt;&lt;p&gt;The last step is to apply this eval function to our sequence of user input, passing the modified environment forward to the next element. This is a classic case of a fold. We start with an initial environment, call eval on the first item in the sequence, and then pass the resulting environment in when calling eval on the second item. Then the environment returned by eval'ing the second item gets passed into the third, etc. Here's what this looks like:&lt;/p&gt;&lt;pre&gt;Seq.fold eval 0 input |&amp;gt; ignore&lt;/pre&gt;&lt;p&gt;That's it. We don't care about the final value of the environment so we just pipe it to ignore. With only a few lines of F# we have a basic REPL going and we're ready to start with the real language work next time.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5369466039953704945?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5369466039953704945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5369466039953704945' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5369466039953704945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5369466039953704945'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/writing-compiler-with-f-part-2.html' title='Writing a Compiler with F# Part 2'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-2320718393961397283</id><published>2009-03-14T21:32:00.001-05:00</published><updated>2009-03-14T21:33:55.996-05:00</updated><title type='text'>Writing a Compiler with F#</title><content type='html'>&lt;p&gt;I've been dabbling with F# off and on since it was first publicly available, but I've never put enough time into it for it to feel natural to me.&amp;#160; The language itself has also evolved considerably since the early days.&lt;/p&gt;  &lt;p&gt;To take my knowledge of the F# from its current state (simple snippets typed into FSI used to befuddle and amaze people who have never seen a functional language with strong type inference before) into a solid working understanding I'm going to write a compiler for a new programming language.&amp;#160; Languages like F# excel at solving problems like this, so this should give me a good exposure to what it's really like.&lt;/p&gt;  &lt;p&gt;I also have some ideas regarding programming languages that I want to try out, but I'll talk more about those as they arise.&amp;#160; I'm going to start pretty simply for the target language and as time goes by I'll hopefully transition from worrying about the low level stuff like F# syntax into the really interesting stuff like the type system for my language and how it interoperates with the CLR.&lt;/p&gt;  &lt;p&gt;My intent is to make a series of posts highlighting the process I'm going through including interesting things about F#, compilers and compiling, and type systems.&amp;#160; I'm not getting any Big Ideas about the resulting language - my formal PL background is limited to a solid CS education, reading Pierce's &lt;em&gt;Types and Programming Languages&lt;/em&gt;, and lurking &lt;a href="http://lambda-the-ultimate.org" target="_blank"&gt;Lambda The Ultimate&lt;/a&gt;.&amp;#160; That is to say, I'm expecting to do things...less than optimally.&lt;/p&gt;  &lt;p&gt;Now since I've posted this introduction I actually have to work on this thing.&amp;#160; Next time I'll talk about some basics of F# and also compilers.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-2320718393961397283?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/2320718393961397283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=2320718393961397283' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2320718393961397283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2320718393961397283'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/03/writing-compiler-with-f.html' title='Writing a Compiler with F#'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-5914613207503660402</id><published>2009-02-11T16:26:00.002-06:00</published><updated>2009-02-11T16:35:58.987-06:00</updated><title type='text'>Type.IsAssignableFrom seems backwards</title><content type='html'>Every time I've ever had to use Type.IsAssignableFrom it has always felt backwards.  I usually use this method when checking if a given type implements a specific interface or derives from a certain base class.  &lt;br /&gt;&lt;br /&gt;This has come up recently when writing Windsor Interceptors and also methods that use reflection to walk my assemblies and automatically register components with my container.  In these scenarios I end up with the concrete type in a variable of type Type, while the interface or base class I'm checking for is statically known.  In the midst of my "where" clauses like "where type.IsGenericType &amp;&amp; type.IsPublic" it's tempting to write "type.IsAssignableFrom(typeof(IMyInterface))", but this is, of course, incorrect.  You have to reverse the order to get "typeof(IMyInterface).IsAssignableFrom(type)".  There's a small amount of cognitive dissonance for me every time I have to do it.&lt;br /&gt;&lt;br /&gt;What I'm really thinking is "make sure 'type' is an 'IMyInterface'.  Why not make it so the API reflects that?  Here's a little extension method that will let you write "where type.IsA&amp;lt;IMyInterface&amp;gt;()" instead.  This reads a lot more naturally to me.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static class TypeExtensions&lt;br /&gt;{&lt;br /&gt;  public static bool IsA&amp;lt;T&amp;gt;(this Type type)&lt;br /&gt;  {&lt;br /&gt;    return typeof(T).IsAssignableFrom(type);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-5914613207503660402?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/5914613207503660402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=5914613207503660402' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5914613207503660402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/5914613207503660402'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/02/typeisassignablefrom-seems-backwards.html' title='Type.IsAssignableFrom seems backwards'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-6266250235467468196</id><published>2009-02-11T14:11:00.002-06:00</published><updated>2009-02-11T14:21:52.748-06:00</updated><title type='text'>Extension Methods and CodeDom</title><content type='html'>A developer on my current project is creating a code generator and wondered how to emit extension methods.  It turns out this is really easy.  &lt;br /&gt;&lt;br /&gt;All you have to do is emit a System.Runtime.CompilerServices.ExtensionAttribute on your static method and the class that contains it.  Then just construct the method like a regular static method where the first parameter is the type you want to add the extension to.  For example, to emit something like:&lt;br /&gt;&lt;br /&gt;public static class StringExtensions {&lt;br /&gt;  public static string SayHi(this string instance) &lt;br /&gt;  { ... }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;you can emit:&lt;br /&gt;&lt;br /&gt;[Extension]&lt;br /&gt;public static class StringExtensions {&lt;br /&gt;  [Extension]&lt;br /&gt;  public static string SayHi(string instance)&lt;br /&gt;  { ... }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then make sure you reference System.Core.dll in your compiler options and everything will work fine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-6266250235467468196?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/6266250235467468196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=6266250235467468196' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6266250235467468196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6266250235467468196'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2009/02/extension-methods-and-codedom.html' title='Extension Methods and CodeDom'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-7807977851695466458</id><published>2008-11-28T17:48:00.004-06:00</published><updated>2008-12-05T07:40:14.159-06:00</updated><title type='text'>Using the Windsor Fluent Interface and an XML Configuration file</title><content type='html'>The framework we've built uses the Windsor container quite heavily.  Users of the framework supplied a dependencies.config file in their application that had a bunch of boilerplate stuff in it for our framework (facilities, framework component registrations, etc.) along with the registration for all of their components.&lt;br /&gt;&lt;br /&gt;Boilerplate anything bothers me and boilerplate XML even more so.  I wanted a nice programmatic way for the users to say "configure the framework" in their application as a substitute for all the XML.  What this meant, however, was that I now needed to configure the container 2 ways: programmatically using the fluent interface available in the trunk, and using a config file.&lt;br /&gt;&lt;br /&gt;My first attempt went something like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;WindsorContainer c = new WindsorContainer("dependencies.config");&lt;br /&gt;c.Register(Component.For&amp;lt;IFrameworkThing&amp;gt;().ImplementedBy&amp;lt;FrameworkThing&amp;gt;();&lt;br /&gt;c.AddFacility&amp;lt;RequiredFacility&amp;gt;();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;While that looks ok, the order things happened bit me.  Our facility (RequiredFacility in this example) happens to listen to the ComponentModelCreated event raised by the Kernel when a component is added to add a ComponentActivator (&lt;a href="http://codegoeshere.blogspot.com/2008/06/windsor-and-linq-datacontexts.html"&gt;more specifics here&lt;/a&gt;).  Since the XML gets processed (and all the components in it get added) before our facility is added, we miss the events we need to handle.&lt;br /&gt;&lt;br /&gt;I needed a way to have my facility in place before adding in the stuff in the config.  Due to a lack of documentation and the castle forums guys taking Thanksgiving off, I went down a bunch of fruitless avenues.   I looked into loading the framework stuff into a parent container and then creating a child container with &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;WindsorContainer child = &lt;br /&gt;  new WindsorContainer(&lt;br /&gt;    parentContainerAlreadyConfigured,&lt;br /&gt;    "dependencies.config");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;but the parent doesn't get the ComponentModelCreated events from the child.&lt;br /&gt;&lt;br /&gt;Eventually I ended up with the following solution.  This came from using Reflector (the best documentation for Castle I've found to date) and mimicking what the WindsorContainer constructor itself does.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;WindsorContainer container = new WindsorContainer();&lt;br /&gt;container.AddFacility&amp;lt;RequiredFacility&amp;gt;();&lt;br /&gt;//other programmatic config&lt;br /&gt;XmlInterpreter configInterpreter = &lt;br /&gt;  new XmlInterpreter("dependencies.config");&lt;br /&gt;configInterpreter.ProcessResource(&lt;br /&gt;  configInterpreter.Source,&lt;br /&gt;  container.Kernel.ConfigurationStore);&lt;br /&gt;container.Installer.SetUp(&lt;br /&gt;  container,&lt;br /&gt;  container.Kernel.ConfigurationStore);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The API seems a bit ugly, but it works. I get all the events I need and the users of the framework don't have to deal with any more boilerplate Windsor configuration.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update:&lt;/b&gt; It turns out you can replace all the XmlInterpreter stuff with this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;container.Install(&lt;br /&gt;  Configuration.FromXmlFile("dependencies.config"));     &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This does the same stuff, only it looks a lot nicer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-7807977851695466458?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/7807977851695466458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=7807977851695466458' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7807977851695466458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7807977851695466458'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/11/using-windsor-fluent-interface-and-xml.html' title='Using the Windsor Fluent Interface and an XML Configuration file'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-7045569333155074916</id><published>2008-10-31T18:37:00.002-05:00</published><updated>2008-10-31T18:40:13.809-05:00</updated><title type='text'>ASP.NET MVC and form editing scenarios</title><content type='html'>I'm a big fan of the new ASP.NET MVC framework and I've begun using it on several projects I'm delivering.  Though each preview gets better and better, there are still a few scenarios that could work more smoothly.  One of these is a normal form edit/post situation where the user types data into a form and posts it to a different action.&lt;br /&gt;&lt;br /&gt;For example, the user browsers to Customers/Edit?id=1 and gets the Edit view.  When submitting the form, the form posts to Customers/Update, which redirects back to Customers/List on success.&lt;br /&gt;&lt;br /&gt;ScottGu's blog (and others') have examples for this, but most rely on a simple set of data used for the edit screen.  ScottGu's example approach involves catching any exceptions during update and then re-rendering the Edit view. There are a few problems with this approach.  The first is that the Url now shows Customers/Update and not Customers/Edit (so the same screen has different Urls).  The second issue arises when your Edit view needs more than ViewData.Model to display.  Suppose the Customer object has a Status property that you want to pick from a dropdown.  To make this work, the Edit action would set ViewData["Statuses"] to the list of allowable statuses.  Now, in order for Update to render the Edit view, we'd have to also load up Statuses.  Now we're loading Statuses into ViewData in two places, the Edit action and the Update action.&lt;br /&gt;&lt;br /&gt;Because of these issues, we've taken a different approach.  Inside our base controller we override OnActionExecuted and look for exceptions.  If an exception happened, we capture the ModelState and store it in TempData.  We then redirect back to where we came from.  If no exception happened and our TempData has ModelState stored in it from an invalid form attempt, we restore it.&lt;br /&gt;&lt;br /&gt;Conceptually it's pretty simple, and it mostly works with the current beta release.  It solves the two issues we had in that the Edit action is the only place the data for the Edit view is populated and since we redirect the Url is always correct.&lt;br /&gt;&lt;br /&gt;There are still a few minor issues.  One is a bug I found in DropDownList where it doesn't look at the Model to find the selected value.  It is documented &lt;a href="http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=2534"&gt;on CodePlex here.&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I've posted a sample solution that uses this technique &lt;a href="http://www.mapsandmazes.com/code/MvcFormEdits - Blog Version.zip"&gt;here&lt;/a&gt;.  It's just the default MVC app with a new tab added to the page.&lt;br /&gt;&lt;br /&gt;Our real application does a lot more than this, including hiding all the unit of work logic and automatically committing if there were no errors, as well as integrating a validation framework based on Castle.Components.Validator and jQuery.  The extensibility of the MVC made adding all this stuff pretty easy and clean.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-7045569333155074916?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/7045569333155074916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=7045569333155074916' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7045569333155074916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7045569333155074916'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/10/aspnet-mvc-and-form-editing-scenarios.html' title='ASP.NET MVC and form editing scenarios'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-6649322222824438351</id><published>2008-09-13T20:26:00.002-05:00</published><updated>2008-09-13T20:36:34.856-05:00</updated><title type='text'>C# mod operator (%) and negative numbers</title><content type='html'>The C# mod operator, %, takes the sign of the dividend as the sign of the result.  Simply, this means that -1 % 3 is -1, and not 2 as I was expecting.  Apparently every language I've ever programmed professionally in behaves the same as C#, so I'm surprised I never noticed it before.  Of the other 2 languages I have handy, F# behaves just like C#, while Ruby gives me the result I expected.&lt;br /&gt;&lt;br /&gt;A more comprehensive list can be found at &lt;a href="http://en.wikipedia.org/wiki/Modulo_operation"&gt;Wikipedia&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This came up while trying to learn some WPF.  I have a main window and a bunch of child windows that I want to cycle through with ctrl-tab.  When I went to add cycling backwards with ctrl-shift-tab I was rewarded with a nice ArgumentOutOfRangeException.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-6649322222824438351?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/6649322222824438351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=6649322222824438351' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6649322222824438351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6649322222824438351'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/09/c-mod-operator-and-negative-numbers.html' title='C# mod operator (%) and negative numbers'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-6580121985322843649</id><published>2008-07-01T14:05:00.003-05:00</published><updated>2008-07-01T14:08:52.145-05:00</updated><title type='text'>NUnit within Visual Studio</title><content type='html'>My current client is not licensed for TFS, so we're going with NUnit for unit testing.  Rather than pay actual money for TestDriven.net, we're using NUnitForVS, a nice free codeplex tool that integrates NUnit with all the unit testing infrastructure present in Visual Studio 2008 Professional and Team Editions.&lt;br /&gt;&lt;br /&gt;It was a bit flaky at first, but a recent release has fixed all the non-trivial problems.&lt;br /&gt;&lt;br /&gt;Check it out &lt;a href="http://www.codeplex.com/NUnitForVS"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-6580121985322843649?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/6580121985322843649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=6580121985322843649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6580121985322843649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6580121985322843649'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/07/nunit-within-visual-studio.html' title='NUnit within Visual Studio'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-7105867392776899778</id><published>2008-06-10T21:06:00.002-05:00</published><updated>2008-06-10T21:11:03.688-05:00</updated><title type='text'>Windsor and Linq DataContexts</title><content type='html'>For one of the systems I built I needed to use the Windsor container to resolve instances of a Linq DataContext.  The DataContext was created using the standard Linq dbml designer.  Using standard Windsor stuff, the configuration should look something like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  &amp;lt;properties&amp;gt;&lt;br /&gt;    &amp;lt;connectionString&amp;gt;&lt;br /&gt;Data Source=server;&lt;br /&gt;Initial Catalog=Sample;&lt;br /&gt;Integrated Security=True&lt;br /&gt;    &amp;lt;/connectionString&amp;gt;&lt;br /&gt;  &amp;lt;/properties&amp;gt;&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;    &amp;lt;component&lt;br /&gt;      id="datacontext"&lt;br /&gt;      service="Sample.SampleDataContext, Sample"&lt;br /&gt;      type="Sample.SampleDataContext, Sample"&lt;br /&gt;      lifestyle="transient"&amp;gt;&lt;br /&gt;      &amp;lt;parameters&amp;gt;&lt;br /&gt;        &amp;lt;connection&amp;gt;#{connectionString}&amp;lt;/connection&amp;gt;&lt;br /&gt;      &amp;lt;/parameters&amp;gt;&lt;br /&gt;    &amp;lt;/component&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Easy, right?  Unfortunately if you try to run this and do container.Resolve&amp;lt;SampleDataContext&amp;gt;(); you'll get an error like: "Key invalid for parameter connection."  It turns out that what is happening is that Windsor doesn't know which Constructor to use.  The generated DataContext has 2 single parameter constructors, one that takes a string named "connection", and the other that takes an IDbConnection named "connection".  I think what happens is that the container tries to convert the property to an IDbConnection and it fails.&lt;br /&gt;&lt;br /&gt;What we need to do is change the way the constructor is chosen.  One simple way is just to add another constructor to your DataContext with a dummy ignored parameter.  Like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public SampleDataContext(string connection, int ignoreThis) &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you then add &amp;lt;ignoreThis&amp;gt;5&amp;lt;/ignoreThis&amp;gt; to the parameters section in the config then Windsor will find your new constructor and everything will work.  This, however, is ugly.&lt;br /&gt;&lt;br /&gt;A better way is to create a Facility.  What we're going to do is assume that all our DataContexts will follow the same pattern, i.e., that we always want to use the constructor that takes a single string parameter.&lt;br /&gt;&lt;br /&gt;First, we create a facility that inherits from Castle.MicroKernel.Facilities.AbstractFacility.  We want to replace the default ComponentActivator, so we'll need to get ahold of the ComponentModel when it's created.  We can override Init like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected override void Init()&lt;br /&gt;{&lt;br /&gt;  Kernel.ComponentModelCreated +=&lt;br /&gt;  (model) =&gt;&lt;br /&gt;  {&lt;br /&gt;    if (typeof(System.Data.Linq.DataContext)&lt;br /&gt;        .IsAssignableFrom(model.Implementation))&lt;br /&gt;    {&lt;br /&gt;      model.CustomComponentActivator = typeof(CustomActivator);&lt;br /&gt;    }&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notice we're only setting a custom activator for classes that inherit from DataContext.  Now all that's left is to implement CustomActivator.  Luckily, the default activator is designed to be inherited from; everything we need to change is virtual.  Create CustomActivator that inherits from Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.  You'll need a constructor that takes the same parameters.  All we need to do is override SelectEligibleConstructor to force the container to choose the single string parameter one.  We can do that just like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected override &lt;br /&gt;  ConstructorCandidate SelectEligibleConstructor&lt;br /&gt;   (CreationContext context)&lt;br /&gt;{&lt;br /&gt;  return &lt;br /&gt;    Model.Constructors.Cast&amp;lt;ConstructorCandidate&amp;gt;()&lt;br /&gt;    .First(c =&gt; c.Constructor.GetParameters().Length == 1 &lt;br /&gt;      &amp;&amp; c.Constructor.GetParameters()[0]&lt;br /&gt;                      .ParameterType == typeof(string));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The final step is just to add the facility to our configuration.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;facilities&amp;gt;&lt;br /&gt;&amp;lt;facility id="linqFacility" type="Core.LinqFacility, Core" /&amp;gt;&lt;br /&gt;&amp;lt;/facilities&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now everything works as expected for all DataContexts in our config.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-7105867392776899778?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/7105867392776899778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=7105867392776899778' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7105867392776899778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7105867392776899778'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/06/windsor-and-linq-datacontexts.html' title='Windsor and Linq DataContexts'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1199968650693470732</id><published>2008-05-14T20:52:00.006-05:00</published><updated>2008-12-23T15:40:05.000-06:00</updated><title type='text'>Anonymous Interface Implementation</title><content type='html'>With the introduction of lambdas, it's now incredibly easy to pass tiny bits of functionality around.  Unfortunately, some existing methods in the Framework take parameters of an interface type, instead of a delegate.  Contains, for example, takes an IEqualityComparer instead of a Predicate.  This makes using these methods in an ad-hoc manner difficult.  What we need is the ability to quickly throw together a temporary class that implements the interface, basically an anonymous type only with method implementation.&lt;br /&gt;&lt;br /&gt;I submitted a Connect item about this (&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=336215"&gt;here&lt;/a&gt;), but as you can see it won't be making it into this release.&lt;br /&gt;&lt;br /&gt;To tide myself over I wrote a version that is built on anonymous types, Reflection.Emit, and Funcs.  You can download it &lt;a href="http://www.mapsandmazes.com/code/AnonymousInterfaces.zip"&gt;here&lt;/a&gt;.  This is a proof of concept...no warranties...don't use in production...blah blah blah.&lt;br /&gt;&lt;br /&gt;As a sample, here's how to create an instance of IEqualityComparer that thinks strings are equal if they are the same length:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Make.Instance&amp;lt;IEqualityComparer&amp;lt;string&amp;gt;&amp;gt;(&lt;br /&gt;  new {&lt;br /&gt;    Equals = Make.Func(&lt;br /&gt;      (string x, string y) =&amp;gt; x.Length == y.Length)&lt;br /&gt;  })&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I had to use &lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/01/12/lambda-expressions-vs-anonymous-methods-part-three.aspx"&gt;Eric Lippert's trick&lt;/a&gt; to get lambdas and inferencing working in anonymous types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1199968650693470732?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1199968650693470732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1199968650693470732' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1199968650693470732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1199968650693470732'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/05/anonymous-interface-implementation.html' title='Anonymous Interface Implementation'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-2088595831093666239</id><published>2008-04-04T17:31:00.002-05:00</published><updated>2008-04-04T17:35:28.197-05:00</updated><title type='text'>DataContractSerializer and 0 length array</title><content type='html'>In short, I don't think the DataContractSerializer for WCF likes 0 length arrays at all.  I was getting mysterious exceptions and random crashing of my WCF service.  I was using wsHttpBinding and getting some WS-Trust invalid or expired security token message so I switched to basicHttpBinding.  When debugging that, after the return of my method on the server side, cassini would crash and I'd get Fatal Execution Engine Error messages in my event log.&lt;br /&gt;&lt;br /&gt;I cut my service method down to nearly as simple as it could go:&lt;br /&gt;&lt;br /&gt;return new MyClass { Name = "BLARG", Children = new MyClass[0] }&lt;br /&gt;&lt;br /&gt;and that was still dying.  But when I changed it to&lt;br /&gt;Children = null&lt;br /&gt;everything magically started working.&lt;br /&gt;&lt;br /&gt;This really merits more investigation but it's after 5 on a Friday and I'm going home.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-2088595831093666239?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/2088595831093666239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=2088595831093666239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2088595831093666239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/2088595831093666239'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/04/datacontractserializer-and-0-length.html' title='DataContractSerializer and 0 length array'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-6776742446787484481</id><published>2008-03-25T09:06:00.002-05:00</published><updated>2008-03-25T09:15:06.106-05:00</updated><title type='text'>New stuff</title><content type='html'>New job means new laptop.  New laptop means new laptop bag.&lt;br /&gt;&lt;br /&gt;The new laptop is a Lenovo T61p with the 15" screen.  I'm running Vista x64 on it and that part has gone smoothly so far.  Design-wise, I think I liked my Dell D820 better.  The T61p feels much heavier than the Dell (though I do have a 9 cell battery in this one), the screen is slightly off center, and I don't like the keyboard layout at all.  I'm perhaps overly concerned about keyboard layouts and this one just doesn't do it for me.  The biggest issues for me are that the arrow keys aren't normal sized keys, the escape key sits above F1, and the lower left corner is a special Fn key, rather than Ctrl.  By default, Fn-Space triggers the built in Lenovo Zoom utility, which is really jarring when you just intended to pop up intellisense.  I'm sure I'll get used to all that though.&lt;br /&gt;&lt;br /&gt;The new laptop bag is an Ogio Metroid and it's nothing but fantastic.  I was originally worried that the T61p wouldn't fit, but it easily does.  The Metroid is a backpack with a laptop pocket, but it also has a file section in the front that keeps my papers from sliding down and getting crumpled in the main pocket.  There's plenty of room for all my junk and the mp3 player pocket fits my external hard drive just fine.  Plus, I got it from amazon for $60 (of which work reimbursed me $40).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-6776742446787484481?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/6776742446787484481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=6776742446787484481' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6776742446787484481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/6776742446787484481'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/03/new-stuff.html' title='New stuff'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-8755663134582914236</id><published>2008-02-27T13:06:00.006-06:00</published><updated>2008-02-27T13:22:52.969-06:00</updated><title type='text'>Derived Properties in LINQ to SQL</title><content type='html'>When using a rich domain model, you often end up with properties that are dervied from other persisted values. To take a trivial example:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;public bool HasMiddleName&lt;br /&gt;{&lt;br /&gt;  get { return MiddleName != ""; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;where MiddleName is a persisted property (column in the database, mapped by LINQ, etc.).&lt;br /&gt;&lt;br /&gt;This works fine in object land, but breaks down when you need to query the database based on this property.  LINQ to SQL can't read into the definition of the property itself and figure out what to do. If you try to run something that looks like:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;setOfObjects.Where(o =&amp;gt; o.HasMiddleName)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;you'll get an exception saying that LINQ to SQL doesn't know how to translate HasMiddleName.&lt;br /&gt;&lt;br /&gt;Now you're left with a choice: either duplicate the implementation of your property in the query, or come up with something clever.  Starting with the assumption that duplicating domain knowledge is bad, let's explore the clever path.&lt;br /&gt;&lt;br /&gt;Our particular architecture builds up queries using IQueryable, to make sure that as much of our logic as possible is executed by the database, rather than in memory.  IQueryable&amp;lt;T&amp;gt;.Where takes an Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt;, basically an expression that represents a function taking your object and returning a boolean.  In the normal case, you just pass a lambda to Where and the compiler builds the expression for you.  In our case, we have to build the expression ourselves.  Back in the domain object we do:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;public static readonly Expression&amp;lt;Func&amp;lt;MyObject,bool&amp;gt;&amp;gt; &lt;br /&gt;  HasMiddleNameExpr = o =&amp;gt; o.MiddleName != "";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we can write queries that look like:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;var result = setOfObjects.Where(MyObject.HasMiddleNameExpr)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and things will run just fine.  Great!  Except we still have duplication: our object has a property with logic in it, and the definition of the expression with the logic in it.  Let's remove that.&lt;br /&gt;&lt;br /&gt;First, since Expressions can't be invoked directly, save a compiled version of the expression (i.e., a Func&amp;lt;MyObject,bool&amp;gt;).&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;public static readonly Func&amp;lt;MyObject,bool&amp;gt; HasMiddleNameFunc = &lt;br /&gt;  HasMiddleNameExpr.Compile();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now, define the property in terms of the Func.&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;public bool HasMiddleName&lt;br /&gt;{&lt;br /&gt;  get { return HasMiddleNameFunc(this); }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now all the duplication is removed.  Unfortunately this seems like quite a few hoops to have to jump through.  Instead of just a property we now have a property, a static function, and a static expression representing the function.&lt;br /&gt;&lt;br /&gt;Unfortunately, it gets worse.  The particular query we were writing depended on two derived properties and not just one.  That meant that we couldn't just call Where with our expression.  We wanted all objects where either one or the other property was true.  That meant we had to build the or expression ourselves.  It looks something like this in the query:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;ParameterExpression p = &lt;br /&gt;  Expression.Parameter(typeof(MyObject), "p");&lt;br /&gt;&lt;br /&gt;var result = setOfObjects.Where(&lt;br /&gt;  Expression.Lambda&amp;lt;Func&amp;lt;MyObject,bool&amp;gt;&amp;gt;(&lt;br /&gt;    Expression.OrElse(&lt;br /&gt;      Expression.Invoke(MyObject.HasMiddleName,p),&lt;br /&gt;      Expression.Invoke(MyObject.HasLastName,p)),&lt;br /&gt;    p));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What this does is build an expression that represents something like:&lt;br /&gt;&lt;pre style="font-size:smallest"&gt;&lt;br /&gt;p =&amp;gt; MyObject.HasMiddleNameFunc(p) || &lt;br /&gt;  MyObject.HasLastNameFunc(p)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The combining of two Func&amp;lt;T,bool&amp;gt; expressions via a logical operator could probably be hidden by an extension method to clean things up a bit.&lt;br /&gt;&lt;br /&gt;Ultimately, though, we ended up deciding that there was no way a junior developer reading this code in the future would be able to maintain this, much less understand it.  After all this exploration we opted just to duplicate the domain logic in the query.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-8755663134582914236?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/8755663134582914236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=8755663134582914236' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/8755663134582914236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/8755663134582914236'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/02/derived-properties-in-linq-to-sql.html' title='Derived Properties in LINQ to SQL'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-8972460944288102653</id><published>2008-01-25T22:49:00.001-06:00</published><updated>2008-02-27T13:33:38.582-06:00</updated><title type='text'>Also</title><content type='html'>Why does SqlMethods.Like throw NotImplementedException when you try to use it against in memory objects?&lt;br /&gt;&lt;br /&gt;It seems like it would be pretty easy to actually implement it with RegEx or something.  It's really inconvenient that you can't mock your database to test tricky queries with in memory objects because of this.&lt;br /&gt;&lt;br /&gt;Edit: &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=330320"&gt;Vote for my feedback!&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-8972460944288102653?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/8972460944288102653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=8972460944288102653' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/8972460944288102653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/8972460944288102653'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/01/also.html' title='Also'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1171488776475384402</id><published>2008-01-25T22:35:00.000-06:00</published><updated>2008-01-25T22:48:46.079-06:00</updated><title type='text'>Misc. Project Notes</title><content type='html'>First, a minor annoyance: If you happen to have join tables without primary keys defined, the LINQ designer won't generate the properties corresponding to the association.  Either go have a talk with your DBA or update the Primary Key property for your Properties in the designer and you'll be fine.&lt;br /&gt;&lt;br /&gt;Second, TFS is proving more of a hindrance than a help sometimes.  So much of the build setup requires duplicated settings on all clients, rather than being centrally managed.  Policies must be installed on all machines, code analysis configurations have to be imported into the solution, etc.  It seems like the right way for this to work would be for the TFS server to transparently distribute and install any artifacts required by the project.&lt;br /&gt;&lt;br /&gt;Additionally, code analysis is nice, but there's no way to have a check in policy that uses it that only applies to some of the projects in the solution.  We'd like to exclude our unit test projects (since [ExpectedException] tests in particular result in unreferenced variable warnings), but it's all or nothing.&lt;br /&gt;&lt;br /&gt;The source control piece is definitely nicer than VSS, but really, what isn't?  There are a few recurring issues, though.  Sometimes opening a solution causes lots of the project files to get checked out, even though there are no changes locally (doing a Compare confirms that all files are identical).  The other issue revolves around the vsmdi file used with the testing bits.  For some reason this file is included in the solution and checked into source control, even though it contains user-specific information.  If you bring up the test list window and pick 3 tests to run, the vsmdi is updated to show this.  VS tries to check out the file (which someone invariably already has out), which results in VS checking out the solution and adding a new vsmdi file named solutionname1.vsmdi (followed by solutionname2.vsmdi, etc.).  Excluding vsdmi from source control entirely as part of TFS settings gets ignored, excluding the file manually from the solution gets ignored, etc.  I'd love a workaround for this problem.&lt;br /&gt;&lt;br /&gt;The only other thing that would make things easier is an update for BizTalk 2006 R2 so we can use VS2008 to develop against it and not have to run 2 IDEs (and have custom build steps using the 2005 devenv in our team build).&lt;br /&gt;&lt;br /&gt;Despite all that complaining, we still have a pretty clever solution going that uses a ton of cool technologies like LINQ, CI, MSTEST, Rhino Mocks, Watin, Windsor, ASP.NET MVC, WCF, and BizTalk 2006 R2.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1171488776475384402?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1171488776475384402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1171488776475384402' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1171488776475384402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1171488776475384402'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2008/01/misc-project-notes.html' title='Misc. Project Notes'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-3429481078784983291</id><published>2007-12-20T15:24:00.000-06:00</published><updated>2007-12-20T15:39:59.976-06:00</updated><title type='text'>Whining</title><content type='html'>WatiN is a reasonably nice tool for automating UI tests.  It even has a recorder that we could probably get our BAs to understand.  It seems like a great fit for having the BAs (basically 'the customer') create our acceptance tests.  They click around for a bit, save the recorded test as an MSTest cs file, and send it to a developer who adds this file to our Test Project.  Now, through the magic of Team Builds, we have automated acceptance tests that are owned by the business and not developers.  &lt;br /&gt;&lt;br /&gt;Except:&lt;br /&gt;- WatiN basically scripts IE so it needs to open an IE window.&lt;br /&gt;- VS Team Build runs as a service.&lt;br /&gt;- The client's policy forces that service to run as a specific service account, not LocalSystem.&lt;br /&gt;- Only a service running as LocalSystem can be allowed to interact with the desktop.&lt;br /&gt;&lt;br /&gt;End result:&lt;br /&gt;There's no way to have automated acceptance tests with WatiN as part of our CI Team Build.&lt;br /&gt;&lt;br /&gt;Great.&lt;br /&gt;&lt;br /&gt;There are arguments to be made about not needing acceptance tests to run at every build and maybe they could be scheduled to run nightly or something.  The downside is that all the test results are now outside of all the TFS reporting.  We're talking ourselves into this being ok.&lt;br /&gt;&lt;br /&gt;What's not ok is that we were also planning to use WatiN for developers to create UI-related integration tests.  Those definitely need to run as part of our CI build. Given the above restrictions, we decided to investigate the Web Test feature of MSTest.  Feature-wise they seemed to be a good fit.&lt;br /&gt;&lt;br /&gt;Except:&lt;br /&gt;Web Tests are only available in the Tester edition of VSTS and all the developers have Developer edition.&lt;br /&gt;&lt;br /&gt;How frustrating.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-3429481078784983291?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/3429481078784983291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=3429481078784983291' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/3429481078784983291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/3429481078784983291'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/12/whining.html' title='Whining'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-1516658397717570443</id><published>2007-11-16T15:21:00.000-06:00</published><updated>2007-11-16T15:26:05.493-06:00</updated><title type='text'>More functional Ruby</title><content type='html'>I just stumbled across Reg's blog today after a link from Jeff Atwood's.  Almost immediately I found &lt;a href="http://weblog.raganwald.com/2007/10/stringtoproc.html"&gt;this post about turning strings into procs in Ruby&lt;/a&gt;.  Wow.&lt;br /&gt;&lt;br /&gt;One of the only things about Ruby that consistently bugged me was the difficulty of passing existing functions into methods expecting blocks without having to wrap them in boilerplate junk.  This (and Symbol#to_proc) basically cleans all that up.&lt;br /&gt;&lt;br /&gt;He also has a nice implementation of unfold posted.&lt;br /&gt;&lt;br /&gt;IronRuby can't get here fast enough.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-1516658397717570443?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/1516658397717570443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=1516658397717570443' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1516658397717570443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/1516658397717570443'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/11/i-just-stumbled-across-regs-blog-today.html' title='More functional Ruby'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-9100079815995355005</id><published>2007-10-22T12:20:00.000-05:00</published><updated>2007-10-22T12:31:06.540-05:00</updated><title type='text'>A quick note about Extension Methods</title><content type='html'>If you're ever adding extension methods to a generic type (like say, IEnumerable&amp;lt;T&amp;gt;), nothing says you have to keep the same constraints on T for your method.  For example, maybe your method is only relevant for reference types.  &lt;br /&gt;&lt;br /&gt;Assume you have a simple class called Box&amp;lt;T&amp;gt; with a single property Contents of type T.  Box is just a box (a wrapper) around an instance of some unconstrained type T. You could define something like:&lt;br /&gt;&lt;br /&gt;public static bool IsNull&amp;lt;T&amp;gt;(this Box&amp;lt;T&amp;gt; box) where T : class //note the new constraint&lt;br /&gt;&lt;br /&gt;Now our extension method will only apply to Boxes whose T is a reference type.&lt;br /&gt;Box&amp;lt;string&amp;gt; sbox = new Box&amp;lt;string&amp;gt;("abc");&lt;br /&gt;bool isNull = sbox.IsNull(); //this works&lt;br /&gt;&lt;br /&gt;Box&amp;lt;int&amp;gt; ibox = new Box&amp;lt;int&amp;gt;(5);&lt;br /&gt;isNull = ibox.IsNull(); //does not compile&lt;br /&gt;&lt;br /&gt;For some reason I expected the extra constraints not to work and I was surprised when they did.  Of course you can only make your extension method type parameter &lt;span style="font-style:italic;"&gt;more&lt;/span&gt; constrained than the existing type.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-9100079815995355005?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/9100079815995355005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=9100079815995355005' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/9100079815995355005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/9100079815995355005'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/10/quick-note-about-extension-methods.html' title='A quick note about Extension Methods'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-3725394946503433075</id><published>2007-09-30T18:22:00.000-05:00</published><updated>2007-09-30T18:45:41.512-05:00</updated><title type='text'>Build your own whiteboard</title><content type='html'>Everyone knows that a developer's productivity is directly proportional to the total surface area of whiteboard he has access to, but places like Office Depot want $150 or more for a whiteboard of any appreciable size.  Luckily, building your own is incredibly easy.  Here's all you have to do:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Head to your local hardware store to acquire materials. You'll need:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;A 4'x8' sheet of melamine coated board.  I found this in the Building Materials section.  This is the key piece of the whole thing.  Obviously 4'x8' is a lot of whiteboard.  I had the helpful hardware store employee cut mine into 2 pieces, a 3'x4' and a 5'x4'.  The whole thing is about $11.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Since the board is thin and wobbly, you'll need something to stabilize it.  I opted to build a simple wood frame to mount the board to.  You could glue it to a big sheet of plywood, but that will make the whole thing pretty heavy and difficult to move.  Alternatively you could just mount the board directly to one of your walls with glue or cleverly placed trim or something.&lt;br /&gt;&lt;br /&gt;The hardware store sold nice 1.5" wide pieces of pine that came in 8' lengths.  I bought 4 and had them custom cut to the size I needed. 2 were cut into a 3' length and a 5' length (for the top and bottom of the frames), and the other 2 were cut into 2x 3'-9" pieces each (4 total) to form the sides of each board (4' tall - 1.5" for the width of the top frame piece - 1.5" for the width of the bottom frame piece).  Each one of these was about $2.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;To assemble the frame I bought some flat L-shaped brackets.  The packages I found came with 4 brackets and all the screws.  I bought two of these for about $3 each.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Finally, to glue the board to the frame I bought some construction adhesive.  It comes in a tube that fits in a caulk gun which you may have to buy if you don't have one.  It was about $4.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If don't have some already, get some sandpaper to smooth out the frame edges.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Total material cost is just under $30.  For the record, $30 &amp;lt; $150.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Now to build the thing.  First sand the frame pieces nice and smooth.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The brackets I bought said to drill 5/64" pilot holes before running the screws, so I dutifully complied.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Then I screwed in all the brackets.  I did the first 2 one at a time, but for the final 2 I put them in loosely and then tightened gradually going from one side to the other to make sure everything lined up fine.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Now, place the melamine white side down on the floor (maybe on a towel so as not to scratch anything).  Run a nice solid line of construction adhesive along the frame you just built on the side you didn't mount the brackets on.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Place the frame onto the melamine, line things up, and press down firmly all along the edges.  This step is much easier if you can procure the aid of a Lovely Assistant.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Put some bricks or something heavy along the edges of the frame to hold things together while the adhesive sets up.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;I let mine set up for a day and by then it was rock solid.  I now have 2 giant whiteboards that cost about $30 and less than an hour of labor total.  Not bad at all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-3725394946503433075?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/3725394946503433075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=3725394946503433075' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/3725394946503433075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/3725394946503433075'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/09/build-your-own-whiteboard.html' title='Build your own whiteboard'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-7359654225340399762</id><published>2007-06-12T15:23:00.000-05:00</published><updated>2007-06-12T16:04:14.677-05:00</updated><title type='text'>Extending the CalendarExtender</title><content type='html'>The Ajax Control Toolkit comes with an extender that automatically adds a javascript-based calendar popup to any TextBox.  While the calendar is certainly nicer than the ASP.NET control that requires a postback for every action, the customization options are severely limited.  In particular, the CalendarExtender always allows selection of every single date.  For one of our apps we needed to limit the selection to certain days.  This is how we did it.&lt;br /&gt;&lt;br /&gt;The implementation of the CalendarExtender (mostly) lives in CalendarExtender.cs and the client-side javascript file, CalendarBehavior.js.  Nearly everything we need is in the javascript.  For our limited scenario, we decided to simply add a property to the control that lets you specify a javascript function to call that returns a bool, indicating whether or not the date is selectable.  First, add the new property to the cs file:&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;[ExtenderControlProperty]&lt;br /&gt;[ClientPropertyName("isDateSelectableFunction")]&lt;br /&gt;public string IsDateSelectableFunction&lt;br /&gt;{&lt;br /&gt;  get { return GetPropertyValue("IsDateSelectableFunction", ""); }&lt;br /&gt;  set { SetPropertyValue("IsDateSelectableFunction", value); }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ExtenderControlProperty attribute tells the toolkit to magically make your property available on the client side, while the ClientPropertyName attribute tells the toolkit what name to give the client property.  GetPropertyValue and SetPropertyValue just move things back and forth from ViewState.&lt;br /&gt;&lt;br /&gt;The real work is done in the behavior file.  First we have to initialize our new property.  This happens right at the top of the file.&lt;br /&gt;&lt;pre  style="font-size:smaller;"&gt;&lt;br /&gt;this._yearsBody = null;&lt;br /&gt;this._button = null;&lt;br /&gt;//new&lt;br /&gt;this._isDateSelectableFunction = null;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we have a private field that will automatically get populated with the value set on the server control.  Since javascript doesn't support Properties like C#, we need to add getter and setter methods.  Above the definition for "get_animated" add the following&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;get_isDateSelectableFunction : function() {&lt;br /&gt;  return this._isDateSelectableFunction;&lt;br /&gt;},    &lt;br /&gt;set_isDateSelectableFunction : function(value) {&lt;br /&gt;  this._isDateSelectableFunction = value;&lt;br /&gt;},&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next, we have to use it.  There's a lot of javascript to wade through, but the important bits are all in one place.  The CalendarExtender has several views, allowing you to select days, zoom out to months, or zoom out to years.  Since date selection only happens on the days view, that's the only thing to be modified.  The extender builds a single grid to represent the month and then renumbers each cell whenever you switch months.  All we're going to do is insert a bit of code when the numbering is happening.  This numbering happens in the _performLayout function.  Find this function in the js file.  There's a big switch statement on this._mode to handle which view is currently active.  We're interested in the "days" case.&lt;br /&gt;&lt;br /&gt;There are 2 main for loops here. The first (from i = 0, i &lt; 7) renders the headers, while the next one is nested and walks over both weeks and days.  Right after &lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;$common.removeCssClasses(dayCell.parentNode, &lt;br /&gt;  [ "ajax__calendar_other", "ajax__calendar_active" ]);&lt;br /&gt;Sys.UI.DomElement.addCssClass(dayCell.parentNode, &lt;br /&gt;  this._getCssClass(dayCell.date, 'd'));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;but before&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;currentDate = new Date(currentDate.getFullYear(), &lt;br /&gt;  currentDate.getMonth(), currentDate.getDate() + 1);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;we're going to add our code.   At this point, the cell (dayCell) has been populated with the right number and currentDate is set to the date in the cell.  All we do is pass this date into our function and take action based on the result.  Here's the code:&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;$common.removeHandlers(dayCell, this._cell$delegates);&lt;br /&gt;if(eval(this.get_isDateSelectableFunction() + "(currentDate);")) &lt;br /&gt;{&lt;br /&gt;  $addHandlers(dayCell, this._cell$delegates);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What we've done is really simple.  First, we unhook the event handlers for the cell.  This makes them not clickable (and removes the mouseover highlighting).  Next, if the result of our function is true, we add the handlers back.  It's important to remove and re-add instead of just doing an "if(!eval) remove" type of thing because the grid is reused for every month, so we must handle both cases every time.&lt;br /&gt;&lt;br /&gt;That's all there is to it.  An easy additional feature would be to have a separate CSS class for selectable dates.  To do that, first add the name of your CSS class to the call to $common.removeCssClasses (e.g  [ "ajax__calendar_other", "ajax__calendar_active", "my_new_class ]).  Then, put Sys.UI.DomElement.addCssClass(dayCell.parentNode, "my_new_class"); inside the "if(eval)" block.&lt;br /&gt;&lt;br /&gt;For completeness you should probably handle disabling the "Today" link at the bottom of the calendar when today isn't a valid date, but given the above information you can handle that the same way.&lt;br /&gt;&lt;br /&gt;Here's a snippet of the control used in a page that limits the selectable dates to Mondays only.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;&amp;lt;script language="javascript" type="text/javascript"&amp;gt;&lt;br /&gt;function isSelectable(x)&lt;br /&gt;{&lt;br /&gt;  return x.getDay() == 1; //Mondays&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;asp:TextBox ID="txtDate" runat="server"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;ajax:CalendarExtender ID="calExtDate" runat="server"&lt;br /&gt;  TargetControlID="txtDate" PopupButtonID="imgCal"&lt;br /&gt;  IsDateSelectableFunction="isSelectable"&amp;gt;&amp;lt;/ajax:CalendarExtender&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-7359654225340399762?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/7359654225340399762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=7359654225340399762' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7359654225340399762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/7359654225340399762'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/06/extending-calendarextender.html' title='Extending the CalendarExtender'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-866175351950985943</id><published>2007-05-31T08:55:00.000-05:00</published><updated>2007-05-31T08:58:18.672-05:00</updated><title type='text'>Quick Note</title><content type='html'>If you use regular expressions to validate email addresses, make sure you allow '+' before the '@' character.  This is perfectly valid according to the RFC and some email servers let you do fun things with it.  Gmail, for example, delivers anything addressed to 'youremail+anythingyouwanthere at gmail' to 'youremail at gmail'.  Combined with filters that automatically label and file items, you can get email delivered directly to a specific folder.  I know some unix mail systems support this stuff, too.&lt;br /&gt;&lt;br /&gt;Don't be lazy with your regular expressions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-866175351950985943?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/866175351950985943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=866175351950985943' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/866175351950985943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/866175351950985943'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/05/quick-note.html' title='Quick Note'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-4953230218809694002</id><published>2007-05-08T08:40:00.001-05:00</published><updated>2008-06-03T23:30:47.626-05:00</updated><title type='text'>Dynamic Cast in C#</title><content type='html'>C# allows you to overload the implicit and explicit cast operators to permit your class to be converted to another, either automatically (implicit) or declaratively (explicit).  All the necessary conversions are determined and applied by the compiler, at compile time.  For example, if you have the following (assume A and B aren't in the same hierarchy):&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;A a = new B();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The compiler will look to see if B has an implicit cast operator (defined as a static method) and insert it for you if it exists, or fail with a type checking error if it doesn't.  Likewise&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;A a = (A)(new B());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;will cause the compiler to insert a call to the explicit cast operator defined in B that casts to A, or fail if it doesn't exist.&lt;br /&gt;&lt;br /&gt;This is fine when you only need to handle conversions based on the compile-time type of your objects.  If, however, you had written this extremely contrived example:&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;B b = new B();&lt;br /&gt;object o = b;&lt;br /&gt;A a = b;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This would fail to compile because the compiler is now checking the type "object" for an implicit cast to A, even though the underlying type of o is "B".  If you put an explicit cast in "A a = (A)b;" it would then fail at run time, like any other invalid cast.  What is really needed is a way to apply cast operators based on the run-time type of the object.  This ends up being a pretty simple exercise in reflection.&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;public static MethodInfo GetMethod(Type toSearch, string methodName,&lt;br /&gt;    Type returnType, BindingFlags bindingFlags)&lt;br /&gt;{&lt;br /&gt;    return Array.Find(&lt;br /&gt;        toSearch.GetMethods(bindingFlags),&lt;br /&gt;            delegate(Refl.MethodInfo inf)&lt;br /&gt;            {&lt;br /&gt;                 return ((inf.Name == methodName) &amp;&amp;amp; (inf.ReturnType == returnType));&lt;br /&gt;            });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static T DynamicCast&amp;lt;T&amp;gt;(object o)&lt;br /&gt;{&lt;br /&gt;    Type ot = o.GetType();&lt;br /&gt;    MethodInfo meth = GetMethod(ot, "op_Implicit", typeof(T),&lt;br /&gt;        BindingFlags.Static | BindingFlags.Public);&lt;br /&gt;    if(meth == null)&lt;br /&gt;    {&lt;br /&gt;        meth = GetMethod(ot, "op_Explicit", typeof(T),&lt;br /&gt;            BindingFlags.Static | BindingFlags.Public);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    if(meth == null) throw new InvalidCastException("Invalid Cast.");&lt;br /&gt;&lt;br /&gt;    return (T)meth.Invoke(null, new object[] { o });&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we can just do&lt;br /&gt;&lt;pre style="font-size:smaller;"&gt;&lt;br /&gt;B b = new B();&lt;br /&gt;object o = b;&lt;br /&gt;A a = DynamicCast&amp;lt;A&amp;gt;(o);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and everything works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-4953230218809694002?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/4953230218809694002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=4953230218809694002' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4953230218809694002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/4953230218809694002'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/05/dynamic-cast-in-c.html' title='Dynamic Cast in C#'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-116889021140874164</id><published>2007-03-08T10:00:00.000-06:00</published><updated>2007-03-08T10:28:19.265-06:00</updated><title type='text'>Anonymous Method Subtleties</title><content type='html'>As explained quite clearly by Raymond Chen &lt;a href="http://blogs.msdn.com/oldnewthing/archive/2006/08/02/686456.aspx" target="_blank"&gt;here&lt;/a&gt;, the compiler generates a few different things when confronted with an anonymous method, based on what the method does.  If the method doesn't refer to anything other than its parameters, it generates a static method on the containing class.  If it refers to class instance members, you get an instance method.  When the method refers to other variables in the lexically-enclosing method (basically when you need a closure), the compiler generates a sealed nested class to track those variables and puts the method there.&lt;br /&gt;&lt;br /&gt;We have an interesting framework scenario where controls register event handlers with a custom base page.  In the "add" section of the event in the page, we need to get a reference to the control that is adding the handler.  Generally this is available by reading "value.Target" (value is a Delegate since we're inside the "add" of an event).  However, if you happen to be using an anonymous method as your handler and you happen to change it to require a closure, "value.Target" will instead point at the compiler-generated nested class.  This nested class inherits from nothing, implements no interfaces, and has a field for each captured variable as well as a reference to the instance the anonymous method is defined in.&lt;br /&gt;&lt;br /&gt;As far as I can tell, there isn't a general way to get from the instance of the nested class back to the instance of the surrounding class.  Furthermore, there isn't a general, easy way to detect that "value.Target" is giving you a generated class rather than the one you were expecting.  Since anonymous methods are a compiler trick, there's no run time information available via reflection to tell you whether a method came from an anonymous method or not.&lt;br /&gt;&lt;br /&gt;We still needed to get at the control, so we had to guess.  We guess (with very high probability) that if "value.Target" doesn't inherit from Control, it must be an anonymous method.  We then do a few sanity checks to make sure (including checking that the class is sealed, private, nested, and has a [CompilerGenerated] attribute on it).  Then, to get at the original instance, we find the field of "value.Target" whose type matches the outer type of our class, and then read its value.  It looks a little something like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (d.Target is Control)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    return d.Target;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Type targetType = d.Target.GetType();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (!(targetType.IsNestedPrivate &amp;&amp;amp; targetType.IsSealed&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     &amp;&amp;amp; (targetType.GetCustomAttributes(&lt;br /&gt; typeof(CompilerGeneratedAttribute), false).Length == 1)))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    //you've hit the Anonymous Method case with something &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    //&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;that doesn't appear &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;to be an anonymous method&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    throw new InvalidOperationException("Error.");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Type outerClassType = targetType.DeclaringType;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;FieldInfo outerField = Array.Find(targetType.GetFields(),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            delegate(FieldInfo field)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;               return field.FieldType.Equals(outerClassType);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            });&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (outerField == null)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    //see note on the throw exception above&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    throw new InvalidOperationException("Error.");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;return outerField.GetValue(d.Target);&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This would be a lot easier if the compiler-generated class implemented an interface or something with a single method returning object that pointed back to the enclosing instance.  Then I could just say:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;return (d.Target is IAnonymousMethodState ?&lt;br /&gt;((IAnonymousMethodState)d.Target).EnclosingInstance :&lt;br /&gt;d.Target);&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;I'm going to suggest this at the Connect site and see what happens.&lt;br /&gt;Edit: Suggested &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=262339" target="_blank"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-116889021140874164?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/116889021140874164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=116889021140874164' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116889021140874164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116889021140874164'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/03/anonymous-method-subtleties.html' title='Anonymous Method Subtleties'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-116949104363631058</id><published>2007-01-22T12:30:00.001-06:00</published><updated>2009-12-19T11:35:55.576-06:00</updated><title type='text'>Referencing a Master Page from a User Control</title><content type='html'>UPDATE: It turns out this works fine for debugging, but once you go to publish it doesn't work at all (if you check the Allow Updateable box).  It looks like the Reference Directive is being ignored when compiling the code behind file so it can't find the class "ASP.nameofmymasterpage_master".  I'll update again if I find a solution.  Very discouraging.&lt;br /&gt;&lt;br /&gt;UPDATE 2: see workarounds below&lt;br /&gt;&lt;br /&gt;I ran into a situation where I needed to access a custom property of a master page from within a user control.  Were I dealing with a regular page, the MasterType directive would have worked fine, but this doesn't work for user controls.&lt;br /&gt;&lt;br /&gt;I started by figuring out the name of the type of my custom master page by mousing over a line like "Page.Master" in one of my aspxs that contained a MasterType directive.  This told me that the type of the master page is something like "ASP.nameofmymasterpage_master".  The parent class for this is the class in the master page cs file, usually something like "nameofmymasterpage".&lt;br /&gt;&lt;br /&gt;I then tried casting "Page.Master" to "ASP.nameofmymasterpage_master" in the cs file for my user control, but the compiler complained that it didn't know about this type. To make it aware, you have add the seldom used Reference directive to the ascx file.  Something like "&amp;lt;%@ Reference VirtualPath="~/nameofmymasterpage.master" %&amp;gt;".  Then the type "ASP.nameofmymasterpage_master" is available so the line with the cast can compile and everything works.&lt;br /&gt;&lt;br /&gt;In summary, put this in the ascx:&lt;br /&gt;&amp;lt;%@ Reference VirtualPath="~/nameofmymasterpage.master" %&amp;gt;&lt;br /&gt;&lt;br /&gt;So that you can do this in the ascx.cs:&lt;br /&gt;string thingIwant = (Page.Master as ASP.nameofmymasterpage_master).CustomProperty;&lt;br /&gt;&lt;br /&gt;WORKAROUNDS:&lt;br /&gt;1. Just use Web Application Projects which I should be doing anyway, but I haven't yet gotten the time to update all the sites we currently have&lt;br /&gt;2. Define an interface in your App_Code folder with all the operations you need exposed from your master page.  In your master page cs file, mark the class as implementing your interface.  Then in your ascx, just cast Page.Master to your interface type and go to town.  You don't need the Reference directive at all.  Not as simple as it should be, but it works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-116949104363631058?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/116949104363631058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=116949104363631058' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116949104363631058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116949104363631058'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/01/referencing-master-page-from-user.html' title='Referencing a Master Page from a User Control'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-116895908151981665</id><published>2007-01-16T08:40:00.000-06:00</published><updated>2007-01-16T09:09:38.283-06:00</updated><title type='text'>Type Theory</title><content type='html'>For fun I just finished reading Pierce's &lt;em&gt;Types and Programming Languages&lt;/em&gt;.  I missed some of the formal background for PL while in school since I skipped a pre-req or two to get into a compiler class that my favorite professor was teaching.  It was nice to go back and fill in the gaps.  TAPL came highly recommended from &lt;a href="http://lambda-the-ultimate.org/" target="_blank"&gt;LtU&lt;/a&gt; and it didn't disappoint.  Now, of course, I'm seeing new programming languages as the answer to everything.&lt;br /&gt;&lt;br /&gt;More specifically I'm interested in the practical difference between a statically structurally typed language with type inference and a dynamically typed language.  It seems that structural typing gets pretty close (depending on the implementation) to the duck typing promised by languages like Ruby while still being checked at compile time.  Obviously there are some compromises like meta-programming, but there are even some statically typed languages that offer this as well.&lt;br /&gt;&lt;br /&gt;Unfortunately there isn't a good candidate .net language to play with.  Although OCaml is structurally typed, F# remains nominally typed, probably for .net interop reasons.  Because of the nature of the CLR, any structurally typed language would have to in effect fake it, via reflection or something.  I'm thinking of writing a toy language just to play with this, exposing parameters as "object", invoking methods via reflection, and maybe indicating type constraints via an attribute or something.  Hopefully I'll find some time for this.&lt;br /&gt;&lt;br /&gt;Also, &lt;a href="http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/" target="_blank"&gt;this&lt;/a&gt; is quite good (and released under a Creative Commons license), despite the Boring Manager's name.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-116895908151981665?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/116895908151981665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=116895908151981665' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116895908151981665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116895908151981665'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2007/01/type-theory.html' title='Type Theory'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-116309105219025759</id><published>2006-11-09T10:40:00.000-06:00</published><updated>2006-11-09T11:16:09.756-06:00</updated><title type='text'>ObjectDataSource doesn't respect culture on update</title><content type='html'>I've recently run into an issue with ObjectDataSource, GridView, and alternate cultures. My present client has a Candian office and the project requires selection of a date from a dropdown. When the data binding to the list of possible dates occurs, the data source uses the current culture to format the dates, so I end up with a dropdown whose ListItems have values like "29/10/2006" and "30/10/2006" since they do their dates backwards up there. This is completely expected and is definitely how things should work.&lt;br /&gt;&lt;br /&gt;The problem arises when the user clicks the update button and we have to turn that string (dropdown.SelectedValue) back into a DateTime. Here the ObjectDataSource messes up and converts the string back using the InvariantCulture, which throws an exception since "30/10/2006" isn't a valid date.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105016" target="_blank"&gt;This Microsoft Connect link summarizes the issue a bit more.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I was unhappy with the workaround posted there so I figured out a better one. Basically we just do the DateTime conversion ourselves, instead of letting the ObjectDataSource handle it.&lt;br /&gt;&lt;br /&gt;1. Handle the ObjectDataSource Updating event.&lt;br /&gt;2. In the handler, replace the string input parameter with its culturally aware DateTime equivalent, using something like:&lt;br /&gt;&lt;br /&gt;&lt;div style="FONT-SIZE: small; font-face: Courier"&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;TypeConverter converter =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TypeDescriptor.GetConverter(typeof(DateTime));&lt;br /&gt;e.InputParameters["DateField"] =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;converter.ConvertFromString(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.InputParameters["DateField"] as string);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And that's it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-116309105219025759?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/116309105219025759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=116309105219025759' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116309105219025759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/116309105219025759'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/11/objectdatasource-doesnt-respect.html' title='ObjectDataSource doesn&apos;t respect culture on update'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115981963364811635</id><published>2006-10-02T14:53:00.000-05:00</published><updated>2006-10-02T15:11:41.303-05:00</updated><title type='text'>Enabling Sane Project and Solution Structure</title><content type='html'>One of the constant pains of Visual Studio 2005 and Visual SourceSafe is the strong tie between solution, file system, and VSS structures.  If you only ever have a single large solution with all of your projects underneath it, this never becomes apparent.  If, however, you have several core components that need to be shared across several distinct solutions (systems/applications/whatever), things get gross.  Visual Studio likes the solution to be at a higher level in VSS and the file system than all the projects contained in it.  Once you have a project that needs to be in more than one solution (i.e., have more than one parent folder), this is impossible.  Ideally I'd like my file system to look something like:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;c:\projects (all solution files live here)&lt;br /&gt;c:\projects\sharedlib1&lt;br /&gt;c:\projects\sharedlib2&lt;br /&gt;...&lt;br /&gt;c:\projects\websites\site1&lt;br /&gt;c:\projects\websites\site2&lt;br /&gt;etc.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;with a similar VSS structure:&lt;br /&gt;&lt;blockquote&gt;$/ (all solutions here)&lt;br /&gt;$/sharedlib1&lt;br /&gt;$/sharedlib2&lt;br /&gt;...&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here's what I do when creating a new solution and project to make this work:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a blank solution&lt;br /&gt;File-&gt;New Project&lt;br /&gt; Other Project Types/Visual Studio Solutions/Blank Solution&lt;br /&gt;&lt;br /&gt;Don't check "Add to Source Control"&lt;br /&gt;Location: c:\projects&lt;br /&gt;Name: whatever (application name)&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;File System Surgery&lt;br /&gt;File-&gt;Save As...&lt;br /&gt; c:\projects\whatever.sln&lt;br /&gt;Delete the subdirectory under projects (should be c:\projects\whatever\)&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Add solution to VSS&lt;br /&gt;Right click on sln, Add to Source Control&lt;br /&gt;Leave name alone (will be whatever.root)&lt;br /&gt;Location $/&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;VSS Surgery&lt;br /&gt;Start the VSS Client&lt;br /&gt;Drag and drop Whatever.sln and Whatever.vssscc from c:\projects into $\ in VSS&lt;br /&gt;In Visual Studio, go to File-&gt;Source Control-&gt;Change Source Control&lt;br /&gt;There should be line line listed that says "Solution: Whatever.sln"&lt;br /&gt;Click the elipsis ("...") in the Server Binding column&lt;br /&gt;Pick $/&lt;br /&gt;Hit Ok twice&lt;br /&gt;In VSS, right click on $/whatever.root and pick delete (check the box to destroy permanently)&lt;br /&gt;Close VSS&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;When adding new projects, always choose "C:\projects" for Location&lt;br /&gt;When adding new websites, always choose "C:\projects\websites" for Location&lt;br /&gt;and they will automatically be added to the right place in VSS&lt;br /&gt;&lt;br /&gt;And that's it.  Basically I change the binding root of the solution from the automatically created "whatever.root" folder to its parent, allowing multiple solutions to live in the same directory and in effect share the same binding root.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115981963364811635?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115981963364811635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115981963364811635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115981963364811635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115981963364811635'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/10/enabling-sane-project-and-solution.html' title='Enabling Sane Project and Solution Structure'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115859018874735693</id><published>2006-09-18T09:22:00.000-05:00</published><updated>2006-09-18T09:38:33.320-05:00</updated><title type='text'>Lightweight Promotable Transactions and Connection Pooling</title><content type='html'>We're moving an existing system from a SQL 2000 backend to SQL 2005.  The system uses a custom persistence framework and System.Transactions.TransactionScope for all transactions.  The framework was developed with the best practices for connection pooling in mind.  Basically, connections are cheap; open them when you need them and close them when you're done.  This results in a connection for each type being fetched during a request.  For example, a Customer with an Address would require 2 connections, one to fetch the Customer and one to fetch the dependent Address.&lt;br /&gt;&lt;br /&gt;When SQL 2005 enters the picture, however, we have a problem.  TransactionScope and SQL 2005 are smart enough to realize that not all transactions are distributed, so they start out as local ADO transactions and are supposed to be seamlessly promoted when necessary.  There are 2 problems we've run into so far.  The first is that it's way too easy to trigger a promotion.  Although I guess it makes sense, opening a second connection to the same data source always triggers a promotion.  The second problem arises if the first connection is busy (say, reading a Customer object from a DataReader) when the second connection is open.  This causes an immediate failure since the first connection is blocked, preventing a promotion.&lt;br /&gt;&lt;br /&gt;Although you can work around the blocked connection problem with a new SQL 2005 feature, Multiple Active Result Sets (MARS), it still seems a bit gross.  I may end up rewriting bits of the persistence framework to properly share a single connection, queuing the objects to be loaded and then working through them rather than having multiple connections with multiple DataReaders going at once.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115859018874735693?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115859018874735693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115859018874735693' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115859018874735693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115859018874735693'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/09/lightweight-promotable-transactions.html' title='Lightweight Promotable Transactions and Connection Pooling'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115742470862980805</id><published>2006-09-04T21:42:00.000-05:00</published><updated>2006-09-04T21:51:48.640-05:00</updated><title type='text'>HttpListenerContext is not serializable</title><content type='html'>Today I started working on my own subclass of HttpWorkerRequest so that my webserver could handle POSTs and binary data like rails.png on the Welcome Aboard page.  After writing all the code to handle the necessary overrides I went to actually run the thing and discovered the troubling fact in my subject line.  HttpListenerContext is not serializable.  Since my host runs in a separate AppDomain, this is a big problem.&lt;br /&gt;&lt;br /&gt;I thought about trying to make some serializable dummy class to shuttle data back and forth, but then I came across Aaron Skonnard's Service Station article in MSDN Magazine &lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/12/ServiceStation/" target="_blank"&gt;here&lt;/a&gt; where he hit the same thing.  His solution was just to move the HttpListener into the host's AppDomain, which is exactly the right thing to do.  After doing that, everything works great.  I successfully served the whole Rails Welcome Aboard page including the png (and the AJAX link for environment info), as well as a few test aspx pages with postbacks.  There are still some rough edges (no default page handling, untested auth, etc.), but I think this is good enough to move on to working with a pool of Ruby processes for handling Rails.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115742470862980805?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115742470862980805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115742470862980805' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115742470862980805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115742470862980805'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/09/httplistenercontext-is-not.html' title='HttpListenerContext is not serializable'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115733433641100064</id><published>2006-09-03T20:33:00.000-05:00</published><updated>2006-09-03T20:45:36.426-05:00</updated><title type='text'>More Http.sys and Rails</title><content type='html'>Magically I found some time to work on my web server for Rails based on Http.sys.  In the interest of having something definitely working, I went down the path of creating a basic CGI server.  Given a virtual directory and a physical path to a Rails public folder, I can now successfully serve pages, with a few caveats.&lt;br /&gt;&lt;br /&gt;One minor thing is that I've only tested a few pages in my first ever Rails app, so I'm sure there are things I've missed.  I haven't attempted to support things like auth or https yet, but those should definitely be possible.&lt;br /&gt;&lt;br /&gt;More importantly, I'm using HttpRuntime.ProcessRequest for serving static content, but I'm only using SimpleWorkerRequest at the moment.  This means binary files as well as POSTs and things don't work.  It looks like I'm going to have to subclass HttpWorkerRequest myself to make things work.  I've looked at the Cassini source for how they do it (and to see if I could just use that), so this shouldn't be too bad.  Not exactly fun though.&lt;br /&gt;&lt;br /&gt;Once I get those things handled I'll move onto a pooled interpreter approach and leave the horrible performance of CGI behind.  Seeing the Rails 'Welcome aboard' page served from my code was nice, even if the images didn't work yet.  Soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115733433641100064?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115733433641100064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115733433641100064' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115733433641100064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115733433641100064'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/09/more-httpsys-and-rails.html' title='More Http.sys and Rails'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115603933577897632</id><published>2006-08-19T20:49:00.000-05:00</published><updated>2006-08-19T21:02:15.790-05:00</updated><title type='text'>FP on the brain</title><content type='html'>I did a presentation for our internal user group about languages other than C# including SML, Scheme, and Ruby.  I was attemping to illustrate functional programming,  code as data, lazy evaluation, and dynamic typing to a group who had mostly only dealt with C#, partly to talk about elements from those sources that LINQ will incorporate and partly just to share my enthusiasm.&lt;br /&gt;&lt;br /&gt;I hadn't touched SML in quite awhile, but it was really easy to pick back up and still was just as much fun to write.  It's powerful, expressive, and has a nice, clean syntax.  It might fit really well in a middle-tier type setting, since that would side step the need for strongly typed database access or a web service toolkit.  I need to investigate SML.NET and F# some more as potential avenues to make this happen.  The OCAML syntax of F# bugs me, but I read a cool paper linked off of &lt;a href="http://lambda-the-ultimate.com"&gt;LtU&lt;/a&gt; about its template/meta-programming capabilities which seemed really promising.&lt;br /&gt;&lt;br /&gt;The more I learn about Ruby, the more I like it as a language, too.  The dynamic typing bit still scares me some (especially after SML), but metaprogramming as a means to eliminate boilerplate junk and also to build internal DSLs is just cool.  The interop with .net story isn't quite there yet, but I bet it will be soon.  For the time being, I'm going to play around with using Ruby to generate C#/XML/WSDL/etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115603933577897632?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115603933577897632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115603933577897632' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115603933577897632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115603933577897632'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/08/fp-on-brain.html' title='FP on the brain'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115504618560089152</id><published>2006-08-08T09:01:00.000-05:00</published><updated>2006-08-08T09:09:45.613-05:00</updated><title type='text'>WF, ASP.NET, and transactions</title><content type='html'>My current project has some pretty simple business logic that seemed like it would be a good fit for WF.  I was looking for a good excuse to try it out for real so I started investigating using it and immediately ran into several key problems.&lt;br /&gt;&lt;br /&gt;The first is that there aren't many samples available relating to using WF with an ASP.NET host.  Some of this is because it's still beta, but the only ASP.NET stuff available is either hopelessly trivial (start a workflow on a button click and then wait for it to finish before returning) or just not analogous to a real situation (no error handling, transactions, etc.).  Additionally, you have to use a manual scheduler as opposed to the default one.  I'm trying to get WF to replace business logic, so it would live in the service layer.  I'd need extra code there to check whether we were running with the manual scheduler or not (in order to call RunWorkflow if necessary), which seems gross.&lt;br /&gt;&lt;br /&gt;The other big issue is that it doesn't seem possible to have workflows participate in a transaction that is initiated by the host.  My scenario involves keeping track of many running instances that all need to be finished and exported at once.  This would involve iterating over each instance, sending it a specific event, and then, once all instances have been notified, running a stored proc (or something) once to do the export.  All of that needs to be in one transaction, but it appears this isn't possible.&lt;br /&gt;&lt;br /&gt;I might have to not use WF for this scenario if I can't find answers to those questions.  I'm also concerned that if there aren't good answers, it may severely limit the applicability of WF.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115504618560089152?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115504618560089152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115504618560089152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115504618560089152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115504618560089152'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/08/wf-aspnet-and-transactions.html' title='WF, ASP.NET, and transactions'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115445969421811012</id><published>2006-08-01T14:02:00.000-05:00</published><updated>2006-08-01T14:14:54.230-05:00</updated><title type='text'>More WinFX WF Beta 2 fun</title><content type='html'>Although I got my installation problems resolved on my laptop, my work machine continued to have problems with Workflow Foundation.  When starting Visual Studio I'd get the following error:&lt;br /&gt;&lt;br /&gt;Package Load Failure&lt;br /&gt;Package 'Microsoft.Workflow.VSDesigner.DesignerPackage, Microsoft.Workflow.VSDesigner, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' has failed to load properly ( GUID = {FD526733-BD72-4F81-BEEC-BEB06E2AF59F} ).&lt;br /&gt;&lt;br /&gt;I found some people who had similar problems that arose from using an incompatible WinFX beta with a pre-release version of Visual Studio, but nothing with RTM.  While tracking down the problem I discovered how to generally troubleshoot Visual Studio package load failures.  If you start Visual Studio from the command line with the "/log" option ("devenv /log"), an xml log file is created in "c:\Documents and Settings\[username]\Application Data\Microsoft\VisualStudio\8.0\" called "ActivityLog.xml".&lt;br /&gt;&lt;br /&gt;Mine showed 1 warning (CheckPackageSignature failed; invalid Package Load Key {FD526733-BD72-4F81-BEEC-BEB06E2AF59F}) and 2 errors (SetSite failed for package [Microsoft.Workflow.VSDesigner.DesignerPackage, Microsoft.Workflow.VSDesigner, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35] and End package load).&lt;br /&gt;&lt;br /&gt;Searching on those GUIDs and more detailed error messages I was able to find someone with a similar problem that resulted from having an old Add In file pointing to a location that no longer existed.  Sure enough, in "C:\Documents and Settings\[username]\Application Data\Microsoft\MSEnvShared\Addins" I had a ".AddIn" file I had created ages ago in a folder that no longer exists.  Once I deleted this file, Visual Studio loaded just fine.&lt;br /&gt;&lt;br /&gt;I have no idea why this seemingly unrelated thing caused WF to fail, but at least it's resolved.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115445969421811012?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115445969421811012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115445969421811012' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115445969421811012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115445969421811012'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/08/more-winfx-wf-beta-2-fun.html' title='More WinFX WF Beta 2 fun'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115350642044437565</id><published>2006-07-21T13:22:00.000-05:00</published><updated>2006-07-21T13:27:00.450-05:00</updated><title type='text'>Quick .NET Web Reference Note</title><content type='html'>Apparently setting the URL property of a web service proxy class resets the Credentials property to the default.  This means that if you're setting both, make sure to set URL and then Credentials.  Intuitively I guess this would make sense if the pattern of use involved reusing the same proxy for calls to identical services in different locations. Given that in reality you usually create the proxy, optionally set properties like URL and Credentials, make some calls, and ditch the proxy, I don't know why that behavior exists.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115350642044437565?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115350642044437565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115350642044437565' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115350642044437565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115350642044437565'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/07/quick-net-web-reference-note.html' title='Quick .NET Web Reference Note'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115310279364787018</id><published>2006-07-16T21:06:00.000-05:00</published><updated>2006-07-16T21:19:53.656-05:00</updated><title type='text'>Http.sys and Rails</title><content type='html'>I made some good progress today on my .Net web server for Rails based on Http.sys.  Ultimately I want it to support a pool of ruby interpretters, URL rewriting, and serving regular files (static and dynamic (aspx)) via http.sys. I already have the basic non-Ruby file serving in place through the magic of HttpRuntime.ProcessRequest.   Right now I'm working on some simple wrapper classes to handle CGI.  Once I have that done, I'll add URL rewriting so I can get Rails running.  The last step is the process pool, so things actually run quickly.&lt;br /&gt;&lt;br /&gt;Initially I'm going to try using a TCP socket as a control channel where the server can signal the child process to begin working and the child can tell the server when it's done.  FastCGI looks like it actually multiplexes control information along with standard input and output over the TCP.  Perhaps there's a good reason for that, but I'm going to start with the server writing to and reading from the child's standard in and out directly, orchestrated by the control channel.&lt;br /&gt;&lt;br /&gt;My goals are both to learn about Rails from a development and solution architecture perspective and to simply the process of getting a production-ready Rails server setup on Windows.  Rails can definitely have a place in a real enterprise architecture, but requiring clients with Windows servers to install and maintain apache (or lighttpd, etc.) in addition to IIS is a big hurdle.  Having something based on http.sys should mitigate a lot of this (unified instrumentation, etc.).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115310279364787018?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115310279364787018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115310279364787018' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115310279364787018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115310279364787018'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/07/httpsys-and-rails.html' title='Http.sys and Rails'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115281198569683923</id><published>2006-07-13T12:28:00.000-05:00</published><updated>2006-07-13T12:33:46.110-05:00</updated><title type='text'>WinFX WF Beta 2 installation problems resolved</title><content type='html'>Over the course of messing with a new version of LINQ and other things, my WinFX Beta 2 install somehow got corrupted.  When I tried to load the Workflow Foundation Designer I got the following error message:&lt;br /&gt;&lt;br /&gt;Method 'ElementRemoved' in type 'TypeProviderHost' from assembly 'Microsoft.Workflow.VSDesigner, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.&lt;br /&gt;&lt;br /&gt;I tried removing everything (Visual Studio Extensions for WF, Orcas CTP, Windows SDK, WinFX Runtime) and reinstalling and the same thing happened.  Finally I was able to find &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=127979&amp;SiteID=1" target="_blank"&gt;this&lt;/a&gt; which solved my problem, even though the original question is about Beta 1.  Basically, if you have 2 versions of EnvDTE80 in the GAC, remove the one with the lower Version (right click-&gt;Properties-&gt;Version tab).&lt;br /&gt;&lt;br /&gt;Now everything is working and I can get back to preparing for my upcoming Devcare presentation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115281198569683923?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115281198569683923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115281198569683923' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115281198569683923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115281198569683923'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/07/winfx-wf-beta-2-installation-problems.html' title='WinFX WF Beta 2 installation problems resolved'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115248829783562641</id><published>2006-07-09T18:27:00.000-05:00</published><updated>2006-07-09T18:38:17.843-05:00</updated><title type='text'>WEBrick Issues</title><content type='html'>I spent several hours today trying to get the most basic Rails site possible running on my laptop and only recently succeeded.  Initially, something prevented remote Ruby Gem installs from working at all (gem install would just hang), so I had to chase down all the gem files and download them manually.  When I finally got all that done, WEBRick just wouldn't respond to requests.  Everything started ok, but when I hit http://localhost:3000/ in my browser I got "Waiting for..." and nothing else.  I eventually had to kill the cmd.exe process to even get WEBrick to exit.&lt;br /&gt;&lt;br /&gt;After lots of running in circles (even attempting to install mongrel which proved difficult since I couldn't find a win32-service.gem &gt;= version 0.5.0 anywhere) I discovered the issue.  A few weeks ago I did a half a day's work for a remote client that required secure VPN access.  I had to install some software that worked with the little key generator they mailed me.  After ruling out all sorts of firewall and connectivity problems I thought of this Juniper Networks stuff they had me install and once I removed it everything worked fine.  Both WEBrick and my remote gem installs functioned perfectly.  Whatever it was doing was enough to mess up Ruby's network code, without bothering my browser or any .NET apps I wrote.&lt;br /&gt;&lt;br /&gt;Very odd.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115248829783562641?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115248829783562641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115248829783562641' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115248829783562641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115248829783562641'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/07/webrick-issues.html' title='WEBrick Issues'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30888820.post-115248729230366100</id><published>2006-07-09T18:18:00.000-05:00</published><updated>2006-07-09T18:23:00.716-05:00</updated><title type='text'>Code Goes Here</title><content type='html'>&lt;pre style="font-family:courier"&gt;&lt;br /&gt;public void Solve()&lt;br /&gt;{&lt;br /&gt;    //code goes here&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30888820-115248729230366100?l=codegoeshere.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codegoeshere.blogspot.com/feeds/115248729230366100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30888820&amp;postID=115248729230366100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115248729230366100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30888820/posts/default/115248729230366100'/><link rel='alternate' type='text/html' href='http://codegoeshere.blogspot.com/2006/07/code-goes-here.html' title='Code Goes Here'/><author><name>Code Monkey</name><uri>http://www.blogger.com/profile/12562549053270419902</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
