<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-35748002</atom:id><lastBuildDate>Sun, 02 Aug 2009 08:29:59 +0000</lastBuildDate><title>Steve's Blog</title><description>Software Development with .Net</description><link>http://srstrong.blogspot.com/</link><managingEditor>noreply@blogger.com (Steve)</managingEditor><generator>Blogger</generator><openSearch:totalResults>38</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/srstrong/DmSo" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-1603510174337092082</guid><pubDate>Thu, 11 Jun 2009 13:55:00 +0000</pubDate><atom:updated>2009-06-11T15:55:05.203+02:00</atom:updated><title>Radio Silence</title><description>&lt;p&gt;For anyone subscribed to this blog (Hi Mum!), you've probably noticed a distinct lack of posts. Lately, I've mainly been posting on my company blog, so if you're interested in my ramblings then I suggest you head over to http://blogs.imeta.co.uk/sstrong and subscribe there. You can also follow me on http://twitter.com/srstrong.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;I may still post occasional things here, but it'll be more personal stuff rather than work or tech related.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-1603510174337092082?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/Pf-3YmFTKk0/radio-silence.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2009/06/radio-silence.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-6341870022452043925</guid><pubDate>Wed, 03 Dec 2008 22:31:00 +0000</pubDate><atom:updated>2008-12-03T23:31:16.975+01:00</atom:updated><title>On Agile</title><description>&lt;p&gt;Following a couple of other posts relating to agile (&lt;a href="http://blogs.imeta.co.uk/TPeplow/archive/2008/11/28/when-should-i-use-agile-methods-on-my-software-project.aspx"&gt;here&lt;/a&gt; &amp;amp; &lt;a href="http://blogs.imeta.co.uk/HHariri/archive/2008/12/03/agile-is-not-chaos.aspx"&gt;here&lt;/a&gt;), I thought I'd give my thoughts on the subject.&amp;#160; &lt;/p&gt;  &lt;p&gt;There are numerous books and posts on the subject of Agile - searching for &amp;quot;Agile Development&amp;quot; on Google gives well over 1 million hits.&amp;#160; As someone who is hugely interested in how to improve software development, I've read a good deal of material on the subject (although, being fair, it would only be a fraction of a percent of those Google hits!).&amp;#160; What I've found very interesting is the number of different opinions as to what Agile means - it's pretty hard to find two books on the subject that agree on a definition of the term.&lt;/p&gt;  &lt;p&gt;One thing that is for sure - Agile (whatever definition you may have) is no silver bullet.&amp;#160; Just being &amp;quot;Agile&amp;quot; does not guarantee success.&amp;#160; It does not guarantee the early delivery of rock-solid software to delirious customers. It does not guarantee that your staff will become highly motivated software ninjas overnight. Given that, what's all the fuss about?&amp;#160; The fuss is that previous software methodologies have got a woeful delivery record.&amp;#160; I'm not going to quote some specific number here, since there are a ton of research articles available which give differing statistics depending on exactly what is defined as failure.&amp;#160; However, the general range is anything from 30% - 85%.&amp;#160; Even if you take the best number there, it's clearly an unacceptable state for a multi-billion dollar industry.&lt;/p&gt;  &lt;p&gt;Given the lack of consistency for what Agile means, and given the proliferation of processes that claim to be Agile (XP, SCRUM, Crystal etc.), what is the best way for you to move forward?&amp;#160; Alas, I don't have a silver bullet here either.&amp;#160; The best I can do is describe the process that I have gone through to get this stuff clear in my head.&lt;/p&gt;  &lt;p&gt;The first step is to clearly understand what the key requirements are for your business.&amp;#160; Ignore software, ignore the process, just focus on what matters to the business.&amp;#160; For me, I came up with a single overriding principal:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;To make a decent, long term, sustainable profit&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I'm guessing that's not particularly contentious - any business for which that isn't a key principal is unlikely to last long.&amp;#160; However on it's own that's not really enough.&amp;#160; So I then pondered what aspects of the business would best support the primary principal.&amp;#160; This gave the following, in no particular order:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;To create solutions that give the customer the solution that he needs, when he needs it, and at a cost he is happy with      &lt;ul&gt;       &lt;li&gt;Happy customers mean repeat business and referrals, which are the best and most profitable form of sales. Plus I'd much rather be working with a customer who's happy rather than one who's not. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;br /&gt;  &lt;ul&gt;   &lt;li&gt;To have control over the costs and timescales for each customer project      &lt;ul&gt;       &lt;li&gt;Not having control means that the customer doesn't know how much he is paying or when he's going to receive the goods.&amp;#160; Given that the software is probably only a part of a bigger project, the timescales in particular are critical - without confidence on delivery dates, how is the customer meant to schedule other aspects of the wider project such as training, marketing, manufacturing etc?&amp;#160; In addition, if we don't know when projects are due to complete it makes it very hard to commit to start dates new customers. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;br /&gt;  &lt;ul&gt;   &lt;li&gt;To have a motivated, skilled team that share the same values      &lt;ul&gt;       &lt;li&gt;Motivated staff take care and pride in their work, which gives rich rewards in terms of the quality of the product.&amp;#160; They also tend to enjoy their work which reduces expensive staff turnover, and just makes the workplace a more enjoyable place to spend what amounts to a significant percentage of your life. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;From this, I could then extract the aspect of Agile from the mass of books that I've read to provide, in effect, the essence.&amp;#160; These are the areas that I consider important, and why:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Accept and embrace change.      &lt;ul&gt;       &lt;li&gt;Anyone who thinks that they can prevent change from occurring during a project of any size is, quite frankly, living on another planet.&amp;#160; Accept that change is &lt;strong&gt;essential&lt;/strong&gt; to enable the software to meet the needs of the customer, and adopt a process that makes change as painless as possible.&amp;#160; The change may be requirements, it may be technical, it may be staffing, but whatever it is, it's &lt;strong&gt;going&lt;/strong&gt; to happen. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Develop in short iterations.      &lt;ul&gt;       &lt;li&gt;There's a load of important things about the iterative approach, so I'll expand on this below. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Don't attempt up-front detailed design      &lt;ul&gt;       &lt;li&gt;Again, there's lots of empirical evidence that this doesn't provide any benefit.&amp;#160; By all means, do up front high-level architectural design - indeed, for the key structural aspects of the project (scalability, security, disaster recovery etc.), this is pretty much essential; getting those wrong or trying to reverse them into an existing code base can be very expensive and not something the &amp;quot;right click / refactor&amp;quot; is going to help with.&amp;#160; But the low level stuff is best done with the compiler. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Make sure that testing is a first class citizen      &lt;ul&gt;       &lt;li&gt;Testing should being as soon as coding begins (indeed, if you want to do TDD, then it starts &lt;em&gt;before&lt;/em&gt; the coding).&amp;#160; As far as possible, make the tests automated so that you can frequently run the full test suite.&amp;#160; It's inevitable (regardless of whether you attempt up-front detailed design or not) that, at times, you'll need to refactor parts of the code base to support new functionality.&amp;#160; At times like this, a large test suite gives a great safety net.&amp;#160; In addition, the tests (if well written) also act as a form of executable (and hence up to date) documentation.&amp;#160; Finally, and most importantly, testing as early as possible tends to promote a testable code base and gets quality in there from day one.&amp;#160; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Empower your team to use their brains.      &lt;ul&gt;       &lt;li&gt;If you've any sense, you spend a lot of time recruiting the very best staff.&amp;#160; Recognize that, and let them shine.&amp;#160; If they are committed to the business, then trust them to make sane choices and don't try to micro-manage tem.&amp;#160; If they're not committed to the business, politely but firmly point them in the direction of the door. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Expanding on iterations, I think the following aspects are essential:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;At the start of an iteration, plan in detail what you are going to achieve.&amp;#160; For that plan to have any teeth, it is essential that changes are &lt;strong&gt;not allowed&lt;/strong&gt; during an iteration.&amp;#160; For this reason, iterations should also not be too long - my experience suggests that between 2 and 4 weeks works well. &lt;/li&gt;    &lt;li&gt;During the iteration planning, ensure that the tasks being worked on are the most important to the project at this moment in time.&amp;#160; Don't do the trivial stuff whilst there are important things to be done (important can either be those items that give most business value, or those items that present the most technical risk) &lt;/li&gt;    &lt;li&gt;At the end of each iteration, deliver demonstrable, working software.&amp;#160; This keeps the team focused and gives a clear view of progress to date.&amp;#160; In addition if, god forbid, you fail to complete all the development tasks you will at least have a system that the customer could take.&amp;#160; And, since you worked in priority order, it should include most of the stuff that the customer considers important.&amp;#160; Telling the customer that you're not finished is never an easy conversation, but &amp;quot;We're not done, we estimate that we're about 80% of the way there, but here's a system in which all of the following function is complete and ready to go&amp;quot; is a much better chat than &amp;quot;We're not done, we estimate that we're about 80% of the way there.&amp;#160; Sorry, but there's nothing you can take yet because until we've done the other 20% nothing will work&amp;quot; &lt;/li&gt;    &lt;li&gt;At the end of each iteration, tasks are either done or not done.&amp;#160; It's notoriously hard to determine how much work is left on a task when it's not yet complete (how often have you heard the phrase &amp;quot;it's 80% done&amp;quot;, only to then find it takes another 100% of the elapsed time so far to finish?).&amp;#160; In addition, done needs to be done.&amp;#160; Code written, all functionality complete, all tests written and passing.&amp;#160; Anything less is &lt;strong&gt;not&lt;/strong&gt; done, and should hence be deferred to a future iteration. &lt;/li&gt;    &lt;li&gt;At the end of each iteration, evaluate what has gone well and what has gone badly.&amp;#160;&amp;#160; Do more of the good things, and make changes to prevent the bad things from happening again.&amp;#160; I have seen a number of teams running iterations who recognize that they are not getting things done as quickly as they need, and whose response is &amp;quot;ok, we recognize that things aren't going well.&amp;#160; We'll try harder in the next iteration&amp;quot;.&amp;#160; Trying harder at something that isn't working is unlikely to yield the results that you want. &lt;/li&gt;    &lt;li&gt;Don't queue up bugs.&amp;#160; The tasks that you've worked on to date are, by definition, the most important ones.&amp;#160; Bugs mean that they are not finished.&amp;#160; Fix the bugs.&amp;#160; If you don't, then at the end of the project you'll have a pile of important stuff that's not done.&amp;#160; The customer is not going to like that. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The key thing that I've observed with well-run iterations is that they tend to surface problems early in the project.&amp;#160; Pain is going to happen (what - you really think that &lt;strong&gt;nothing&lt;/strong&gt; will go wrong?), and Early Pain is considerably more desirable than Late Pain.&amp;#160; Early Pain means that there's time to take corrective action. Late Pain is what kills projects.&lt;/p&gt;  &lt;p&gt;Those are the things that I see as the essence of agile - it's not rocket science, it's just working smarter.&amp;#160; It's understanding that change happens, and making sure that you can handle it.&amp;#160; It's understanding that things go wrong, and making sure that they can be spotted and fixed as early as possible.&amp;#160; It's understanding that you have a hugely talented team, and using them.&amp;#160; It's no silver bullet though.&lt;/p&gt;  &lt;p&gt;What else can I add?&amp;#160; Well, there are a few things that spring to mind:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Requirements - up-front or iteratively? &lt;/li&gt;    &lt;li&gt;Contracts - fixed price or T&amp;amp;M? &lt;/li&gt;    &lt;li&gt;What methodology?&amp;#160; SCRUM?&amp;#160; XP?&amp;#160; Lean? &lt;/li&gt;    &lt;li&gt;We're not Agile, but want to be - how do we change? &lt;/li&gt;    &lt;li&gt;My customer doesn't want Agile - what are my options? &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This has been a pretty long post, so although I've got things to say on those, I'll leave them for another day.&lt;/p&gt;  &lt;p&gt;As a final remark, all of the above is just my opinion.&amp;#160; I've intentionally not put in references to books etc. - for each reference I find that says one thing, I've no doubt you can find a reference that says the opposite.&amp;#160; Such is the nature of our imprecise world.&amp;#160; I hope, however, that this does give some food for thought, and perhaps helps you through your own thought processes around how (or indeed if) to adopt Agile.&lt;/p&gt;  &lt;p&gt;I would certainly appreciate any comments that folk might have...&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-6341870022452043925?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/yiHXrAeTGtU/on-agile.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/12/on-agile.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-7588027454376417200</guid><pubDate>Mon, 10 Nov 2008 10:07:00 +0000</pubDate><atom:updated>2008-11-10T11:10:10.223+01:00</atom:updated><title /><description>&lt;p&gt;This should have been sent last Friday, but other stuff got the better of me. Anyhow, here's last weeks "interesting stuff":&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt; &lt;li&gt;The reason why we have iterations: &lt;a href="http://martinfowler.com/bliki/EarlyPain.html" title="Early Pain"&gt;Early Pain&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;An example of a simple &lt;a href="http://blog.codeslower.com/2008/11/Exploring-Oslo-Using-Mg-to-Define-a-To-Do-Language"&gt;TODO language&lt;/a&gt; implemented in Mg. For those use to parsers, BNFs etc, this will be an easy read. For those that haven't come across such things, it's a nice introduction.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;How &lt;a href="http://www.reghardware.co.uk/2008/11/07/sandisk_extremeffs_dram_buffer/"&gt;SanDisk's ExtremeFFS&lt;/a&gt; works. Bets on how long it is before &lt;a href="http://blogs.imeta.co.uk/jgough/Default.aspx"&gt;Joe&lt;/a&gt; gets one :)&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;br/&gt;&lt;br /&gt; &lt;li&gt;A nice &lt;a href="http://www.wintellect.com/CS/blogs/jrobbins/archive/2008/11/06/pdc-2008-thoughts.aspx"&gt;summary of PDC&lt;/a&gt;. Thanks, John - saves me writing it!&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;br/&gt;&lt;br /&gt; &lt;li&gt;Access to the &lt;a href="http://msdn.microsoft.com/en-us/library/aa363787(VS.85).aspx"&gt;ETW APIs&lt;/a&gt; from .Net using &lt;a href="http://www.wintellect.com/CS/blogs/ahopper/archive/2008/11/09/announcing-ntrace-v1-0.aspx"&gt;NTrace&lt;/a&gt;. Not used it yet, but suspect this is worth keeping an eye on.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;A new &lt;a href="http://blogs.msdn.com/bharry/archive/2008/11/08/oct-08-tfs-power-tools-are-available.aspx"&gt;TFS Power Tools&lt;/a&gt; release. Surprised that &lt;a href="http://www.barackobama.com/index.php"&gt;Obama&lt;/a&gt; got quite so much press coverage considering that this came out the same week.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2008/11/08/code-contracts-and-net-4-0-spec-comes-alive.aspx"&gt;Code Contracts&lt;/a&gt; in C# (well, any .Net language in fact). It's due out with .Net 4.0, but it also looks like it works with VS2008. Getting into the habit of declaring the intent of your code in this way can only be a good thing - it helps out with documentation, static analysis, runtime checks and gives &lt;a href="http://research.microsoft.com/Pex/"&gt;Pex&lt;/a&gt; something to get its teeth into.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;A good &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/11/07/time-to-slow-down-the-oslo-hype.aspx"&gt;reality check&lt;/a&gt; on some of the hype going on about Oslo right now.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;&lt;a href="http://twitter.com/hhariri"&gt;Hadi is twittering&lt;/a&gt;. Hell has also frozen over.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;For those of you with a media center and an iPhone / iPod touch, &lt;a href="http://arstechnica.com/journals/apple.ars/2008/11/07/review-control-your-htpc-with-air-mouse-for-iphone"&gt;this is cool&lt;/a&gt;. I've been running it for a week or so (before this review came out), and although at $6 it's one of the most expensive iPhone apps I've bought, it's a load cheaper than the wireless mouse / keyboard that I would have bought otherwise.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt; &lt;li&gt;Should we put comments in our code? &lt;a href="http://www.nealford.com/"&gt;Neal Ford&lt;/a&gt; has shares his views &lt;a href="http://memeagora.blogspot.com/2008/11/comments-code-smell.html"&gt;here&lt;/a&gt; - not sure I entirely agree with him, but I do respect his opinion and it's hard to refute his reasoning. Some of the comments are pretty decent, so it's worth reading the whole page.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-7588027454376417200?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/8dJOIEcSAHc/weekly-digest-of-interesting-stuff.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/11/weekly-digest-of-interesting-stuff.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-5185643288908773086</guid><pubDate>Fri, 17 Oct 2008 11:54:00 +0000</pubDate><atom:updated>2008-10-17T13:54:01.089+02:00</atom:updated><title>Weekly digest of interesting stuff</title><description>&lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.zdnet.com/microsoft/?p=1631"&gt;News&lt;/a&gt; that the D language that is part of the up-coming &lt;a href="http://www.microsoft.com/soa/products/oslo.aspx"&gt;Oslo&lt;/a&gt; release has been renamed to M.&amp;#160; Wonder what that stands for?       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Silverlight 2 goes RTM.&amp;#160; Various useful links:&amp;#160; &lt;br /&gt;      &lt;ul&gt;       &lt;li&gt;The &lt;a href="http://blogs.msdn.com/somasegar/archive/2008/10/13/silverlight-2-released.aspx"&gt;announcement&lt;/a&gt; from Somesegar &lt;/li&gt;        &lt;li&gt;Information about up-coming &lt;a href="http://blogs.msdn.com/sburke/archive/2008/09/17/control-freak.aspx"&gt;Silverlight controls&lt;/a&gt;. The model for how these are getting released is worth reading - full source on Codeplex under the &lt;a href="http://www.opensource.org/licenses/ms-pl.html"&gt;MS public licence&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;A &lt;a href="http://timheuer.com/blog/archive/2008/10/14/silverlight-2-released-officially.aspx"&gt;whole pile of useful stuff&lt;/a&gt; on what's new, what's changed etc.&amp;#160; &lt;/li&gt;        &lt;li&gt;The release of &lt;a href="http://blogs.msdn.com/somasegar/archive/2008/10/14/silverlight-tools-support-w-expression-blend-2-sp1.aspx"&gt;Expression Blend SP1&lt;/a&gt;           &lt;br /&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.leastprivilege.com/GettingRidOfTheSvcExtensionInIIS.aspx"&gt;Changing extensions&lt;/a&gt; in IIS 7 - the post is about removing the .svc extension, but the method used works for pretty much any type of URL renaming that you want to perform       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;A Channel9 video discussing the &lt;a href="http://channel9.msdn.com/shows/Going+Deep/Erik-Meijer-and-Bart-De-Smet-LINQ-to-Anything/"&gt;provider model in LINQ&lt;/a&gt;.&amp;#160; I've not watched it yet, but &lt;a href="http://research.microsoft.com/~emeijer/"&gt;Erik Meyer&lt;/a&gt; is a smart guy and normally worth watching.&amp;#160; Beware of his shirts though, they are normally pretty shocking!       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Apple released updates to their &lt;a href="http://www.apple.com/macbook/"&gt;MacBook&lt;/a&gt; &amp;amp; &lt;a href="http://www.apple.com/macbookpro/"&gt;MacBook Pro&lt;/a&gt; lines.&amp;#160; These are nice looking machines, and with &lt;a href="http://www.apple.com/macosx/features/bootcamp.html"&gt;bootcamp&lt;/a&gt; they will run Vista just fine.&amp;#160; They aren't the cheapest laptops around, but they do compare reasonably well on price with other manufacturers for similar specs / designs.       &lt;br /&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-5185643288908773086?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/_nZd2wnVEdY/weekly-digest-of-interesting-stuff_17.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/weekly-digest-of-interesting-stuff_17.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-702971754506955638</guid><pubDate>Fri, 17 Oct 2008 10:49:00 +0000</pubDate><atom:updated>2008-10-17T12:49:31.763+02:00</atom:updated><title>Visual Studio Tests and "The location of the file or directory xxx is not trusted"</title><description>&lt;p&gt;If you've ever downloaded stuff from the internet (from XP SP2 onwards), you'll know that the OS marks the file as un-trusted and that to use it you need to right-click, go to properties and click &amp;quot;Unblock&amp;quot;.&amp;#160; If you download a zip and extract it's contents without having unblocked the zip, then you probably also know that every extracted file will also be marked as un-trusted.&amp;#160; &lt;/p&gt;  &lt;p&gt;Referencing a file from an un-trusted source within Visual Studio (for example, adding a reference to the latest library that you've just downloaded) will work just fine, but when you try to run your unit tests they will barf with a &amp;quot;location of the file or directory is not trusted&amp;quot; error.&lt;/p&gt;  &lt;p&gt;The top tip is to remember to unblock the zip file before doing the extract; that way, all the files that you extract will also be unblocked and the world will be a happy place (assuming that none of them have viruses, trojans etc!)&lt;/p&gt;  &lt;p&gt;If you forget, and if you've now got files scattered all over your project such that deleting them and re-extracting is a pain, then here's another option - &lt;a href="http://www.jameskovacs.com/blog/PermaLink.aspx?guid=6985963b-3d85-41ae-bca8-5f9efe2a79c7"&gt;ZoneStripper&lt;/a&gt; is a handy command-line tool that can run recursively over a directory and get rid of the blocks.&amp;#160; Works like a treat.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-702971754506955638?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/Io7KARVvnIw/visual-studio-tests-and-location-of.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/visual-studio-tests-and-location-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-55787614927461516</guid><pubDate>Tue, 14 Oct 2008 13:52:00 +0000</pubDate><atom:updated>2008-10-14T15:52:19.026+02:00</atom:updated><title>Running 32 bit .Net applications on a 64 bit machine</title><description>&lt;p&gt;Just been having a problem trying to get a .Net application running on my 64bit Vista machine.&amp;#160; The app was compiled using the &amp;quot;Any CPU&amp;quot; flag, which means that it can target both 32 or 64 bit machines.&amp;#160; With this flag set, the .Net bootstrap process loads up the appropriate CLR based upon your machine architecture - if you're running a 32 bit OS, then the 32 bit CLR is loaded and the JIT compiler generates 32 bit code.&amp;#160; If you're running a 64 bit OS, then you can guess what happens - 64 bit CLR and 64 bit code.&lt;/p&gt;  &lt;p&gt;For most apps, this is probably exactly the behaviour that you want (although do remember that you need to test on both environments).&amp;#160; If there is a reason why you need to target a specific architecture, then you can change the build settings to force either 32 or 64 bit.&amp;#160; Why would you want to force things?&amp;#160; A good reason would be if you are loading up 32 bit native DLLs for some reason (perhaps your database vendor only ships 32 bit client DLLs, for example).&amp;#160; In this case, quite clearly you need to make sure that your app is also running 32 bit - if not, then when launched on a 64 bit OS, it'll throw a BadImageFormatException at the point that it tries to load the native DLL.&amp;#160; &lt;/p&gt;  &lt;p&gt;That's all fine, but what if you've been given an app that needs to run in 32 bit mode, but was compiled with the &amp;quot;Any CPU&amp;quot; flag?&amp;#160; If you've got the code then you could recompile, but what if that's not an option?&amp;#160; Turns out that there's a handy tool called &lt;a href="http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx"&gt;corflags.exe&lt;/a&gt; which comes with the SDK.&amp;#160; Using this, you can flip the 32 bit flag in the application without requiring access to the source.&amp;#160; For example:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;corflags /32BIT+ /Force TheApplication.exe&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;the /Force flag is needed if the application is strong name signed - if you omit that flag, then it will fail when run against such assemblies.&amp;#160; Obviously, once the bit has been flipped the strong name is no longer valid.&amp;#160; If you've got access to the private key then you can re-sign.&amp;#160; If you don't have the private key and you need to keep the strong name then I'm afraid you're out of luck.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-55787614927461516?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/Nb4zdBoKkW8/running-32-bit-net-applications-on-64.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/running-32-bit-net-applications-on-64.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-1464564699598440063</guid><pubDate>Fri, 10 Oct 2008 09:51:00 +0000</pubDate><atom:updated>2008-10-10T11:51:59.333+02:00</atom:updated><title>Weekly digest of interesting stuff</title><description>&lt;p&gt;I read quite a few blogs and web sites over the course of each week, and thought it might be useful to do a weekly blog on the things that I've found interesting.&amp;#160; If nothing else, it gives me a way of keeping track of things - but hopefully some of you will find it useful as well...&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;The Austrian's now have the &lt;a href="http://news.bbc.co.uk/1/hi/sci/tech/7661311.stm"&gt;first computer network protected by quantum encryption&lt;/a&gt;. This stuff has been in the labs for a while, but this is the first (reported) implementation &amp;quot;in the wild&amp;quot;.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;A largely speculative post, but it's one of the first to discuss the new name from Microsoft: &lt;a href="http://blogs.zdnet.com/microsoft/?p=1626"&gt;Windows Strata&lt;/a&gt;.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2008/10/07/migrating-from-linq-to-sql-to-entity-framework-eager-loading.aspx"&gt;Eager loading&lt;/a&gt; in the Entity Framework, and how it differs from LINQ to SQL.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;New &lt;a href="http://blogs.msdn.com/bharry/archive/2008/10/07/msbuild-extension-pack.aspx"&gt;MSBuild extensions library&lt;/a&gt; released.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://memeagora.blogspot.com/2008/10/library-oriented-programming.html"&gt;&amp;quot;Library Oriented Programming&amp;quot;&lt;/a&gt; - is this what we're all doing now?         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;A list of links that details the new stuff, and the broken stuff, in &lt;a href="http://blogs.msdn.com/dougste/archive/2008/10/07/what-s-in-microsoft-net-framework-3-5-sp1.aspx"&gt;.Net 3.5 SP1&lt;/a&gt;. I know it's been out a while, but it's nice to have one place to refer to :)         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;A &lt;a href="http://www.pluralsight.com/community/blogs/dbox/archive/2008/10/08/talks-i-want-to-see-pdc.aspx"&gt;list of the talks&lt;/a&gt; that Don Box wants to see at PDC.&amp;#160; And if Don's interested, then you probably should be too.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/somasegar/archive/2008/10/06/visual-studio-team-system-2010.aspx"&gt;Some VSTS 2010 features&lt;/a&gt;.&amp;#160; It's a while until we'll see this, so it's nice to see what's coming our way.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;For anyone into encryption,I think you'll find the &lt;a href="http://www.wintellect.com/CS/blogs/jprosise/archive/2008/10/08/pdc-time.aspx"&gt;Silverlight Enigma Machine&lt;/a&gt; kind of cute.         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;I've not watched it myself yet, but any video of &lt;a href="http://channel9.msdn.com/posts/Charles/Anders-Hejlsberg-and-Guy-Steele-Concurrency-and-Language-Design/"&gt;Anders talking about language design&lt;/a&gt; is likely to be worth watching.&amp;#160; If you're into that sort of thing, of course!         &lt;br /&gt;&lt;/li&gt;      &lt;li&gt;A really good article on what makes a &lt;a href="http://www.bluebytesoftware.com/blog/2008/10/02/AFewThoughtsOnTheRoleOfSoftwareArchitects.aspx"&gt;good software architect&lt;/a&gt;.&amp;#160; If you think you are, or think you'd like to be, or work in a team with one, or have the misfortune to be married to one (or, worse, to be married to someone who &lt;em&gt;thinks&lt;/em&gt; they are!), then it's worth a read.         &lt;br /&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-1464564699598440063?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/nNQD5PmbQx8/weekly-digest-of-interesting-stuff.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/weekly-digest-of-interesting-stuff.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-2524303733792558970</guid><pubDate>Fri, 03 Oct 2008 10:47:00 +0000</pubDate><atom:updated>2008-10-03T12:47:38.414+02:00</atom:updated><title>WPF Localization, part II</title><description>&lt;p&gt;Following on from the previous &lt;a href="http://srstrong.blogspot.com/2008/10/wpf-localization.html"&gt;blog&lt;/a&gt;, I'll briefly look here at how to localise strings that you build within your application as opposed to resources that are within the XAML.&amp;#160; There are a variety of options here, but this approach seems pretty simple and plays nicely with the locabaml / csv approach described earlier.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Add a new item to your project, of type Resource Dictionary.&amp;#160; By default, VS will name it Dictionary1.xaml.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Edit the App.xaml file to reference the new resource dictionary.&amp;#160; The markup you'll need is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;Application.Resources&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;ResourceDictionary x:Uid=&amp;quot;ResourceDictionary_1&amp;quot;&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ResourceDictionary x:Uid=&amp;quot;ResourceDictionary_2&amp;quot; Source=&amp;quot;Dictionary1.xaml&amp;quot; /&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;/ResourceDictionary&amp;gt;      &lt;br /&gt;&amp;lt;/Application.Resources&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;&lt;u&gt;Step 3:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Let's now add some code and content.&amp;#160; Assuming that you are using the &amp;quot;app&amp;quot; we built in the previous blog, double click on the button in the designer to add a Click event and the corresponding method in the code behind file.&amp;#160; Within the method, add the following code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;MessageBox.Show((string)Application.Current.FindResource(&amp;quot;buttonMessage&amp;quot;));&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;quot;buttonMessage&amp;quot; is the name of the resource that we want to display - edit the Dictionary1.xaml file to include it:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;ResourceDictionary      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; xmlns=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation""&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/a&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; xmlns:x=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml""&gt;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/a&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; xmlns:system=&amp;quot;clr-namespace:System;assembly=mscorlib&amp;quot;&amp;gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160; &amp;lt;system:String x:Key=&amp;quot;buttonMessage&amp;quot;&amp;gt;Hello World!&amp;lt;/system:String&amp;gt;     &lt;br /&gt;&amp;lt;/ResourceDictionary&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you are running in the default locale (&amp;quot;en-GB&amp;quot; in our previous example), the app should run and you should get a message box with the text &amp;quot;Hello World&amp;quot; when you click the button.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 4:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Back to our friends from before.&amp;#160; Do the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;run &amp;quot;msbuild /t:updateuid&amp;quot; from your project directory&lt;/li&gt;    &lt;li&gt;build the project&lt;/li&gt;    &lt;li&gt;run &amp;quot;locbaml /parse&amp;quot; from your bin\debug directory&lt;/li&gt;    &lt;li&gt;translate the corresponding csv file&lt;/li&gt;    &lt;li&gt;run &amp;quot;locbaml /generate&amp;quot; to build the new resource dll&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;(I've not put in the full command lines here, since they are exactly as in the previous blog).&lt;/p&gt;  &lt;p&gt;Once you've done this, if you switch culture to your new culture, you should find that the message box now displays the translated text.&amp;#160; &lt;/p&gt;  &lt;p&gt;As before, this isn't too invasive on the project - for each string that you handle in code, add a resource to the resource dictionary and use the FindResource() method to retrieve the string.&amp;#160; That's pretty much it.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-2524303733792558970?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/3mcR9NFtAC4/wpf-localization-part-ii.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/wpf-localization-part-ii.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-1551854548390515820</guid><pubDate>Fri, 03 Oct 2008 09:52:00 +0000</pubDate><atom:updated>2008-10-03T11:52:59.201+02:00</atom:updated><title>WPF Localization</title><description>&lt;p&gt;There are a good number of articles out there on how to localize WPF resources, including the &lt;a href="http://msdn.microsoft.com/en-us/library/ms753931.aspx"&gt;main one on MSDN&lt;/a&gt;.&amp;#160; However, they are all quite long-winded and having now gone through all the necessary steps I thought I'd just document exactly what you have to do.&amp;#160; Hopefully this will be of some help to others.&lt;/p&gt;  &lt;p&gt;The support for localization within WPF is actually pretty good, but unfortunately it is not quite as integrated with the IDE as one might like, and does involve some work on the command line.&amp;#160; For all you &amp;quot;point'n'click&amp;quot; warriors, I think the best I can do is to send you &lt;a href="http://www.microsoft.com/enable/training/windowsvista/osk.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Download and compile locbaml.&amp;#160; You can find it &lt;a href="http://msdn.microsoft.com/en-us/library/ms771568.aspx"&gt;here&lt;/a&gt;.&amp;#160; Once you've downloaded and &amp;quot;installed&amp;quot; it, head to the directory you chose and go into the &amp;quot;csharp&amp;quot; folder.&amp;#160; In there, you'll see a csproj file.&amp;#160; Either open that in Visual Studio and build, or run msbuild from the command prompt.&amp;#160; Either way, you'll end up with a nice new locbaml.exe just a couple of seconds later.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Create yourself a new WPF project within Visual Studio, and the close the IDE straight away.&amp;#160; Open up the new .csproj file in your favorite text editor, and add the following property to the first PropertyGroup section:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;UICulture&amp;gt;en-GB&amp;lt;/UICulture&amp;gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;where &amp;quot;en-GB&amp;quot; is the culture that you are developing in.&amp;#160; For a full list of culture codes, head &lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Open up the project again, and open the AssemblyInfo.cs file.&amp;#160; Add the following line to the bottom:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;[assembly: NeutralResourcesLanguage(&amp;quot;en-GB&amp;quot;, UltimateResourceFallbackLocation.Satellite)]&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you build &amp;amp; run now, your app should work just fine.&amp;#160; If you take a peek in the bin\debug directory, you'll notice that VS has created an en-BG directory and popped a new dll in there.&amp;#160; This dll is a satellite assembly containing just the resources for that culture.&amp;#160; &lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 3:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Before localizing, let's add some content to our application. Open up Window1.xaml, and add the following as a child of the Grid element:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;Button&amp;gt;Hello&amp;lt;/Button&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You can look at all of &lt;a href="http://blogs.imeta.co.uk/FMoreno/"&gt;Fran's blogs&lt;/a&gt; for details on how to make it prettier :)&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 4:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Here's where we drop down to the command line.&amp;#160; Spin up a VS Command Prompt, and cd to the directory that contains your project.&amp;#160; Run the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;msbuild /t:updateuid&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This will walk all the XAML in your project and add Uid attributes to pretty much everything.&amp;#160;&amp;#160; It does mess the XAML up a smidge, but that's just how it goes.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 5:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Copy the locbaml.exe that you created in step 1 to the bin/debug directory.&amp;#160; Then run:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;LocBaml.exe /parse en-GB\WpfLocalization.resources.dll&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If all goes well, you should now have a .CSV file containing all the resource information which locbaml has extracted from the default resources dll.&amp;#160; Mine looks something like this:&lt;/p&gt;  &lt;p&gt;WpfLocalization1.g.en-GB.resources:window1.baml,Window_1:WpfLocalization.Window1.$Content,None,True,True,,#Grid_1;    &lt;br /&gt;WpfLocalization1.g.en-GB.resources:window1.baml,Window_1:System.Windows.Window.Title,Title,True,True,,Window1     &lt;br /&gt;WpfLocalization1.g.en-GB.resources:window1.baml,Window_1:System.Windows.FrameworkElement.Height,None,False,True,,300     &lt;br /&gt;WpfLocalization1.g.en-GB.resources:window1.baml,Window_1:System.Windows.FrameworkElement.Width,None,False,True,,300     &lt;br /&gt;WpfLocalization1.g.en-GB.resources:window1.baml,Button_1:System.Windows.Controls.Button.$Content,Button,True,True,,Hello&lt;/p&gt;  &lt;p&gt;The columns in this file are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Baml Name - the name of the compiled XAML stream that is held in the resource dll &lt;/li&gt;    &lt;li&gt;Resource Key - maps back to the Uid attributes that we created in Step 4.&amp;#160; Actually, it's even better than that, since it doesn't just have the content of the element, it also allows for the modification of some of the other properties.&amp;#160; So in the example above, on the element with the Uid of Window_1, I can change the $Content, Title, Height and Width properties. &lt;/li&gt;    &lt;li&gt;Localization Category - A value from the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.localizationcategory.aspx"&gt;LocalizationCategory&lt;/a&gt; enumeration &lt;/li&gt;    &lt;li&gt;Readable: Is the value visible for translation &lt;/li&gt;    &lt;li&gt;Modifiable: Is the value modifiable during the translation &lt;/li&gt;    &lt;li&gt;Comments: Any comments - more on this later &lt;/li&gt;    &lt;li&gt;Value: The value of the property.&amp;#160; This is the chap that needs translating &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;&lt;u&gt;Step 6:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Translate the file.&amp;#160; Can't help you there :)&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 7:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;So you've now got a new version of the CSV file in the new culture (let's say it's es-ES).&amp;#160; From this, we need to build a new satellite assembly.&amp;#160; Drop the file into the bin\debug directory alongside the original, and then run this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;locbaml /generate en-GB\WpfLocalization.resources.dll /trans:WpfLocalization.resources.CSV /out:es-ES /cul:es-ES&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It should be pretty obvious what's happening here - from the information present in the original resource dll, and with the updated values in the CSV, generate a new resource dll in the es-ES directory, for the culture es-ES.&amp;#160; Note that you need to create the output directory first.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Step 8:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;Test it.&amp;#160; Either change your locale in the control panel, or add some code to the constructor of your App class (in App.xaml.cs):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;public App()      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160; CultureInfo ci = new CultureInfo(&amp;quot;es-ES&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160; Thread.CurrentThread.CurrentCulture = ci;       &lt;br /&gt;&amp;#160;&amp;#160; Thread.CurrentThread.CurrentUICulture = ci;       &lt;br /&gt;}&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Note that you do need to do this pretty early on in the application lifecycle; once resource start being read, then you are fixed in whatever locale you were at the time.&amp;#160; You can't use this approach to switch languages dynamically once the app is loaded - if that's a requirement, then I'm afraid you need to head back to google.&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;Conclusion&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;That's it.&amp;#160; It's a bit of an effort first time round, but once you get used to things it's pretty simple.&amp;#160; To summarise:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;You can pretty much develop your WPF app as normal. (just add the UICulture to the .csproj and the NeutralResourceLanguage attribute to AssemblyInfo.cs) &lt;/li&gt;    &lt;li&gt;At suitable points, run &amp;quot;msbuild /t:updateuids&amp;quot; to refresh your Uids, and run &amp;quot;locbaml /parse&amp;quot; to get your latest CSV &lt;/li&gt;    &lt;li&gt;Once translated, run &amp;quot;locbaml /generate&amp;quot; to build a new resource DLL. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;What I like is that it doesn't really impact day-to-day development, and it doesn't require a recompile of the main application to add additional languages.&lt;/p&gt;  &lt;p&gt;I'll do another blog shortly that extends this to include the localization of strings that are used within code (e.g., exception messages etc.)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-1551854548390515820?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/C0JoLGf1vCA/wpf-localization.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/wpf-localization.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-4925382956023597768</guid><pubDate>Wed, 01 Oct 2008 20:18:00 +0000</pubDate><atom:updated>2008-10-01T22:18:34.702+02:00</atom:updated><title>Apple drop iPhone NDA</title><description>&lt;p&gt;It appears that Cupertino does listen to what's going on in the wild...&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.appleinsider.com/articles/08/10/01/apple_drops_iphone_nda_for_released_software.html"&gt;http://www.appleinsider.com/articles/08/10/01/apple_drops_iphone_nda_for_released_software.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It's only for for released software, but considerably better than the previous position.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-4925382956023597768?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/Xrbc53xHkao/apple-drop-iphone-nda.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/apple-drop-iphone-nda.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-6648803438456566045</guid><pubDate>Wed, 01 Oct 2008 07:38:00 +0000</pubDate><atom:updated>2008-10-01T09:38:35.779+02:00</atom:updated><title>There's a new Process Monitor</title><description>&lt;p&gt;It's even had a major version number change - you can get Process Monitor V2.0 &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-6648803438456566045?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/YcBCS2tfrDE/there-new-process-monitor.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/10/there-new-process-monitor.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-576889042442437175</guid><pubDate>Mon, 29 Sep 2008 21:50:00 +0000</pubDate><atom:updated>2008-09-29T23:50:15.449+02:00</atom:updated><title>CompiledQuery and Enumerating Query Results</title><description>&lt;p&gt;More fun with compiled queries, this time when processing the results.&amp;#160; Firstly, the simple non-compiled query:&lt;/p&gt;  &lt;div&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (DataClasses1DataContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataClasses1DataContext())&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   var results = context.Employees.Where(e =&amp;gt; e.EmployeeID == 1);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Number of employees: {0}&amp;quot;&lt;/span&gt;, results.Count());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;First ID: {0}&amp;quot;&lt;/span&gt;, results.First().EmployeeID);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Simple stuff, and it works as you'd expect.&amp;#160; We get both the number of employees and the Id of the first one.&amp;#160; Note that under the covers, SQL gets executed twice.&amp;#160; Perhaps not quite what you'd expect ;)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here's the compiled version:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;var compiledQuery = CompiledQuery.Compile((DataClasses1DataContext context) =&amp;gt; context.Employees.Where(e =&amp;gt; e.EmployeeID == 1));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (DataClasses1DataContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataClasses1DataContext())&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   var results = compiledQuery(context);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Number of employees: {0}&amp;quot;&lt;/span&gt;, results.Count());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;First ID: {0}&amp;quot;&lt;/span&gt;, results.First().EmployeeID);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This one doesn't do what you'd expect. On the second Console.WriteLine(), instead of executing a suitable query, you get an InvalidOperationException saying that &amp;quot;The query results cannot be enumerated more than once&amp;quot;.&amp;#160; It's pretty clear what it means, and the fix is simple - make sure you only enumerate the results once, using something like the ToList() method:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;var results = compiledQuery(context).ToList();&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;With this, you only hit the DB once, and you can then look at the list of results as much as you like.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The difference between the non-compiled and the compiled query is down to how the two different queries are processed.&amp;#160; In the non-compiled version, there's an expression tree floating around, which is lazily evaluated when the results are enumerated.&amp;#160; Because LINQ to SQL has the expression tree available, it can generate different SQL on each hit, so results.Count() generates a &amp;quot;select count(*) ...&amp;quot; statement and results.First() generates a &amp;quot;select top 1 ...&amp;quot; statement.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For compiled queries, the SQL is determined at the point you call CompiledQuery.Compile().&amp;#160; When the results are enumerated the first time, this pre-prepared SQL is executed and the results processed.&amp;#160; Note that since the SQL is already built, the thing that you are doing with the results doesn't influence the SQL.&amp;#160; So the call to &amp;quot;results.Count()&amp;quot; will execute a select of the entire dataset, which will then get enumerated and counted in the client.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Since repeatedly issuing the same SQL is unlikely to be what you want your app to be doing, the designers of LINQ to SQL quite wisely throw an exception if you try to do so.&amp;#160; Instead, you need to stick in the explicit ToList() to make it clear that you understand the behaviour.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;At first glance it seems a shame that you can't just swap normal queries &amp;amp; compiled queries but hopefully you can see that the semantics are quite different between the two, at which point having different client code which respects these differences is more acceptable.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Last point - before you start getting excited about the number of SQL queries that the non-compiled version may be executing, and start scattering ToList() calls everywhere, make sure that you understand the consequences.&amp;#160; For the code above, ToList() is going to be a good thing, but if you consider a scenario where the Where() clause doesn't identity a single entry but instead hits perhaps many thousands of rows, then it may not be so good.&amp;#160; The first time we look at the results, we just want the count which gets mapped to count() in SQL, and on the second time the First() method gets mapped to a TOP 1 clause in the SQL.&amp;#160; Although it would mean two hits on the database, it would likely be far better to do that than to bring back thousands of records for processing in the client.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As with most abstraction layers, LINQ offers a lot of benefits but it cannot be used without considered thought as to what is happening underneath.&amp;#160; I thoroughly recommend that when testing your LINQ queries you have the SQL profiler running so that you can see what's going on.&amp;#160; Also, don't forget the DataContext.Log property which lets you dump the SQL out to a TextWriter.&amp;#160; Using this, it would be quite possible to check within your unit tests that the DB interaction is running the way you expect, and also to spot when changes cause unexpected interactions.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-576889042442437175?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/Shjxhz4DKkQ/compiledquery-and-enumerating-query.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/compiledquery-and-enumerating-query.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-5919658201403459520</guid><pubDate>Mon, 29 Sep 2008 21:17:00 +0000</pubDate><atom:updated>2008-09-29T23:17:44.479+02:00</atom:updated><title>Passing Predicates into Compiled Queries</title><description>&lt;p&gt;I've recently been looking at generating LINQ predicates on the fly in a mapping layer between a set of business domain entities and a set of related, but different, database entities.&amp;#160; One of the problems that I've encountered is to do with the way in which predicates are handled when using CompiledQueries.&lt;/p&gt;  &lt;p&gt;To start off, lets consider the easy non-compiled version.&amp;#160; Here's a method:&lt;/p&gt;  &lt;div&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;// Get an employee by a predicate&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetEmployee(Expression&amp;lt;Func&amp;lt;Employee, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; predicate)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Just perform the select, and output the results&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (DataClasses1DataContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataClasses1DataContext())&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      var results = context.Employees.Where(predicate);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Number of employees: {0}&amp;quot;&lt;/span&gt;, results.Count());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The usage of this is nice and simple, and the sort of thing in LINQ examples all over the web:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;GetEmployee(e =&amp;gt; e.EmployeeID == 1);&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Calling this does exactly what you'd expect.&amp;#160; My next step was to look at how this approach could be used with compiled queries.&amp;#160; I started with a simple method:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;// Get an employee by a predicate, using a compiled expression&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetEmployeeCompiled(Expression&amp;lt;Func&amp;lt;Employee, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; predicate)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Compile the query&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   var compiledQuery =&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      CompiledQuery.Compile((DataClasses1DataContext context) =&amp;gt; context.Employees.Where(predicate));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// and using the compiled query, output the results.  This crashes :(&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (DataClasses1DataContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataClasses1DataContext())&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      var results = compiledQuery(context);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Number of employees: {0}&amp;quot;&lt;/span&gt;, results.Count());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Obviously, this is pointless since it just recompiles the query every time.&amp;#160; But let's ignore that small fact - it should, after all, still work.&amp;#160; Alas, it doesn't.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;At the point where the results are enumerated, it explodes with a &amp;quot;NotSupportedException&amp;quot;.&amp;#160; Specifically, it fails due to an &amp;quot;Unsupported overload used for query operator 'Where'.&amp;quot;.&amp;#160; Looking at the expression tree that is being compiled, in conjunction with some help from Reflector to look at what LINQ is doing under the cover, it can be seen that the issue is down to how the predicate is included in the final query expression.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Remember, the compiler is not generating executable code here, it is just building a lambda expression.&amp;#160; When it sees the parameter to the Where() method, it has little choice but to be &amp;quot;lift&amp;quot; this variable its own class, and it is a property on this lifted class that is passed as a parameter to the Where() method.&amp;#160; Although the non-compiled version handles this just fine, it causes the CompiledQuery object to barf.&amp;#160; This is just the same as any other query that uses a local variable or parameter.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I've experimented with a number of ways of constructing the query that I'm trying to compile, but all ultimately end up with the same problem.&amp;#160; The solution I've found is a little nasty, but it does work.&amp;#160; If I've missed a cleaner way, then I'd love to hear about it!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Anyhow, the solution.&amp;#160; It is based on the fact that it is the act of &amp;quot;passing&amp;quot; the predicate into the Where() method that is the problem.&amp;#160; So the solution is to not pass in the predicate, but instead pass in some dummy predicate.&amp;#160; Then do some expression tree walking to swap out the dummy predicate for the real one.&amp;#160; The code looks like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;// Get an employee by a predicate, using a compiled expression&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetEmployeeCompiled2(Expression&amp;lt;Func&amp;lt;Employee, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; predicate)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Setup the required query, using a dummy predicate (c =&amp;gt; true)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   Expression&amp;lt;Func&amp;lt;DataClasses1DataContext, IEnumerable&amp;lt;Employee&amp;gt;&amp;gt;&amp;gt; compiledExpression =&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      context =&amp;gt; context.Employees.Where(c =&amp;gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Dig out the dummy predicate from the expression tree created above&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   Expression template = ((UnaryExpression)((MethodCallExpression)(compiledExpression.Body)).Arguments[1]).Operand;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Swap out the template for the predicate&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   compiledExpression = (Expression&amp;lt;Func&amp;lt;DataClasses1DataContext, IEnumerable&amp;lt;Employee&amp;gt;&amp;gt;&amp;gt;) &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;                                 ExpressionRewriter.Replace(compiledExpression, template, predicate);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// Compile the query&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   var compiledQuery = CompiledQuery.Compile(compiledExpression);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #008000"&gt;// and using the compiled query, output the results.  This works :)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (DataClasses1DataContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataClasses1DataContext())&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      var results = compiledQuery(context);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Number of employees: {0}&amp;quot;&lt;/span&gt;, results.Count());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So the required query is itself stored as an expression, with a dummy predicate (c =&amp;gt; true) used to get the correct &amp;quot;shape&amp;quot; of tree.&amp;#160; This predicate is then located and the expression tree is rewritten, swapping out the dummy predicate for the real one.&amp;#160; This new query expression then compiles and executes just fine.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For completeness, the ExpressionRewriter class is defined as:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ExpressionRewriter : ExpressionVisitor&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Expression Replace(Expression tree, Expression toReplace, Expression replaceWith)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      ExpressionRewriter rewriter = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ExpressionRewriter(toReplace, replaceWith);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; rewriter.Visit(tree);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; Expression _toReplace;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; Expression _replaceWith;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ExpressionRewriter(Expression toReplace, Expression replaceWith)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      _toReplace = toReplace;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      _replaceWith = replaceWith;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; Expression Visit(Expression exp)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (exp == _toReplace)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _replaceWith;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Visit(exp);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;where the ExpressionVisitor base class can be found on &lt;a href="http://msdn.microsoft.com/en-us/library/bb882521.aspx"&gt;MSDN&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-5919658201403459520?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/JnfQUgJ_XjY/passing-predicates-into-compiled.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/passing-predicates-into-compiled.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-750645371700093292</guid><pubDate>Tue, 23 Sep 2008 12:09:00 +0000</pubDate><atom:updated>2008-09-23T14:09:58.036+02:00</atom:updated><title>Unsafe code without the Unsafe keyword</title><description>&lt;p&gt;I've been playing around with some code lately that uses dynamic method generation fairly extensively.&amp;#160; In the course of doing so, I've written the odd dodgy bit of IL out.&amp;#160; Interestingly, a couple of time I got some very strange results when assigning fields from one object to another - specifically, if I got the types mismatched I just got garbage in the destination rather than some form of Cast exception (which I'd expect the runtime to generate during execution) or Verification exception (which I'd expect when I finally surface my generated method through a call to DynamicMethod.CreateDelegate()).&lt;/p&gt;  &lt;p&gt;Finally had some time today to take a closer look, and the results are very interesting and not at all clear from the documentation.&amp;#160; Specifically, if you create a dynamic method using the following constructor:&lt;/p&gt;  &lt;div&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DynamicMethod(&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name,&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    Type returnType,&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    Type[] parameterTypes,&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    Module m&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;)&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;and pass in &amp;quot;Assembly.GetExecutingAssembly().ManifestModule&amp;quot; for the module, then it appears that all type safety within the generated code is turned off.&amp;#160; i.e., you can pretty much assign anything to anything.&amp;#160; The following code, for example, enables you to dump the memory address of any reference type:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// Return a method that gives the memory address of any object&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; Get_GetAddress_Method()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   DynamicMethod d = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DynamicMethod(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Type[] {&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (Object)},&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;                                       Assembly.GetExecutingAssembly().ManifestModule);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   ILGenerator ilGen = d.GetILGenerator();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   ilGen.Emit(OpCodes.Ldarg_0); &lt;span style="color: #008000"&gt;// Load arg_0 onto the stack (of type object)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   ilGen.Emit(OpCodes.Ret);     &lt;span style="color: #008000"&gt;// And return - note that the return type is an int...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;)d.CreateDelegate(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can use this in the following way:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; getAddress = Get_GetAddress_Method();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; greeting = &lt;span style="color: #006080"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;// Get the address of the &amp;quot;Hello&amp;quot; string&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x = getAddress(greeting);&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;x now contains the memory address of the string &amp;quot;Hello&amp;quot;.&amp;#160; So what?&amp;#160; Well, you can also write a method like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// Return a method that &amp;quot;maps&amp;quot; any type to a particular memory location&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt; Get_ObjectAtAddress_Method&amp;lt;T&amp;gt;()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   DynamicMethod d = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DynamicMethod(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (T), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Type[] {&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)},&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;                                       Assembly.GetExecutingAssembly().ManifestModule);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   ILGenerator ilGen = d.GetILGenerator();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   ilGen.Emit(OpCodes.Ldarg_0);  &lt;span style="color: #008000"&gt;// Load arg_0 onto the stack (of type int)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   ilGen.Emit(OpCodes.Ret);      &lt;span style="color: #008000"&gt;// And return - note that the return type is T&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt;)d.CreateDelegate(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt;));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This chap lets you take any memory address, and &amp;quot;pretend&amp;quot; that an object of type T resides there.&amp;#160; So you can do something like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[]&amp;gt; getData = Get_ObjectAtAddress_Method&amp;lt;&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[]&amp;gt;();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;// Get a byte array on the same location&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] data = getData(x);&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;where x is a memory location that you've acquired previously.&amp;#160; It &lt;em&gt;doesn't matter&lt;/em&gt; if the type that really resides at address x is a byte[] or not.&amp;#160; This basically lets you get access to the whole address space within your AppDomain (and possibly the whole Win32 process) and write whatever you like into it.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This seems plain wrong to me - I haven't specified the &amp;quot;unsafe&amp;quot; keyword anywhere, nor is this code built with the &amp;quot;Allow unsafe code&amp;quot; box checked.&amp;#160; Without jumping through those hoops, I should not be able to write code like this.&amp;#160; I'll concede that this only works in a full trust environment, but it still smells like a very serious hole in the type safety of .Net.&amp;#160; Interestingly, if you use the DynamicMethod constructor that doesn't take a Module parameter, then everything works as you'd expect - you are politely served a VerficationException when you try to compile the method.&amp;#160; According to the docs, the constructor overload that takes a module is only supposed to allow access to internals of the specified module, &lt;strong&gt;not&lt;/strong&gt; to skip type safety.&amp;#160; I wonder if the implementation of DynamicMethod in that scenario is flawed.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Below is a big lump of code - it compiles and shows the issue quite clearly.&amp;#160; I'd be interested in your views on whether this is a bug or &amp;quot;by design&amp;quot;. If the latter, what exactly was the scenario that they were designing for?&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Reflection;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Reflection.Emit;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ConsoleApplication1&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;   &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Get some methods generated...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; getAddress = Get_GetAddress_Method();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[]&amp;gt; getData = Get_ObjectAtAddress_Method&amp;lt;&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[]&amp;gt;();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; greeting = &lt;span style="color: #006080"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Print the greeting&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         Console.WriteLine(greeting);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Get the address of the &amp;quot;Hello&amp;quot; string&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x = getAddress(greeting);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Get a byte array on the same location&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] data = getData(x);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Change some data...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         SetString(&lt;span style="color: #006080"&gt;&amp;quot;Bye!!&amp;quot;&lt;/span&gt;, data);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// And display the greeting again (remember, strings are immutable...)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         Console.WriteLine(greeting);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// And just to show it against other bits of the framework...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         Console.WriteLine(Assembly.GetExecutingAssembly().FullName);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         SetString(&lt;span style="color: #006080"&gt;&amp;quot;Hacked!&amp;quot;&lt;/span&gt;, getData(getAddress(Assembly.GetExecutingAssembly().FullName)));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         Console.WriteLine(Assembly.GetExecutingAssembly().FullName);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// Return a method that gives the memory address of any object&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; Get_GetAddress_Method()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         DynamicMethod d = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DynamicMethod(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Type[] {&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (Object)},&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;                                             Assembly.GetExecutingAssembly().ManifestModule);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         ILGenerator ilGen = d.GetILGenerator();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         ilGen.Emit(OpCodes.Ldarg_0); &lt;span style="color: #008000"&gt;// Load arg_0 onto the stack (of type object)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         ilGen.Emit(OpCodes.Ret);     &lt;span style="color: #008000"&gt;// And return - note that the return type is an int...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;)d.CreateDelegate(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// Return a method that &amp;quot;maps&amp;quot; any type to a particular memory location&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt; Get_ObjectAtAddress_Method&amp;lt;T&amp;gt;()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         DynamicMethod d = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DynamicMethod(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (T), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Type[] {&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)},&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;                                             Assembly.GetExecutingAssembly().ManifestModule);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         ILGenerator ilGen = d.GetILGenerator();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         ilGen.Emit(OpCodes.Ldarg_0);  &lt;span style="color: #008000"&gt;// Load arg_0 onto the stack (of type int)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         ilGen.Emit(OpCodes.Ret);      &lt;span style="color: #008000"&gt;// And return - note that the return type is T&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt;)d.CreateDelegate(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, T&amp;gt;));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// Little helper method to copy a string into a byte[]&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetString(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; requiredString, &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] dest)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         UnicodeEncoding encoder = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UnicodeEncoding();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] requiredBytes = encoder.GetBytes(requiredString);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// Need to do the copy by hand, since Array.Copy bleats&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// about the dimensions of the destination.  No surprise really,&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         &lt;span style="color: #008000"&gt;// since the destination isn't really an array...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; requiredBytes.Length; i++)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;            dest[i] = requiredBytes[i];&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-750645371700093292?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/CYafTlE17zI/unsafe-code-without-unsafe-keyword.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/unsafe-code-without-unsafe-keyword.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-6892125578420371419</guid><pubDate>Mon, 15 Sep 2008 15:59:00 +0000</pubDate><atom:updated>2008-09-15T17:59:20.797+02:00</atom:updated><title>Debugging Services</title><description>&lt;p&gt;We all know the problem - to debug a program (particularly if it's the startup procedures that you need to look at), you simply load the solution in Visual Studio and hit F5.&amp;#160; Except if it's a service.&amp;#160; With a service, you can't just run it but instead it needs to be launched via the Service Control Manager, which makes debugging its startup a real pain.&lt;/p&gt;  &lt;p&gt;The solutions that I've used in the past have either been to have a command line option to enable the process to launch as a regular process as opposed to being control by the SCM, or to have it sleep for a number of seconds when it is launched.&amp;#160; Either of these gives me a route to get a debugger attached before anything &amp;quot;interesting&amp;quot; happens.&amp;#160; But both of these also mean I've got code present that isn't going to be in the live, and I much prefer to be debugging &amp;quot;the real thing&amp;quot; rather than some (albeit close) approximation.&lt;/p&gt;  &lt;p&gt;But there's a third way, which I'd not heard of before - there is a registry setting for &amp;quot;Image File Execution Options&amp;quot; which, amongst other things, allows you to specify that when an app is launched (via CreateProcess(), which covers most scenarios), instead of just firing up the exe it instead runs the required debugger.&amp;#160; Nice :)&lt;/p&gt;  &lt;p&gt;For more details, check out &lt;a href="http://blogs.msdn.com/greggm/archive/2008/09/12/attaching-a-debugger-at-startup.aspx"&gt;this blog&lt;/a&gt; on the subject.&amp;#160; There's also &lt;a href="http://blogs.msdn.com/junfeng/archive/2004/04/28/121871.aspx"&gt;this entry&lt;/a&gt; which describes a few more of the settings that are available.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-6892125578420371419?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/VeIRbwojV3c/debugging-services.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/debugging-services.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-3267357926584615411</guid><pubDate>Mon, 08 Sep 2008 18:56:00 +0000</pubDate><atom:updated>2008-09-08T20:56:14.897+02:00</atom:updated><title>Naming Tests</title><description>&lt;p&gt;Following on from &lt;a href="http://blogs.imeta.co.uk/HHariri/archive/2008/08/28/naming-tests-yet-again.aspx"&gt;Hadi's post&lt;/a&gt;, I found this &lt;a href="http://www.pluralsight.com/community/blogs/starr/archive/2008/09/07/bdd_2D00_test_2D00_naming_2D00_experiment.aspx"&gt;recent blog&lt;/a&gt; on the same topic.&amp;#160; It says pretty much the same thing, and acts as a good re-enforcement to the general point, which is to give your tests good names so that the next chap who looks at the code understands what the code being tested is supposed to do.&amp;#160; It's such a valuable addition to the project documentation.&lt;/p&gt;  &lt;p&gt;Exactly which form you choose isn't really that important, providing that it is both descriptive and consistent.&amp;#160; What do you use for your test names?&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-3267357926584615411?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/dkbpxZX0imQ/naming-tests.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/naming-tests.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-5000203881802607493</guid><pubDate>Thu, 04 Sep 2008 09:24:00 +0000</pubDate><atom:updated>2008-09-04T11:24:09.629+02:00</atom:updated><title>More on the Chrome EULA</title><description>&lt;p&gt;Google obviously read my blog&lt;sup&gt;*&lt;/sup&gt; and caved in without a fight.&amp;#160; Clause 11 in the EULA has now been changed to:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;11. Content license from you&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;11.1 You retain copyright and any other rights you already hold in Content which you submit, post or display on or through, the Services.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Much better.&lt;/p&gt; &lt;sup&gt;*&lt;/sup&gt; Ok, perhaps it wasn't &lt;strong&gt;just&lt;/strong&gt; my blog that did it :)  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-5000203881802607493?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/cjXofofoRWI/more-on-chrome-eula.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/more-on-chrome-eula.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-7582162060780747997</guid><pubDate>Wed, 03 Sep 2008 13:13:00 +0000</pubDate><atom:updated>2008-09-03T15:13:40.931+02:00</atom:updated><title>Chrome EULA</title><description>&lt;p&gt;There's an interesting clause in the &lt;a href="http://www.google.com/chrome/eula.html?hl=en"&gt;EULA&lt;/a&gt; for Chrome:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;11.1 You retain copyright and any other rights you already hold in Content which you submit, post or display on or through, the Services. By submitting, posting or displaying the content you give Google a perpetual, irrevocable, worldwide, royalty-free, and non-exclusive license to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute any Content which you submit, post or display on or through, the Services. This license is for the sole purpose of enabling Google to display, distribute and promote the Services and may be revoked for certain Services as defined in the Additional Terms of those Services.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;where Services is defined as:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;1.1 Your use of Google&amp;#8217;s products, software, services and web sites (referred to collectively as the &amp;#8220;Services&amp;#8221; in this document and excluding any services provided to you by Google under a separate written agreement) is subject to the terms of a legal agreement between you and Google. &amp;#8220;Google&amp;#8221; means Google Inc., whose principal place of business is at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States. This document explains how the agreement is made up, and sets out some of the terms of that agreement&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Chrome is, I believe, a Google product, and so falls into the definition of Services.&amp;#160; Hence, according to the EULA, Google can do pretty much anything with any information that you &amp;quot;submit, post or display&amp;quot;.&amp;#160; I suspect that this is a mistake on their part, and that they've just cut'n'pasted a little to much from the EULA's for some of their other services.&amp;#160; It's certainly at odds with the &lt;a href="http://www.google.com/chrome/intl/en/privacy.html"&gt;privacy policy&lt;/a&gt; for Chrome.&lt;/p&gt;  &lt;p&gt;However, if you're worried about such things, then I'd suggest that you don't use Chrome for anything sensitive.&amp;#160; Note that this licence only applies to the executable installation; if you download the source and build it yourself then you are covered by a regular Open Source licence.&amp;#160; It'll be interesting to see how long it takes them to re-word this...&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-7582162060780747997?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/xdBtbCzuhlY/chrome-eula.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/chrome-eula.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-2156290343226322632</guid><pubDate>Wed, 03 Sep 2008 11:32:00 +0000</pubDate><atom:updated>2008-09-03T13:32:32.827+02:00</atom:updated><title>U.S. Employer Identification Number (EIN)</title><description>&lt;p&gt;Any non-US company that wishes to sell iPhone applications in the US via the AppStore needs to obtain an Employer Identification Number to complete the contract details with Apple.&amp;#160; The Apple site is not particularly helpful with regard to how this is achieved, and simply points you at the &lt;a href="http://www.irs.gov/pub/irs-pdf/fss4.pdf"&gt;IRS Form SS-4&lt;/a&gt; PDF.&amp;#160; You can fill this out and send it off, but my understanding is that if you do so it will be several weeks before you receive your EIN.&amp;#160; &lt;/p&gt;  &lt;p&gt;Alternatively, try dialling this number: +1-215-516-6999 - I just did, and after a few minutes with a very helpful chap I received my EIN. Fast and easy, just how I like it :)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-2156290343226322632?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/kBbXqwzsjUo/us-employer-identification-number-ein.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/us-employer-identification-number-ein.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-5707405118573556128</guid><pubDate>Wed, 03 Sep 2008 08:10:00 +0000</pubDate><atom:updated>2008-09-03T10:10:48.826+02:00</atom:updated><title>Google Chrome</title><description>&lt;p&gt;No doubt this is old news already, but for those that haven't seen it there's a cartoon strip that describes the new google browser &lt;a href="http://www.google.com/googlebooks/chrome/"&gt;here&lt;/a&gt; (although it's an odd format, it's actually quite a good read).&amp;#160; The browser itself is available for download &lt;a href="http://www.google.com/chrome"&gt;here&lt;/a&gt;.&amp;#160; No Mac or Linux support yet, but supposedly that's on the way.&lt;/p&gt;  &lt;p&gt;My first impressions are pretty good - it's seems to be fairly snappy and correctly renders most of the pages that I use.&amp;#160; I like the UI - it's nicely un-cluttered, and having the tabs right at the top seems to work well.&amp;#160; &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-5707405118573556128?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/rF8xFHS1Tnw/google-chrome.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/google-chrome.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-7999301487771707551</guid><pubDate>Tue, 02 Sep 2008 11:17:00 +0000</pubDate><atom:updated>2008-09-02T13:17:44.606+02:00</atom:updated><title>Pseudo-Predicates in Specifications</title><description>&lt;p&gt;Following on from my previous blog entry in which I asserted that I don't normally bother just referencing other people's blog, here's another reference :)&lt;/p&gt;  &lt;p&gt;It's quite a long article, but well written and definitely makes it's point.&amp;#160; To anyone writing specifications, and to anyone reading them (which I think covers just about everyone who's reading this!), it's well worth a read:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2008/08/19/tasty-beverages.aspx"&gt;Tasty Beverages&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It's talking about predicates in the context of security, but I think the lesson is actually broader than that - I don't think it's all that unusual to see pseudo-predicates in pretty much any form of specification, and the danger with them is that the human brain is pretty adept at filling in what it thinks is missing (hence, they can be hard to spot).&amp;#160; Alas, what the brain makes up isn't always what the author of the spec was thinking, leading to the wrong thing being developed.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-7999301487771707551?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/AU6XBOZ9zEM/pseudo-predicates-in-specifications.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/09/pseudo-predicates-in-specifications.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-1028821525942611963</guid><pubDate>Fri, 29 Aug 2008 15:24:00 +0000</pubDate><atom:updated>2008-08-29T17:24:35.732+02:00</atom:updated><title>Enable SSH on ESXi</title><description>&lt;p&gt;Don't normally bother writing blogs that just reference another blog, but this one gem me a while to find, so if only for my own reference I'm copying it here:&lt;/p&gt;  &lt;li&gt;Go to the ESXi console and press alt+F1 &lt;/li&gt;  &lt;li&gt;Type: unsupported &lt;/li&gt;  &lt;li&gt;Enter the root password &lt;/li&gt;  &lt;li&gt;At the prompt type &amp;#8220;vi /etc/inetd.conf&amp;#8221; &lt;/li&gt;  &lt;li&gt;Look for the line that starts with &amp;#8220;#ssh&amp;#8221; (you can search with pressing &amp;#8220;/&amp;#8221;) &lt;/li&gt;  &lt;li&gt;Remove the &amp;#8220;#&amp;#8221; (press the &amp;#8220;x&amp;#8221; if the cursor is on the character) &lt;/li&gt;  &lt;li&gt;Save &amp;#8220;/etc/inetd.conf&amp;#8221; by typing &amp;#8220;:wq!&amp;#8221; &lt;/li&gt;  &lt;li&gt;Restart the management service &amp;#8220;/sbin/services.sh restart&amp;#8221;    &lt;p&gt;Original entry was &lt;a href="http://www.yellow-bricks.com/2008/08/10/howto-esxi-and-ssh/"&gt;here&lt;/a&gt;, nice one :)&lt;/p&gt; &lt;/li&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-1028821525942611963?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/2PHBQzH1spM/enable-ssh-on-esxi.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/08/enable-ssh-on-esxi.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-2454874715963723939</guid><pubDate>Thu, 28 Aug 2008 10:02:00 +0000</pubDate><atom:updated>2008-08-28T12:02:53.520+02:00</atom:updated><title>Targeting .Net 2.0 from VS2008</title><description>&lt;p&gt;Following on from the &lt;a href="http://srstrong.blogspot.com/2008/08/net-35-sp1-changes.html"&gt;previous post&lt;/a&gt; about old assemblies being updated with the latest .Net 3.5 service pack, I thought it also worth mentioning the other gotcha that can happen when targeting old versions of .Net from VS2008.&lt;/p&gt;  &lt;p&gt;If you have a project that is set to target .Net 2.0, VS will dutifully only allow you to add 2.0 assemblies to the project, ensuring that you don't accidentally make use of 3.0 or 3.5 &lt;strong&gt;framework&lt;/strong&gt; features that perhaps aren't installed on the machines of your target audience.&amp;#160; However, VS will still use the latest compiler to compile the code, hence you can make use of 3.0 &lt;strong&gt;language&lt;/strong&gt; features such as var, lambdas etc.&amp;#160; These work, even on a box with just the 2.0 framework installed, because they are all handled via compiler magic - there was no change to the resulting IL to support the new 3.0 language features.&lt;/p&gt;  &lt;p&gt;Now this can either be a good or a bad thing.&amp;#160; Good, because you can start making use of the new language tools without requiring your customer to upgrade anything.&amp;#160; Why bad?&amp;#160; Three reasons I can think of:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;For a big project, switching compilers is not a simple decision.&amp;#160; Your app has all been fully tested, both internally and through man-years of usage in the field, but by switching the compiler, &lt;em&gt;you have (potentially) just changed every line of code&lt;/em&gt;.&amp;#160; The only sane thing to do would be a full regression test of the whole system - who's to say that the new 3.0 compiler doesn't have some bugs in it, or (equally likely, I think), it fixes some bugs that were present in the 2.0 compiler, but which your code unknowingly relied on to function correctly. &lt;/li&gt;    &lt;li&gt;If you start using 3.0 features on your dev machines, don't forget that you'll also need to upgrade your CI build servers.&amp;#160; If they are only building your project, that might be an easy choice.&amp;#160; If they are shared by several teams, that may be more difficult. &lt;/li&gt;    &lt;li&gt;If you ship code to the customer rather than binaries, you need to ensure that your customer is also happy to upgrade from VS2005 to VS2008, otherwise they won't be able to build your code anymore. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;What can you do?&amp;#160; Well, if you're in the &amp;quot;it's a good thing&amp;quot; camp, then just get coding.&amp;#160; If the bad things are important to you, then the bad news is that there's not much you can do on your development machines to help (other than go back to VS2005!).&amp;#160; What you &lt;strong&gt;can&lt;/strong&gt; do is to ensure that on your CI build machines you specify the TargetFramework option to MSBuild.&amp;#160; This forces MSBuild to use the appropriate versions of the compiler and other tools.&amp;#160; See &lt;a href="http://blogs.imeta.co.uk/HHariri/archive/2008/06/16/294.aspx"&gt;this&lt;/a&gt; blog for more details. That way, if a dev uses some 3.0 language feature, it will cause the CI build to fail and hence get spotted nice and quickly. You don't have a CI server?&amp;#160; Shame on you.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-2454874715963723939?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/b3UVDAvnc80/targeting-net-20-from-vs2008.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/08/targeting-net-20-from-vs2008.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-6246725373989110187</guid><pubDate>Wed, 27 Aug 2008 14:09:00 +0000</pubDate><atom:updated>2008-09-03T10:18:13.010+02:00</atom:updated><title /><description>&lt;p&gt;There have been a number of posts about the changes introduced in .Net 3.5 SP1, but this is one I've not seen before.  I'm not sure that the title, "breaking changes" is entirely correct, but it probably got your attention :)&lt;/p&gt;  &lt;p&gt;In .Net 3.0, there was a new class, System.Collections.ObjectModel.ObservableCollection&amp;lt;T&amp;gt; (I'm sure you can guess what it does).  It had two constructors, ObservableCollection&amp;lt;T&amp;gt;() and ObservableCollection&amp;lt;T&amp;gt;(List&amp;lt;T&amp;gt;).  Clearly the guy who wrote it was having a bad day - List&amp;lt;T&amp;gt; as a constructor parameter?  What's all that about?&lt;/p&gt;  &lt;p&gt;This stayed the same in .Net 3.5, but changed with .Net 3.5 SP1.  Now, ObservableCollection&amp;lt;T&amp;gt; has an additional constructor, ObservableCollection&amp;lt;T&amp;gt;(IEnumerable&amp;lt;T&amp;gt;) - i.e., the one that they should have had in the first place instead of List&amp;lt;T&amp;gt;.  All is good in the world.&lt;/p&gt;  &lt;p&gt;Now there's a nice feature in VS2008 whereby you can indicate in the project properties which version of .Net you are building for.  This means that VS makes sane choices as to which assemblies you can reference, meaning that the code you write should run just fine on a machine that's only got old versions of the framework, even if you've got all the latest spanky stuff installed.  (There's another issue to do with the compiler, but I'll cover that in another blog).&lt;/p&gt;  &lt;p&gt;Here's the problem.  If you have .Net 3.5 SP1 installed, and you create a project that targets 3.0, VS will happily only add 3.0 references.  Including the reference to the assembly (WindowsBase, if you care) that contains ObservableCollection&amp;lt;T&amp;gt;.  Which SP1 upgraded. So you can write code that takes advantage of the new constructor, such as:&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Consolas;"&gt;ObservableCollection&amp;lt;int&amp;gt; x = new ObservableCollection&amp;lt;int&amp;gt;(new int[] { 1, 2 });&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;which will compile and run just fine.&lt;/p&gt;  &lt;p&gt;When you finally complete all your coding and have all your tests passing, you pass it to your customer confident in the knowledge that you've done a good job.  He installs and runs the code, and the very first impression he gets of your work is a MethodNotFound exception, since you're calling a constructor that he doesn't have on his machine.&lt;/p&gt;  &lt;p&gt;So what do you do?  There's not much you can do on your development system, other than be careful, which isn't much help.  What you can, and &lt;strong&gt;should,&lt;/strong&gt; do is to make sure that your build server and test environments exactly match the &lt;strong&gt;minimum&lt;/strong&gt; that you expect your code to be running on.  That way, a problem like the one above will get spotted during the development process where it can be easily fixed.  Note that it's probably a good idea to turn off automatic updates on build &amp;amp; test machines, otherwise you'll probably end up getting stuff pushed down that you didn't want.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;[Update]&lt;/p&gt;&lt;p&gt;Just found out that FxCop has a rule to detect and warn on the usage of such methods - see Brad Abrams blog posting on the subject &lt;a href="http://blogs.msdn.com/brada/archive/2008/09/02/vs2008-multitargeting-gets-even-better-with-sp1.aspx"&gt;here&lt;/a&gt;.  That helps no end :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-6246725373989110187?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/_eK2bXNtpZc/net-35-sp1-changes.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/08/net-35-sp1-changes.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-35748002.post-5406317757761544814</guid><pubDate>Mon, 14 Jul 2008 12:53:00 +0000</pubDate><atom:updated>2008-07-14T14:53:59.057+02:00</atom:updated><title>Default Gateway of 0.0.0.0 in Vista</title><description>&lt;p&gt;Strange one just occurred - woke up my machine from sleep, and plugged in the various cables in no particular order.&amp;#160; Everything looked good, except no network access.&amp;#160; Could ping the local network (including the gateway), but nothing outside of that.&amp;#160; Everyone else on the same subnet was seeing external IPs just fine.&amp;#160; &lt;/p&gt;  &lt;p&gt;A quick investigation with IPConfig showed that I had two default gateways, once with the correct address but another with an address of 0.0.0.0.&amp;#160; And it was the one that was first in the list.&lt;/p&gt;  &lt;p&gt;No idea where it came from - Vista does use that address if you are using dial-up networking, but I wasn't (although my mobile was plugged in through USB to charge it, so perhaps it is related in someway).&amp;#160; Anyhow - that was clearly the problem, so it was just a case of getting rid of the rogue gateway address.&lt;/p&gt;  &lt;p&gt;Tried &amp;quot;ipconfig /renew&amp;quot;.&amp;#160; Tried &amp;quot;ipconfig /release&amp;quot; then &amp;quot;ipconfig /renew&amp;quot;.&amp;#160; Tried unplugging network cables, mobile phones etc.&amp;#160; No luck.&amp;#160; Reboot was looking likely.&amp;#160; Last attempt was to use netsh.&amp;#160; Success :)&lt;/p&gt;  &lt;p&gt;For those of you who may get stuck in a similar situation, here's the netsh rune that you need to cast:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;netsh interface ipv4 delete address &amp;quot;Local Area Connection&amp;quot;     &lt;br /&gt;addr=a.b.c.d gateway=0.0.0.0&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;where a.b.c.d is your local IP address.&amp;#160; netsh can do just about anything to your local network config - well worth some exploration if you're *really* bored.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35748002-5406317757761544814?l=srstrong.blogspot.com'/&gt;&lt;/div&gt;</description><link>http://feedproxy.google.com/~r/srstrong/DmSo/~3/pwPxylVXdqs/default-gateway-of-0000-in-vista.html</link><author>noreply@blogger.com (Steve)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total><feedburner:origLink>http://srstrong.blogspot.com/2008/07/default-gateway-of-0000-in-vista.html</feedburner:origLink></item></channel></rss>
