<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-2088695286535567324</id><updated>2013-05-02T19:03:17.715+01:00</updated><category term="VBScript" /><category term="Visual Studio" /><category term="reflection" /><category term="PortableClassLibrary" /><category term="MVC" /><category term="Lamda Expressions" /><category term="SQL" /><category term="JustTrace" /><category term="Deployment" /><category term="Build Error" /><category term="SiteMaps" /><category term="youtube" /><category term="Azure" /><category term="Visual Studio 2010" /><category term="ASP.NET MVC" /><category term="Data Type" /><category term="HTTP Headers" /><category term="chrome" /><category term="ASP.NET" /><category term="Windows Phone" /><category term="Access" /><category term="TDD" /><category term="Multi Threading" /><category term="BuildServer" /><category term="VS2012" /><category term="HTMLHelper" /><category term="Content-Disposition" /><category term="Google SiteMap Generator" /><category term="vs2010" /><category term="DotRAS" /><category term="Windows Azure" /><category term="Yahoo" /><category term="Shims" /><category term="Threading" /><category term="Packt" /><category term="LINQ" /><category term="Book Review" /><category term="Plugin" /><category term="masterclass" /><category term="Script" /><category term="Interupts" /><category term="Image Resizing" /><category term="internet explorer" /><category term="Profiling" /><category term="monotouch" /><category term="Hack Day" /><category term="EntityFramework" /><category term="vs11" /><category term="XML" /><category term="streams" /><category term="IIS" /><category term="Data Migration" /><category term="Google" /><category term="google chrome" /><category term="Import Export" /><category term="VS2008" /><category term="SubVersion" /><category term="C#" /><category term="vimeo" /><category term="Fakes" /><category term="unblock" /><category term="Data" /><category term="Firefox" /><category term="Publish" /><category term="LuceneToLinq" /><category term="nuget" /><category term="Telerik" /><category term="drivers" /><category term="flickr" /><category term="FCKEditor" /><category term="openhackdaylondon" /><category term="Battery" /><category term="Bandwidth" /><category term="SVN" /><category term="DataTypes" /><category term="WIndows 7" /><category term="Tips and Tricks" /><category term="vista" /><category term="CodeFirst" /><category term="Hardware Interupts" /><category term="CodePlex" /><category term="Silverlight" /><category term=".NET" /><category term="Books" /><category term="Excel" /><title type="text">Michael James - Developer</title><subtitle type="html">An Application Developers View on Grasping New Technologies</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://blog.mjjames.co.uk/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default?start-index=26&amp;max-results=25" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Mjjames-WebDeveloper" /><feedburner:info uri="mjjames-webdeveloper" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:emailServiceId>Mjjames-WebDeveloper</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-5175657349146216561</id><published>2012-10-23T22:32:00.000+01:00</published><updated>2012-10-23T22:35:07.836+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JustTrace" /><category scheme="http://www.blogger.com/atom/ns#" term="Profiling" /><category scheme="http://www.blogger.com/atom/ns#" term="Telerik" /><title type="text">Getting all profile happy with JustTrace</title><content type="html">Recently I have been developing a fair size application and so far everything seemed to be "just working" fine. However during testing I noticed a few times the app seemed to stall up. This left me quite unhappy and I knew it was time to relook at some of my "decisions". Initial glances through the code didn't really highlight anything so I thought it about time to profile the application and see what it can find.&lt;br /&gt;&lt;br /&gt;In the past I have used&lt;a href="http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/" target="_blank"&gt; Redgate's Ants Profiler&lt;/a&gt; and an early version of &lt;a href="http://www.telerik.com/products/memory-performance-profiler.aspx" target="_blank"&gt;Telerik's JustTrace.&lt;/a&gt; I decided to give Telerik's JustTrace a go again as I have heard alot about it and wanted to see how it's changed / grown.&lt;br /&gt;&lt;br /&gt;Alas, my initial attempt to use JustTrace ended quite&amp;nbsp;abruptly, I've been developing on Windows 8 and VS2012 exclusively for about 5 months now and sadly JustTrace didn't support IIS8 or IIS Express 8. I was gutted to find this out but a quick chat to the Telerik Dev Team and &lt;a href="http://www.kodefuguru.com/" target="_blank"&gt;Chris Eargle&lt;/a&gt; gave me hope as they advised me the Q3 update was right around the corner, 1 week to be exact, and it brought all the new toys into the game,&lt;br /&gt;&lt;br /&gt;HURRAH!&lt;br /&gt;&lt;br /&gt;So tonight I got it all updated and fired up, and started profiling my app. Profiling is&amp;nbsp;immensely&amp;nbsp;easy to perform, simply enable justtrace in the Telerik menu and hit F5 :) You are asked how you want to profile, i chose to simply [].&lt;br /&gt;&lt;br /&gt;You then simply start using your application like normal and JustTrace sits there observing and recording what it is up too. Once you have spent some testing you can really start digging around. The first thing to notice is the Timeline view, this is showing all the CPU activity whilst running through the application. You want to start looking at where you have some peaks, and in particular extended CPU activity.&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;span style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="339" src="http://2.bp.blogspot.com/-gZFb8QpPwQ4/UIcGesRlcXI/AAAAAAAAAAM/zvptisDukG4/s640/initial-profiling.png" width="640" /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Timeline View&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;By clicking on an area of the timeline you get a larger view where you can highlight a time snapshot to view.&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-3uxoTduulYs/UIcHCMRve9I/AAAAAAAAAAU/jSumzFRZMZw/s1600/show-snapshot.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="172" src="http://2.bp.blogspot.com/-3uxoTduulYs/UIcHCMRve9I/AAAAAAAAAAU/jSumzFRZMZw/s400/show-snapshot.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Show Snapshot&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;You can then look at a ton of options to find your issue, by looking at the call trees across all threads, all methods and even look straight into "hot spots". Hot spots are each threads expensive method in terms of time. In my current snapshot Assembly.Load was very expensive, but this was app startup, not what I was noticing.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-r1fiU5mXpr0/UIcH-upTuTI/AAAAAAAAAAc/rWT2rmoxZtw/s1600/hot-spot-view.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="224" src="http://2.bp.blogspot.com/-r1fiU5mXpr0/UIcH-upTuTI/AAAAAAAAAAc/rWT2rmoxZtw/s640/hot-spot-view.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Hot Spot View&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;By looking at the other peaks I did find where 3 seconds was going, executing queries against the database. Now this could be down to bad queries, but its more likely to be a bad use of Linq with Entity Framework, and not&amp;nbsp;compiling&amp;nbsp;queries etc. However now I know where to look and it only took me 5 - 10 minutes of profiling to find out. Fantastic, stuff and I've not even touched memory profiling !&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-QlZpQTEw0Ps/UIcL1QeuvhI/AAAAAAAAAAs/yaJrRpScBl0/s1600/my-hotspot.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="186" src="http://3.bp.blogspot.com/-QlZpQTEw0Ps/UIcL1QeuvhI/AAAAAAAAAAs/yaJrRpScBl0/s640/my-hotspot.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;My Hot Spot&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;Hopefully I can do before my trial runs out, but so far it looks worthwhile investing in, here's hoping I can get some BizSpark discount ;)&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/hDJyVWL_ZkY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/5175657349146216561/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/10/getting-all-profile-happy-with-justtrace.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/5175657349146216561" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/5175657349146216561" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/hDJyVWL_ZkY/getting-all-profile-happy-with-justtrace.html" title="Getting all profile happy with JustTrace" /><author><name>Michael James</name><uri>http://www.blogger.com/profile/07822072908375574137</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-gZFb8QpPwQ4/UIcGesRlcXI/AAAAAAAAAAM/zvptisDukG4/s72-c/initial-profiling.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/10/getting-all-profile-happy-with-justtrace.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-9087069262653973575</id><published>2012-10-10T21:32:00.000+01:00</published><updated>2012-10-10T21:32:28.318+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Publish" /><category scheme="http://www.blogger.com/atom/ns#" term="VS2012" /><category scheme="http://www.blogger.com/atom/ns#" term="Deployment" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><title type="text">Deploying Non Project Files with Web Deploy</title><content type="html">Deploying Websites and Web Applications has changed massively over the years, I have seen the likes of FTP, Copy &amp;amp; Paste over RDP (why!!) etc but there has always been a degree of, did I copy the correct files, did I miss any, did I upload the correct client config etc.&lt;br /&gt;&lt;br /&gt;Since VS2010 I have been a big fan of always publishing my applications to either a local folder and then upload or directly to the server, depending on the setup. &lt;br /&gt;&lt;br /&gt;One thing I have always struggled with is publishing files that aren't part of my project, and ensuring the correct client config settings are uploaded. Now I'm running VS2012 full time I decided it was time to put to bed these issues and ensure I could use one click, or as near to one as possible, to deploy stage configurations of my applications as well as live.&lt;br /&gt;&lt;br /&gt;VS2012 has tweaked publishing again, it now includes a much fuller publish model, with WebDeploy amongst the usual FTP, FileSystem etc. The Package / Publish process is just an extension of MSBuild, which means you can perform any process / action that you would normally do with MSBuild, this could mean perform&amp;nbsp;minimization&amp;nbsp;/ compression of css / js etc. Other people have written about this,&amp;nbsp;&lt;a href="http://sedodream.com/2011/02/25/HowToCompressCSSJavaScriptBeforePublishpackage.aspx"&gt;http://sedodream.com/2011/02/25/HowToCompressCSSJavaScriptBeforePublishpackage.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;When you deploy MSBuild performs two steps, first of all it bundles all your content into a temporary location and then copies it all to the final location, or compiles a package if that's what you have configured&lt;br /&gt;&lt;br /&gt;What I needed to do was alter the process to pull in some additional files into the temporary location so that they then get published to the final place.&lt;br /&gt;&lt;br /&gt;This is possible by extending the&amp;nbsp;PipelineCollectFilesPhaseDependsOn phase. We can simply add a build target to our file and then run this in the&amp;nbsp;PipelineCollectFilesPhaseDependsOn phase.&lt;br /&gt;&lt;br /&gt;Our Target:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;Target Name="CopyIOCFiles"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;Message Text="Copy IOC Files" Importance="high"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;ItemGroup&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;_CustomFiles Include="$(ProjectDir)\IOC\**\*" /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;FilesForPackagingFromProject &amp;nbsp;Include="%(_CustomFiles.Identity)"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;DestinationRelativePath&amp;gt;bin\%(RecursiveDir)%(Filename)%(Extension)&amp;lt;/DestinationRelativePath&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/FilesForPackagingFromProject&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/ItemGroup&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/Target&amp;gt;&lt;br /&gt;&lt;br /&gt;It's worth noting here that my target could just contain the ItemGroup element however I like to know the target has run so by sticking in a message element we know it's ran by looking at our build output,&lt;br /&gt;&lt;br /&gt;This target is then run in the correct phase via the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;PropertyGroup&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;PipelineCollectFilesPhaseDependsOn&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; CopyIOCFiles;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; $(PipelineCollectFilesPhaseDependsOn);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/PipelineCollectFilesPhaseDependsOn&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/PropertyGroup&amp;gt;&lt;br /&gt;&lt;br /&gt;Hurrah! That's it, actually a lot easier than I thought, when you combine this with web.config transformations on a per configuration basis you really can deploy one application in several configurations in one click.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/uMMXYee3lo4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/9087069262653973575/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/10/deploying-non-project-files-with-web.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/9087069262653973575" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/9087069262653973575" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/uMMXYee3lo4/deploying-non-project-files-with-web.html" title="Deploying Non Project Files with Web Deploy" /><author><name>Michael James</name><uri>http://www.blogger.com/profile/07822072908375574137</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/10/deploying-non-project-files-with-web.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-420099152155719408</id><published>2012-06-10T23:17:00.001+01:00</published><updated>2012-06-10T23:17:22.455+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Fakes" /><category scheme="http://www.blogger.com/atom/ns#" term="VS2012" /><category scheme="http://www.blogger.com/atom/ns#" term="Shims" /><title type="text">Shims Shim Shims</title><content type="html">Tonight I started a small project and I thought I'd take the opportunity to explore the new Microsoft.QualityTools.Testing.Fakes library. In case you don't know this library basically allows you to "easily" mock out those pesky sealed classes within the .Net Framework, I've only used it to do System.IO tonight but it does do more. I have a feeling though System.IO will be used heavily with it.&lt;br /&gt;&lt;br /&gt;What the library allows you to do is to generate a shim version of each sealed class within a dll. So what is a shim?&lt;a href="http://msdn.microsoft.com/en-us/library/hh549176(v=vs.110)" target="_blank"&gt; MSDN&lt;/a&gt; at the moment says the following: &lt;br /&gt;&lt;blockquote class="tr_bq"&gt;Shim types allow detouring of hard-coded dependencies on static or non-overridable methods.&lt;/blockquote&gt;What this means to you and I&amp;nbsp;is you get&amp;nbsp;to create a wrapper type, ShimDirectoryInfo for&amp;nbsp;example, you then set delegates for each method and property&amp;nbsp;that you&amp;nbsp;are going to use on the type and let these return your expected values. When your real code then goes to use the original type, DirectoryInfo in our example, it will automatically use the shimmed methods you have defined. What's clever about this is you can not only pass your shims into code by getting the shims generated instance type but you can also declare an AllInstance implementation which any code that creates your type uses. This is neat as you don't have to then modify existing code to take this types.&lt;br /&gt;&lt;br /&gt;A simple example that isn't playing with System.DateTime.Now ;) A lot of the examples on the net use DateTime.Now as an example of shims but I wanted to show how I started using them for testing code that relies on System.IO. &lt;br /&gt;&lt;br /&gt;I have a simple class LocalStorage that has a constructor that takes a file path. all we do for now in this constructor is check for a null / empty path and whether the directory actually exists, and if it doesn't throw.&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;br /&gt;&amp;nbsp;/// Creates a new local storage class for accessing file and directory information&lt;br /&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;&amp;nbsp;/// &amp;lt;param name="rootPath"&amp;gt;Base path to storage location&amp;lt;/param&amp;gt;&lt;br /&gt;&amp;nbsp;public LocalStorage(string rootPath)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; if(String.IsNullOrWhiteSpace(rootPath)){&lt;br /&gt;&amp;nbsp;&amp;nbsp;throw new ArgumentNullException("rootPath");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!System.IO.Directory.Exists(rootPath))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new IOException("Path does not exist: " + rootPath);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rootPath = new DirectoryInfo(rootPath);&lt;br /&gt;}&lt;/blockquote&gt;Nothing to complicated there but how would we test the directory not existing and returning an exception. Previously I would have done something like pass in a path that "should" never exist however this isn't a particularly elegant way of doing it. So how would shims help.&lt;br /&gt;&lt;br /&gt;Here's my new test:&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;[Fact]&lt;br /&gt;public void NonExistantPathThrowsIOException()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (ShimsContext.Create())&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //use fakes to say the folder doesn't exist without having to actually hit the operating system&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.IO.Fakes.ShimDirectory.ExistsString = (path) =&amp;gt; false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.Throws&amp;lt;System.IO.IOException&amp;gt;(() =&amp;gt; new LocalStorage("m:\\test"));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/blockquote&gt;&lt;br /&gt;To start using Shims after creating&amp;nbsp;the shim types of an assembly, we new up a ShimsContext, ShimsContext.Create(),&amp;nbsp;note how this needs to be in a&amp;nbsp;using statement as it's disposable and for good reason.&amp;nbsp;Shims exist for the lifetime of the&amp;nbsp;appdomain, so if you forget to dispose of your context any shims you have created would be used for all tests until the appdomain was shutdown. Therefore by using a using statement and thus the dispose method you are creating a scope and context.&lt;br /&gt;&lt;br /&gt;Now within our context we get to set a delegate against what we want faking. In this case we want to fake our call to Directory.Exists. As this is a static method we can set this globally. This is done by using the ExistsString delegate on the ShimDirectory class. We can use a lambda here to make this really short and sweet. &lt;br /&gt;&lt;br /&gt;That's it! Now when we run our test our fake method is used when ever Directory.Exists is called, no more dependency on the real filesystem. Nice :)&lt;br /&gt;&lt;br /&gt;Now you can take this quite far and start mocking out further things, GetFiles for example, I want to test that my business logic which trims out specific files that can't be handled by the default GetFiles method. &lt;br /&gt;&lt;br /&gt;What you find with methods which take overloads is that when you go to set the delegate you have to ensure you set the correct one. GetFiles for example has the following delegate methods on ShimDirectoryInfo: GetFiles, GetFilesString, GetFilesStringSearchOption. One for each overload combination. It's worth ensure you check the method signature to ensure you get the correct delegate otherwise you'll end up chasing a bug which doesn't exist in the real code but in your test ;)&lt;br /&gt;&lt;br /&gt;Finally not everything is implemented via shims, there is still stuff missing. I found that ShimFileInfo doesn't provide a way to fake File write times, but it does names etc. It is a step in the right direction though when dealing with "stubborn" code.&lt;br /&gt;&lt;br /&gt;Enjoy&lt;br /&gt;&lt;span style="color: white; font-family: Consolas; font-size: x-small;"&gt;&lt;span style="color: white; font-family: Consolas; font-size: x-small;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: white; font-family: Consolas; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/4VZEkEseHsM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/420099152155719408/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/06/shims-shim-shims.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/420099152155719408" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/420099152155719408" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/4VZEkEseHsM/shims-shim-shims.html" title="Shims Shim Shims" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/06/shims-shim-shims.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2033412109555954934</id><published>2012-05-10T13:32:00.000+01:00</published><updated>2012-05-10T13:32:17.445+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PortableClassLibrary" /><category scheme="http://www.blogger.com/atom/ns#" term="BuildServer" /><category scheme="http://www.blogger.com/atom/ns#" term="vs2010" /><title type="text">Portable Class Library Projects and your Build Server</title><content type="html">Yesterday my build server started failing on a particular project and after a quick look at the log I found that it simply wasn't building the solution. Peculiar as I knew it built fine on several development machines, however I dug into the logs and found the following:&lt;br /&gt;&lt;ul class="compile" id="compileErrorsData" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #151515; display: block; font-size-adjust: none; font-stretch: normal; font: 13px/19px &amp;quot;helvetica neue&amp;quot;, tahoma, arial, sans-serif; letter-spacing: normal; list-style-type: none; margin: 10px 0px 0px; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&amp;nbsp;error&amp;nbsp;MSB4019:&amp;nbsp;The&amp;nbsp;imported&amp;nbsp;project&amp;nbsp;"C:\Program&amp;nbsp;Files&amp;nbsp;(x86)\MSBuild\Microsoft\Portable\v4.0\Microsoft.Portable.CSharp.targets"&amp;nbsp;was&amp;nbsp;not&amp;nbsp;found.&amp;nbsp;Confirm&amp;nbsp;that&amp;nbsp;the&amp;nbsp;path&amp;nbsp;in&amp;nbsp;the&amp;nbsp;&amp;lt;Import&amp;gt;&amp;nbsp;declaration&amp;nbsp;is&amp;nbsp;correct,&amp;nbsp;and&amp;nbsp;that&amp;nbsp;the&amp;nbsp;file&amp;nbsp;exists&amp;nbsp;on&amp;nbsp;disk.&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;li class="compiler-error" style="color: #d00000; display: inline; font-family: Menlo, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; white-space: normal;"&gt;&lt;/li&gt;&lt;/ul&gt;Oh dear, now I know Portable Class Libraries is an add on so I went to MSDN Visual Studio Gallery&amp;nbsp;and &lt;a href="http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/" target="_blank"&gt;got the installer&lt;/a&gt; so that I could chuck it on to the build server.&lt;br /&gt;&lt;br /&gt;However when attempting to install I got a great message saying I needed VS2010 and SP1 installed, obviously for a build server this wasn't going to happen. After a bit of digging on &lt;a href="http://msdn.microsoft.com/en-us/library/gg597391.aspx" target="_blank"&gt;MSDN&lt;/a&gt; I found that the installer actually has a switch that when used just installs the targets for MSBuild.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 13px/normal &amp;quot;Segoe UI&amp;quot;, Verdana, Arial; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;To install the Portable Class Library Tools on a build machine without installing Visual Studio 2010, save the download file (PortableLibraryTools.exe) on your computer, and run the installation program from a Command Prompt window. Include the&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal &amp;quot;Segoe UI&amp;quot;, Verdana, Arial; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="input" style="font-weight: 700;"&gt;/buildmachine&lt;/span&gt;&lt;/span&gt;&lt;span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 13px/normal &amp;quot;Segoe UI&amp;quot;, Verdana, Arial; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;switch on the command line.&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;Simply run the installer with the /BuildMachine switch and everything installs hunky dory.&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;PortableLibraryTools.exe&amp;nbsp; /buildmachine&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;To my great relief the build server started building again and things went back to normal.&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/1sVETn153Mc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2033412109555954934/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/05/portable-class-library-projects-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2033412109555954934" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2033412109555954934" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/1sVETn153Mc/portable-class-library-projects-and.html" title="Portable Class Library Projects and your Build Server" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/05/portable-class-library-projects-and.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-6026334964175970554</id><published>2012-04-12T13:27:00.000+01:00</published><updated>2012-04-12T13:28:27.371+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Import Export" /><category scheme="http://www.blogger.com/atom/ns#" term="Access" /><category scheme="http://www.blogger.com/atom/ns#" term="Excel" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Migration" /><category scheme="http://www.blogger.com/atom/ns#" term="Data" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title type="text">Using the SQL Server Export generating an excel spreadsheet from an access database</title><content type="html">What a wordy title, go read it again, it's crazy but true.&lt;br /&gt;&lt;br /&gt;This post covers generating an Excel spreadsheet from an Access Database but using a SQL Server tool. It's crazy but great and easy!&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-yipFcDFo5yw/T4a_mIJYlaI/AAAAAAAAAZw/swD3gfabmWQ/s1600/Welcome.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-yipFcDFo5yw/T4a_mIJYlaI/AAAAAAAAAZw/swD3gfabmWQ/s200/Welcome.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Welcome!&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;I am assuming you have SQL Server installed and the import export wizard, if you don't have this go get it first before carrying on.&lt;br /&gt;&lt;br /&gt;First up open the Import and Export Data application, note this has to be the x86 edition so if you are running an x64 machine, which I think most dev's are nowadays, ensure you choose the correct edition.&lt;br /&gt;This will give you the welcome screen.&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dEXHRZ-sdAs/T4bA81Ic9sI/AAAAAAAAAZ4/AInicPMeX5c/s1600/Source.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-dEXHRZ-sdAs/T4bA81Ic9sI/AAAAAAAAAZ4/AInicPMeX5c/s200/Source.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Source Screen&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Click next to get the ball rolling, this first screen is where we want to get the data from, in this case access, so use the drop down box to select Microsoft Access. Then provide the path to the database file, you can see my file path was actually on the network and it worked fine.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-RXQ_tf2jaBc/T4bBqN4gGDI/AAAAAAAAAaA/9OgTLEunoqs/s1600/destination.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-RXQ_tf2jaBc/T4bBqN4gGDI/AAAAAAAAAaA/9OgTLEunoqs/s200/destination.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Destination Screen&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Next up the destination, well again Excel is what we want so highlight in the list and provide a path to save too. You can also choose the version of Excel you want the file format to be, lots of options which is great. &lt;br /&gt;&lt;br /&gt;Now upon clicking Next here two things may happen, you might proceed to the data copy screen or your might get an error. On my machine I got an error however on others I did not. The error was: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. (System.Data) &lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-RZz6iqFOSh8/T4bD95zQ0LI/AAAAAAAAAaI/oHNSfY0O_o8/s1600/CopyOrQuery.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-RZz6iqFOSh8/T4bD95zQ0LI/AAAAAAAAAaI/oHNSfY0O_o8/s200/CopyOrQuery.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Copy or Query&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;If you don't have office installed going to &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=13255"&gt;http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=13255&lt;/a&gt;&amp;nbsp;and downloading the 32bit Access Database Engine will fix this however I already has Office 2010 so this wasn't the issue. However if you remember earlier I mentioned about the difference between x86 and x64 well it's back to haunt us, I installed 64bit Office, at the time I thought why not I have 16GB ram, something needs to attempt to use it.... well this meant that only a 64bit provider was registered. I attempted to download the 32bit access database engine but it won't install if you have 64 bit office, which does make sense. So I rolled myself back to 32bit Office, sad but true.&lt;br /&gt;&lt;br /&gt;Any how, with all that sorted you will be at the copy or query screen, if you simply want all your data out of your database in the form it is stored you could use the copy table option. However I wanted to pull data from several tables and output it into a specific format so I chose the query option.&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--WeL50Ph_KM/T4bGYWHiGeI/AAAAAAAAAaY/otCV6h6B3-E/s1600/querywindow-shortquery.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/--WeL50Ph_KM/T4bGYWHiGeI/AAAAAAAAAaY/otCV6h6B3-E/s200/querywindow-shortquery.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;What a query&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;You then get a nice big text box to enter your query, you could be hard core and enter this direct and ensure it parses etc but I'm guessing like most people you would have this query tested in Sql Management Studio and would simply paste it in or use the browse button to point it to a saved query. &lt;br /&gt;&lt;br /&gt;It is worth noting here that I believe there is a bug with this window, if you browse and load a file I was finding that only half of my query was in the window, however if I copy pasted it worked fine.&lt;br /&gt;&lt;br /&gt;The next window asks you to confirm the tables and views to copy, when you are using a custom query there isn't a lot more you can do on this screen so click next again.&lt;br /&gt;&lt;br /&gt;This next screen, Run Package, gives you the option to run the export now or to save it as a package that can be reused or used later. However you can only do this on SQL Server Standard, Enterprise, Developer or Evaluation. If you have SQL Server Express, Web, or Workgroup you can only run it immediately.&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Rnr91O3tW3k/T4bIS16SZbI/AAAAAAAAAag/GJvQKgutmxk/s1600/success.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-Rnr91O3tW3k/T4bIS16SZbI/AAAAAAAAAag/GJvQKgutmxk/s200/success.png" width="194" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Success!&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;When you choose to run the package you get a progress window showing what's happening, what's left etc, very similar to the SQL installation progress screens, however when it's done you should have all green ticks and an excel file with you access data in.&lt;br /&gt;&lt;br /&gt;Cracking stuff, if you haven't before you should take some time looking at the SQL Import and Export tool and DTS more fully, it allows you to import and export data from a vast array of sources into just as many again. I have used it to take old Access DB's and create SQL ones and managing data migrations, it's a tool that should be in every developers belt. We don't need to continually write console or windows form apps for managing data we already have a tool that will do the majority of use cases, we just have to use it and write the queries!&lt;br /&gt;&lt;br /&gt;I hope this helps, I know it saved me a ton of time :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/DKoRA56hHbY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/6026334964175970554/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/04/using-sql-server-export-generating.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6026334964175970554" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6026334964175970554" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/DKoRA56hHbY/using-sql-server-export-generating.html" title="Using the SQL Server Export generating an excel spreadsheet from an access database" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-yipFcDFo5yw/T4a_mIJYlaI/AAAAAAAAAZw/swD3gfabmWQ/s72-c/Welcome.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/04/using-sql-server-export-generating.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8463142900502320171</id><published>2012-03-29T17:11:00.000+01:00</published><updated>2012-03-29T17:13:06.707+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CodeFirst" /><category scheme="http://www.blogger.com/atom/ns#" term="CodePlex" /><category scheme="http://www.blogger.com/atom/ns#" term="LuceneToLinq" /><category scheme="http://www.blogger.com/atom/ns#" term="EntityFramework" /><title type="text">Revisting Linq To Lucene</title><content type="html">Last July I wrote a&lt;a href="http://blog.mjjames.co.uk/2011/07/linq-to-lucene-magic-unicorn-edition.html" target="_blank"&gt; blog post about prototyping getting Entity Framework CodeFirst working with Linq To Lucene&lt;/a&gt;. I hadn't realised it was quite that long ago but alas time flies especially with a baby. &lt;br /&gt;&lt;br /&gt;Anyhow, I never finished the work nor made it "feature" ready or submitted it back to the project, this was partly due to the apparent inactivity. However this week the &lt;a href="http://linqtolucene.codeplex.com/" target="_blank"&gt;Linq To Lucene project&lt;/a&gt; has become quite active, and as I now need to use the implementation I spent a few hours to&amp;nbsp;finish it. This included working out how to get all the tables off of a DbContext, which involved a bit of reflection magic and then writing some tests to ensure it worked at least how the LinqToSql version had done.&lt;br /&gt;&lt;br /&gt;I have now submitted this as a patch, &lt;a href="http://linqtolucene.codeplex.com/SourceControl/list/patches"&gt;http://linqtolucene.codeplex.com/SourceControl/list/patches&lt;/a&gt;&amp;nbsp;- item id 11857, and hope its available in the main trunk soon, enjoy!&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/cL8P9vPCaHE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8463142900502320171/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/03/revisting-lucenetolinq.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8463142900502320171" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8463142900502320171" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/cL8P9vPCaHE/revisting-lucenetolinq.html" title="Revisting Linq To Lucene" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/03/revisting-lucenetolinq.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-6227428435099060881</id><published>2012-03-21T15:28:00.000Z</published><updated>2012-03-21T15:42:02.075Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="vs11" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="nuget" /><category scheme="http://www.blogger.com/atom/ns#" term="vs2010" /><title type="text">Troubleshooting NuGet failing to load</title><content type="html">Today I had the unfortunate circumstance for VS2010 to crash whilst I was working, nothing to big I thought, I've had this happen before.&lt;br /&gt;&lt;br /&gt;I reopened VS went to open my solution and got the following message:&lt;br /&gt;&lt;br /&gt;---------------------------&lt;br /&gt;Microsoft Visual Studio&lt;br /&gt;---------------------------&lt;br /&gt;The 'NuGet.Tools.NuGetPackage, NuGet.Tools, Version=1.6.21215.9133, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' package did not load correctly.&lt;br /&gt;&lt;br /&gt;EEK!&lt;br /&gt;&lt;br /&gt;Nuget is smegged :( I immediately thought to uninstall the extension and then reinstall it, same thing happened :(&lt;br /&gt;&lt;br /&gt;I then, (looking back this was foolish as NuGet is shared), thought I know I just load it in VS11 that will work, it also errored.&lt;br /&gt;&lt;br /&gt;Not cool, the error message however directs you to start VS with logging enabled by using the /log command argument and then to look at the activity log.&amp;nbsp; The activity log is located in your appdata roaming folder, simply stick %appdata%\Microsoft\VisualStudio\10.0\ActivityLog.xml into run or %appdata%\Microsoft\VisualStudio\11.0\ActivityLog.xml dependant on your VS version. This will then load a load of XML with the VS loading activity in it. After a bit of scrolling I came across this:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp;&amp;lt;entry&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;record&amp;gt;505&amp;lt;/record&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;time&amp;gt;2012/03/21 09:49:33.568&amp;lt;/time&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;type&amp;gt;Error&amp;lt;/type&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;source&amp;gt;VisualStudio&amp;lt;/source&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;description&amp;gt;SetSite failed for packageSetSite failed for package&amp;lt;/description&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;guid&amp;gt;{5FCC8577-4FEB-4D04-AD72-D6C629B083CC}&amp;lt;/guid&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;hr&amp;gt;80131500&amp;lt;/hr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;errorinfo&amp;gt;The composition produced a single composition error, with 2 root causes. The root causes are provided below. Review the CompositionException.Errors property for more detailed information.&amp;nbsp;&amp;nbsp;  1) '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1. Resulting in: An exception occurred while trying to create an instance of type 'NuGet.VisualStudio.VsSettings'.&lt;br /&gt;Resulting in: Cannot activate part 'NuGet.VisualStudio.VsSettings'.&lt;br /&gt;Element: NuGet.VisualStudio.VsSettings --&amp;gt;&amp;nbsp; NuGet.VisualStudio.VsSettings --&amp;gt;&amp;nbsp; CachedAssemblyCatalog&lt;br /&gt;Resulting in: Cannot get export 'NuGet.VisualStudio.VsSettings (ContractName="NuGet.ISettings")' from part 'NuGet.VisualStudio.VsSettings'.&lt;br /&gt;Element: NuGet.VisualStudio.VsSettings (ContractName="NuGet.ISettings") --&amp;gt;&amp;nbsp; CachedAssemblyCatalog&lt;br /&gt;.........… rest removed due to length .........&lt;br /&gt;&amp;lt;/errorinfo&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/entry&amp;gt; &lt;/blockquote&gt;The key information here is the invalid character and the NuGet.VisualStudio.VsSettings. This looks like the NuGet.Config is corrupt, the next question is where is it. Turns out this is also in app data %appdata%\nuget\ Once here I opened the file in notepad and found it was empty all bar the Unicode start file character.&lt;br /&gt;&lt;br /&gt;To restore the file you just need to put in the location of package sources NuGet should use, the default is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;packageSources&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add key="NuGet official package source" value="&lt;a href="https://go.microsoft.com/fwlink/?LinkID=230477"&gt;https://go.microsoft.com/fwlink/?LinkID=230477&lt;/a&gt;" /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/packageSources&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;activePackageSource&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add key="NuGet official package source" value="&lt;a href="https://go.microsoft.com/fwlink/?LinkID=230477"&gt;https://go.microsoft.com/fwlink/?LinkID=230477&lt;/a&gt;" /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/activePackageSource&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;/blockquote&gt;Once this was saved I tried running NuGet via the command prompt and got the familiar available commands listing.&lt;br /&gt;&lt;br /&gt;Phew&lt;br /&gt;&lt;br /&gt;A bit of a pain but the experience lead me to learning about the VS activity log which I'm sure will be useful to know in the future. Now time to get back on with my project....&lt;br /&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/x3tv5DfTGUo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/6227428435099060881/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/03/today-i-had-unfortunate-circumstance.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6227428435099060881" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6227428435099060881" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/x3tv5DfTGUo/today-i-had-unfortunate-circumstance.html" title="Troubleshooting NuGet failing to load" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/03/today-i-had-unfortunate-circumstance.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2897015678856736186</id><published>2012-03-13T21:54:00.002Z</published><updated>2012-03-13T22:32:57.982Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="monotouch" /><title type="text">Developing with MonoTouch - Day 1 - Setup</title><content type="html">&lt;span class="Apple-style-span" style="font-size: large;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So recently I have started a company and been working on a rather large project, initial plans were to use Window 7 or Windows 8 tablets for the "mobile" solution however for various reasons the plan has somewhat changed to now use iPads.&lt;br /&gt;&lt;br /&gt;As primarily a .Net developer this was a tough decision but a necessary one. However I often talked about using MonoTouch for doing iOS develop after successfully doing some work with MonoDroid when it was in beta. So this is my solution, use MonoTouch to code as much as possible in C# and then Xcode where necessary.&lt;br /&gt;&lt;br /&gt;I thought it would be a good idea to blog my experiences and any insights I gleam during my first few weeks. I have to admit I have never owned a Mac or an iPad so its all very new, although I have used other peoples.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Stage 1 - Order the kit!&lt;/span&gt;&lt;br /&gt;First things first the kit, as most of my work won't actually be on the iPad application but on Azure services etc I decided that the Mac Mini was the way to go. I opted for the basic model i5 2.3 Ghz with 500Gb hard disk. However I did go buy 8GB ram, it was only an extra £35. Due to my existing office setup I chose to reuse my monitor, keyboard and mouse and simply switch my usb hub connection when I work on the Mac so no additional expense there. I also preordered a "new iPad" I won't dwell too much on that as its standard.&lt;br /&gt;&lt;br /&gt;Next comes software, I purchased MonoTouch from the Xamarin website and then the Apple Dev Licence, all pretty basic. It is worth noting that MonoTouch does have a trial / evaluation edition, you are just limited to only having apps run in the simulator.&lt;br /&gt;&lt;br /&gt;Total setup cost to get going: ~£868&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Stage 2 - Setting up the Mac / Installing Everything&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div style="text-align: right;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/-ssLwRoJv4nI/T1--4fFuBEI/AAAAAAAAAXc/zIuFwe7st9g/s1600/Screen+Shot+2012-03-13+at+15.10.32.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="385" src="http://1.bp.blogspot.com/-ssLwRoJv4nI/T1--4fFuBEI/AAAAAAAAAXc/zIuFwe7st9g/s400/Screen+Shot+2012-03-13+at+15.10.32.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Failure to install&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;So the Mac arrived, its incredibly easy to setup and the packaging is very well designed. The first thing I did was to attempt to get the iOS SDK installed, this is done by installing Xcode. However I immediately hit a road block :(&lt;br /&gt;&lt;br /&gt;I was missing a ton of updates preventing the app from installing, not cool for a new mac :(&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/-Kqk7K3A0sII/T1-_sXOb-rI/AAAAAAAAAXk/DjTsEkneMKI/s1600/Screen+Shot+2012-03-13+at+15.10.44.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="133" src="http://2.bp.blogspot.com/-Kqk7K3A0sII/T1-_sXOb-rI/AAAAAAAAAXk/DjTsEkneMKI/s320/Screen+Shot+2012-03-13+at+15.10.44.png" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Hours Later&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;So I had to then go get the software updates, annoyingly its over 1.6GB ;( This would take time on my home connection let alone my office one which is far from speedy at 2 - 3 Mb :( Eventually this finished time for Xcode...... Oh wait another 1.5Gb ;(&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-t2nYMjXAUZk/T1_AC7yEqiI/AAAAAAAAAXs/XtS9Vge9SxA/s1600/Screen+Shot+2012-03-13+at+21.22.31.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="616" src="http://3.bp.blogspot.com/-t2nYMjXAUZk/T1_AC7yEqiI/AAAAAAAAAXs/XtS9Vge9SxA/s640/Screen+Shot+2012-03-13+at+21.22.31.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Warning this make take longer than 1 tea break...&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Eventually after getting all of this sorted it was time to get MonoTouch installed. I have to say the installer for this was pretty painless, It does have to download and install Mono, MonoDevelop and MonoTouch but it went very quickly and was super simple to finish. In fact apart from the time it took to download everything apps on the Mac are super simple to install now theres the app store. One thing I have taken from this is I can't wait to see the Windows App Store in Windows 8, it's long over due and should hopefully make lives easier for everyone.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I then took the jump and opened up MonoDevelop, I have heard good things about it but have never used it personally.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-p6wK-FC6kRc/T1_A1eiEn5I/AAAAAAAAAX0/gdemKlis290/s1600/Screen+Shot+2012-03-13+at+15.12.01.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="352" src="http://3.bp.blogspot.com/-p6wK-FC6kRc/T1_A1eiEn5I/AAAAAAAAAX0/gdemKlis290/s640/Screen+Shot+2012-03-13+at+15.12.01.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Woohoo! MonoDevelop&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;And there we are. Unfortunately I was hoping to have a good play with MonoDevelop but it took over 7 hours to get all the downloads and install which ate all of my day :( There's always tomorrow .....&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/_h6sMy4dFaU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2897015678856736186/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/03/developing-with-monotouch-day-1-setup.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2897015678856736186" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2897015678856736186" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/_h6sMy4dFaU/developing-with-monotouch-day-1-setup.html" title="Developing with MonoTouch - Day 1 - Setup" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-ssLwRoJv4nI/T1--4fFuBEI/AAAAAAAAAXc/zIuFwe7st9g/s72-c/Screen+Shot+2012-03-13+at+15.10.32.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/03/developing-with-monotouch-day-1-setup.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-6394909017153820486</id><published>2012-02-14T14:39:00.003Z</published><updated>2012-02-14T14:41:34.040Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Azure" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows Azure" /><title type="text">DotNetOpenAuth 4 beta with Windows Azure</title><content type="html">Recently I blogged about using &lt;a href="http://www.dotnetopenauth.net/" target="_blank"&gt;DotNetOpenAuth&lt;/a&gt;, I got it working within my local MVC3 Web Application after fixing the dependency issue however when I came to put it into Windows Azure I was getting a random error when the compute emulator started up.&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;blockquote class="tr_bq"&gt;---------------------------&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;Microsoft Visual Studio&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;---------------------------&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;Windows Azure Tools for Microsoft Visual Studio&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;There was an error attaching the debugger to the IIS worker process for URL 'http://127.255.0.0:82/' for role instance 'deployment16(174).xxxxxxxxxxx_IN_0'. Unable to start debugging on the web server. See help for common configuration errors. Running the web page outside of the debugger may provide further information.&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;Make sure the server is operating correctly. Verify there are no syntax errors in web.config by doing a Debug.Start Without Debugging. You may also want to refer to the ASP.NET and ATL Server debugging topic in the online documentation.&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;br /&gt;Nice! How confusing, the compute process didn't even startup but yet if I run it using the built in webserver all is fine. I knew it had to be related to DotNetOpenAuth as this was the only thing I had changed in my project since the last successful run.&lt;br /&gt;&lt;br /&gt;So I started looking into the issue, now I knew it worked on the local dev server however I realised that it wasn't using IIS7 or IIS7.5 but the built in VS. This doesn't run anywhere near the same as IIS7.x which is what Azure is built upon. So I switched my MVC3 Web Application to use IISExpress, which is a lightweight version of IIS, and fired up the app.&lt;br /&gt;&lt;br /&gt;I instantly got where the error message was:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;h3 style="background-color: white; color: #cc0000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 10px;"&gt; HTTP Error 500.19 - Internal Server Error&lt;/h3&gt;&lt;h4 style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.2em; margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 10px;"&gt; The requested page cannot be accessed because the related configuration data for the page is invalid.&lt;/h4&gt;&lt;/blockquote&gt;&lt;h4 style="background-color: #fff5c4; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.2em; margin-bottom: 5px; margin-left: 0px; margin-right: 0px; margin-top: 10px;"&gt; Config Source:&lt;/h4&gt;&lt;pre style="background-color: #fff5c4; font-size: 1.4em; word-wrap: break-word;"&gt;&lt;code style="font-size: 0.8em; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;    7:   &amp;lt;configSections&amp;gt;&lt;br /&gt;&lt;span class="highlight-code" style="color: #cc0000; font-style: italic;"&gt;    8:     &amp;lt;section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span style="background-color: #fff5c4; font-size: 0.8em; font-weight: bold;"&gt;&amp;nbsp; &amp;nbsp; 9:     &amp;lt;sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This section element wasn't needed, .Net 4 already includes&amp;nbsp;System.Configuration.UriSection within the machine.config This is trying to load the v2 component, which is required for .Net 2 - .Net 3.5.&lt;br /&gt;&lt;br /&gt;So where did it come from? Well the answer lies with NuGet, I had installed DotNetOpenAuth using Nuget&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;Install-Package DotNetOpenAuth -Pre&lt;/blockquote&gt;Which along with the library references updated the web.config. The error here is not checking what .Net version the project is before it updates the web.config with the required sections.&lt;br /&gt;&lt;br /&gt;As this is a prerelease version of DotNetOpenAuth my guess is it will be fixed before release, I'll be raising it as an issue any how.&lt;br /&gt;&lt;br /&gt;Hope this helps.&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/q8voB4yVhVU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/6394909017153820486/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/02/opendotnetauth-4-beta-with-windows.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6394909017153820486" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6394909017153820486" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/q8voB4yVhVU/opendotnetauth-4-beta-with-windows.html" title="DotNetOpenAuth 4 beta with Windows Azure" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/02/opendotnetauth-4-beta-with-windows.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2257648558018798824</id><published>2012-02-13T15:35:00.002Z</published><updated>2012-02-13T15:48:44.728Z</updated><title type="text">Using DotNetOpenAuth and getting "DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult"</title><content type="html">Today I started integrating OpenID into my latest web application. I chose to use the &lt;a href="http://www.dotnetopenauth.net/" target="_blank"&gt;DotNetOpenAuth&lt;/a&gt;&amp;nbsp;library as a helper,&amp;nbsp;it's top and makes Open ID &lt;b&gt;really &lt;/b&gt;easy, supports Web Forms, MVC and even &lt;b&gt;classic&lt;/b&gt;&amp;nbsp;ASP. Anyhow there are many how too guides, including one from my &lt;a href="http://blog.dantup.com/2009/04/using-openid-in-your-aspnet-mvc.html" target="_blank"&gt;good friend Danny Tuppeny&lt;/a&gt;, so when it comes to setting it up I refer you to those.&lt;br /&gt;&lt;br /&gt;However today I found when I was using the&amp;nbsp;AsActionResult extension method my web page would come back blank with just &amp;nbsp;DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult written on screen. For some reason the ToString was being called and returned.&lt;br /&gt;&lt;br /&gt;Commonly it seems that the issue is caused by&lt;a href="http://stackoverflow.com/a/1947814/61093" target="_blank"&gt; not having a binding redirect for older versions of the MVC assembly&lt;/a&gt;&amp;nbsp;however my one was set, but what I did notice was the following:&lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;blockquote class="tr_bq"&gt;&amp;lt;dependentAssembly&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;assemblyIdentity name="DataAnnotationsExtensions" publicKeyToken="358a5681c50fd84c" culture="neutral" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;bindingRedirect oldVersion="0.0.0.0-1.0.1.0" newVersion="1.0.1.0" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependentAssembly&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;dependentAssembly&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&amp;gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/dependentAssembly&amp;gt;&lt;/blockquote&gt;&lt;/blockquote&gt;The &amp;nbsp;DataAnnotationsExtensions also had an assemblyIdentity reference to MVC and this was set to version 2. But I was using MVC 3, so I believe what is happening is that the assembly redirect is looking at the first option and then using the wrong version.&lt;br /&gt;I simply removed this redirect and let the main one be used and everything kicked back in.&lt;br /&gt;A lesson learned :)&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/-HDiUahkAAc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2257648558018798824/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/02/using-dotnetopenauth-and-getting.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2257648558018798824" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2257648558018798824" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/-HDiUahkAAc/using-dotnetopenauth-and-getting.html" title="Using DotNetOpenAuth and getting &quot;DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult&quot;" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/02/using-dotnetopenauth-and-getting.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8883897898356451200</id><published>2012-01-27T10:40:00.001Z</published><updated>2012-01-27T10:40:04.208Z</updated><title type="text">Windows Azure and  type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an Exception</title><content type="html">I've been working on a new product that I'm with Windows Azure and today whilst I came to debug a WCF service within it stumbled apon an error that at first glance doesn't make a whole lot of sence, but with a bit of working backwards turns out is quite simple to fix.&lt;br /&gt;&lt;br /&gt;The scenario: I have a WCF service setup to run in a WorkerRole as part of an Azure solution, pretty simple.&lt;br /&gt;&lt;br /&gt;To enable me to see what was going on clearer with my service i decided to configure my system.diagnostic listeners and added the default AzureLocalStorage listener, which is created automatically for you, to my service model and message logging.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&amp;lt;system.diagnostics&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sharedListeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="AzureLocalStorage" type="ServiceAuthenticationGatewayWorkerRole.AzureLocalStorageTraceListener, ServiceAuthenticationGatewayWorkerRole"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/sharedListeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sources&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;source name="System.ServiceModel" switchValue="Verbose, ActivityTracing"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;listeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="AzureLocalStorage"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/listeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/source&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;source name="System.ServiceModel.MessageLogging" switchValue="Verbose"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;listeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="AzureLocalStorage"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/listeners&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/source&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/sources&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/system.diagnostics&amp;gt;&lt;/blockquote&gt;However upon running the application nothing would happen for around 30 - 60 seconds and then I was greeted with a nice TypeInitializationException.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-P02gHN0mW5c/TyJ7PqNrs-I/AAAAAAAAAW8/GTmK0vWzEcg/s1600/AzureTypeInitializationException.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="84" src="http://2.bp.blogspot.com/-P02gHN0mW5c/TyJ7PqNrs-I/AAAAAAAAAW8/GTmK0vWzEcg/s320/AzureTypeInitializationException.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Viewing the detail of this and the inner exceptions eventually led me to the following message:&lt;br /&gt;{"Could not create xxxxxWorkerRole.AzureLocalStorageTraceListener, xxxxxxxx."}&lt;br /&gt;&lt;br /&gt;So the AzureLocalStorageTraceListener was blowing up on type initialisation, popping open the code you see that the constructor does some work, specifically it gets the log directory of the WCF log file and combines the filename and path etc.&lt;br /&gt;&lt;br /&gt;This looked normal,&amp;nbsp;I put a breakpoint in and stepped through the GetLogDirectory method to find which line threw, my guess would be its where it calls into the RoleEnvironment and gets the local resource. Turns out this is exactly where it threw.&lt;br /&gt;&lt;br /&gt;I had a quick gander at &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.getlocalresource.aspx" target="_blank"&gt;MSDN&lt;/a&gt; and found that you pass the local resource name&amp;nbsp;to the method you want to load. This led me to think that the resource wasn't defined so next up was the storage configuration.&lt;br /&gt;&lt;br /&gt;With Azure you configure local storage per role, to change the settings right click the worker role within the main Azure project, it will be in a folder called roles and open properties. You will then get a screen similar to what I had.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-KTvn_8pysC4/TyJ-bCvdYOI/AAAAAAAAAXE/0Cbkvbj2B0E/s1600/AzureEmptyStorage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="95" src="http://3.bp.blogspot.com/-KTvn_8pysC4/TyJ-bCvdYOI/AAAAAAAAAXE/0Cbkvbj2B0E/s320/AzureEmptyStorage.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;You will note, as I did, considering I thought I had local storage and was accessing it via the key, it wasn't setup within the role properties :(&lt;br /&gt;&lt;br /&gt;Simply using the Add Local Storage button and entering the correct details let the project startup and start logging correctly.&lt;br /&gt;&lt;br /&gt;What I found here is another case where the framework gives you the generic error message and not the exception that was really being thrown, &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironmentexception.aspx" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #960bb4; font-size-adjust: none; font-stretch: normal; font: 13px/18px &amp;quot;Segoe UI&amp;quot;, Verdana, Arial; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;RoleEnvironmentException&lt;/a&gt;&amp;nbsp;which would have made me look at the local storage settings a lot quicker.&lt;br /&gt;&lt;br /&gt;Any way there it is, I hope this helps :)&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/s_ymzAHCbzQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8883897898356451200/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/01/windows-azure-and-type-initializer-for.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8883897898356451200" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8883897898356451200" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/s_ymzAHCbzQ/windows-azure-and-type-initializer-for.html" title="Windows Azure and  type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an Exception" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-P02gHN0mW5c/TyJ7PqNrs-I/AAAAAAAAAW8/GTmK0vWzEcg/s72-c/AzureTypeInitializationException.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/01/windows-azure-and-type-initializer-for.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-5070903227580261065</id><published>2012-01-24T12:54:00.000Z</published><updated>2012-01-24T12:54:04.208Z</updated><title type="text">Tidying up user data for display</title><content type="html">Today I was tidying up a quick WPF application i had built for a client. It simply renders "today's schedule" in a way that is meaningful for them and allows them to view it on multiple screens and print as necessary.&lt;br /&gt;&lt;br /&gt;Development was quick as it only consumed several Google Calendar feeds and based upon my test data worked well.&lt;br /&gt;&lt;br /&gt;However today seeing used in real life made me rethink how i rendered the data, in my test data I entered items &lt;b&gt;how I would enter them&lt;/b&gt;, this is important, I entered them using sentence casing for paragraphs, title casing for titles etc. However due to the way some of the users worked everything was being entered in CAPS :(&lt;br /&gt;&lt;br /&gt;Functionally the app works fine, however for me, and I'm no designer, it looked odd. So I opened the solution again and started to look at ways of improving this. My initial thoughts were to apply some sort of styling, think&amp;nbsp;&lt;span style="background-color: white; font-family: 'courier new'; font-size: 13px;"&gt;text-transform:capitalize;&amp;nbsp;&lt;/span&gt;if you were using CSS, but alas XAML doesn't have this. I then thought I could implement a custom formatter that I could use in the XAML upon databinding, I could have done this, but I chose not too. Although it makes sense to do so, I started thinking about how I will probably end up using the data access / domain code in this project later on in another GUI where I will no doubt have the same problem.&lt;br /&gt;&lt;br /&gt;As a result I wanted to &lt;i&gt;"fix"&lt;/i&gt; this data at the domain level in C#. As soon as you hit the code you know there are many ways of achieving this, you could go down the route of RegEx replacing, iterating through the string looking for .'s or whitespace if you want title case etc and then do some replacing. You could even just specify everything is lowercase, but for me none of these fully fitted what I wanted / effort level I wanted to put in for an issue that only I really had.&lt;br /&gt;&lt;br /&gt;What I really wanted was a ToTitleCase or ToSentanceCase that already exists the framework, I didn't want to go grab extension methods which I'm almost certain there will be many of. A quick bit of poking around led me to this gem.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;TextInfo.ToTitleCase&lt;/blockquote&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx" target="_blank"&gt;I refer to MSDN&lt;/a&gt;&amp;nbsp;the ToTitleCase&amp;nbsp;method "Converts the specified string to titlecase." Great, exactly what I wanted. It's easy to use too:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;// Defines the string with mixed casing.&lt;br /&gt;      string myString = "wAr aNd pEaCe";&lt;br /&gt;&lt;br /&gt;      // Creates a TextInfo based on the British culture.&lt;br /&gt;      TextInfo myTI = new CultureInfo("en-GB",false).TextInfo;&lt;br /&gt;&lt;br /&gt;      // Changes a string to titlecase.&lt;br /&gt;      Console.WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase( myString ) );&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Fantastic, build, run, enjoy.....&lt;br /&gt;Well kinda.... This is one method you really do need to read the remarks for &lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx" target="_blank"&gt;on the MSDN page&lt;/a&gt;, &lt;br /&gt;&lt;blockquote class="tr_bq"&gt;this method does not currently provide proper casing to convert a word that is entirely uppercase, such as an acronym.&lt;/blockquote&gt;and&lt;br /&gt;&lt;blockquote class="tr_bq"&gt; the ToTitleCase method provides an arbitrary casing behavior which is not necessarily linguistically correct. A linguistically correct solution would require additional rules, and the current algorithm is somewhat simpler and faster. We reserve the right to make this API slower in the future.&lt;/blockquote&gt;&lt;br /&gt;This actually meant that in my case, when people added descriptions entirely in uppercase the method did nothing. Bit of a shame, I made the conscious decision that Titles I would use ToTitleCase in the hope to improve titles where people enter one with all lower case or mix use, but if they use entirely uppercase then I am unfortunate. However for descriptions I decided to lowercase the string and then use ToTitleCase. Now this isn't sentence casing but it does look better than all caps. This is a compromise, I was able to improve the app without spending too much time on it.&lt;br /&gt;&lt;br /&gt;ToTitleCase is one of those hidden gems, (just like using XmlConvert.ToString with a DateTime will give you the DateTime in RFC 3339 which is fantastic for use with Google Calendar API's etc... but that's a blog post for another day ... ), which can save you time and provide quick wins, it's also culture sensitive which can really help you out if you have a&amp;nbsp;globalised&amp;nbsp;project, just be clear on what it does and what it doesn't do.&lt;br /&gt;&lt;br /&gt;Enjoy&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/K-cja9uo1ms" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/5070903227580261065/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/01/tidying-up-user-data-for-display.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/5070903227580261065" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/5070903227580261065" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/K-cja9uo1ms/tidying-up-user-data-for-display.html" title="Tidying up user data for display" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/01/tidying-up-user-data-for-display.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-6492627802917597867</id><published>2012-01-16T17:21:00.002Z</published><updated>2012-01-16T17:21:38.903Z</updated><title type="text">Tricky times using the MVC3 Date Validator and JQuery UI DatePicker</title><content type="html">Today I came across a strange problem whilst seemingly writing a simple MVC3 prototype. My prototype had a textbox for a date value which I then used jQuery UI to append a date picker too. I was also using unobtrusive validation and data annotations on my models to seemingly "speed up" developing my prototype.&lt;br /&gt;&lt;br /&gt;Although I thought I had wrote everything correctly whenever I tried to submit my form in Chrome I was getting a random error:&amp;nbsp;&lt;span style="background-color: white; color: red; font-family: 'Trebuchet MS', Verdana, Helvetica, sans-serif; font-size: 14px;"&gt;Please enter a valid date. &lt;/span&gt; Originally I had suspected I had messed up the date time formatting, as I was using en-GB format, not the default en-US. Much time wasted and many things I tried had no effect.&lt;br /&gt;&lt;br /&gt;I then by chance loaded the page in Internet Explorer only to find the issue had "vanished", so I went back to Chrome and nope it was back. Upon double checking my code I pondered if using the classname of "date" on my element could cause problems and a bit of Googling confirmed this. In short don't apply a date picker to an element with a class name of "date" otherwise Chrome gets all confused. I believe this is due to the page being HTML5 and the way Chrome parses elements etc, but for now I don't need to know too much about that ;)&lt;br /&gt;&lt;br /&gt;Hurrah everything works again and only x amount of time wasted :(&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/UeNoyOMwa4c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/6492627802917597867/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2012/01/tricky-times-using-mvc3-date-validator.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6492627802917597867" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/6492627802917597867" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/UeNoyOMwa4c/tricky-times-using-mvc3-date-validator.html" title="Tricky times using the MVC3 Date Validator and JQuery UI DatePicker" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2012/01/tricky-times-using-mvc3-date-validator.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3332808871596753148</id><published>2011-12-02T08:08:00.001Z</published><updated>2011-12-10T23:36:48.697Z</updated><title type="text">Resharper 6.1 EAP throws an exception upon load</title><content type="html">Last night I updated my ReSharper 6.1 EAP extension within VS 11 Developer Preview, I was several builds behind and thought it best to try and stay in sync.&lt;br /&gt;&lt;br /&gt;Updating is easy enough, however upon restarting Visual Studio I was finding Resharper was throwing exceptions on load and wanted to send information about them "home".&lt;br /&gt;&lt;br /&gt;I decided to look at the "detailed information" that shows the stack trace and found the following:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;Could not load file or assembly 'JetBrains.ReSharper.UnitTestFramework, Version=6.1.13.115&lt;/blockquote&gt;&lt;br /&gt;It turns out that this was happening in the xunit contrib plugin I had loading for Resharper so I could run my XUnit tests within its runner.&lt;br /&gt;&lt;br /&gt;For now I rolled back by Resharper version until I get chance to either get the source for XUnit Contrib and fix the issue or someone else does it for me :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/t4BkHQsA7ms" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3332808871596753148/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/12/resharper-61-eap-throws-exception-upon.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3332808871596753148" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3332808871596753148" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/t4BkHQsA7ms/resharper-61-eap-throws-exception-upon.html" title="Resharper 6.1 EAP throws an exception upon load" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/12/resharper-61-eap-throws-exception-upon.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3674056906619314547</id><published>2011-08-06T14:17:00.000+01:00</published><updated>2011-11-06T00:00:17.592Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title type="text">Passing Objects between Silverlight Applications</title><content type="html">This week I have been making some prototype applications using Silverlight, which has been awesome, and I decided that I wanted to pass a few objects between these applications. If this wasn't a quick prototype and didn't have to run off of a Sales person's laptop I would have whipped together a quick bit of RIA Services and got them talking that way. However these are just two out of browser applications.&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: 24px; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: 24px; font-weight: bold;"&gt;Enter Local Messaging.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Silverlight has a great little feature, that I'm not sure is too often used, &lt;a href="http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx" rel="external"&gt;Local Messaging&lt;/a&gt;. Local Messaging allows you to send simple string messages between two Silverlight applications running on a local computer. This can be within the same Web Page or two Out of Browser Applications&lt;br /&gt;&lt;br /&gt;Local messaging works by having a LocalMessageReciever listening for messages in one application and then a LocalMessageSender sending messages from the other. If you want two way communication you simply have a listener and sender in each application.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;// In the receiving application:&lt;br /&gt;LocalMessageReceiver messageReceiver = new LocalMessageReceiver("receiver");&lt;br /&gt;&lt;br /&gt;// In the sending application:&lt;br /&gt;LocalMessageSender messageSender = new LocalMessageSender("receiver");&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I'm not going to explain how you send messages between the applications as &lt;a href="http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx"&gt;MSDN&lt;/a&gt; does a far better job of doing so. However MSDN only talks about simple string messages, I wanted to send objects.&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: 24px; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: 24px; font-weight: bold;"&gt;Serialising the objects&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The obvious solution I thought was to just serialise the objects to a string and then back at the other end. Silverlight doesn't support binary serialisation and as we have to send the message as a string the Serialisation could be XML, which is common practice and I'm sure most people know instinctively how to do so, however XML is bloated. Alot of our message string would be information we aren't interested in. Now in most applications we don't worry about this and XML is fine however this local app messaging has a maximum string size of 40 kilobytes. We don't want to fill this up with XML notation, instead we want something alot leaner.&lt;br /&gt;&lt;br /&gt;Although Silverlight doesn't support Binary Serialisation it does however support JSON. JSON is a far less verbose markup which will mean our messages will be more about the object data and structure rather than syntax which is a good thing&lt;br /&gt;&lt;br /&gt;When it comes to JSON serialisation there are a few options, the built in &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx"&gt;DataContractJsonSerializer&lt;/a&gt; , &lt;a href="http://json.codeplex.com/"&gt;JSON.Net&lt;/a&gt; etc. For the ease of setup I have gone for using the build in DataContractJsonSerializer. Here i take a generic object and serialise it to a stream which we can then use in our message.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;DataContractJsonSerializer serialiser = new DataContractJsonSerializer(message.GetType());&lt;br /&gt;var stream = new System.IO.MemoryStream();&lt;br /&gt;serialiser.WriteObject(stream, message);&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;With this string we can simply use a streamreader to get the string that our sendasync message sender method requires.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt; new System.IO.StreamReader(stream).ReadToEnd())&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;But there's a problem, we cant just send the json object, as at the other end we won't know the type. What we have to do then is send the type and the serialised form. This leaves us with the following:&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;&lt;br /&gt;stream.Position = 0;&lt;br /&gt;sender.SendAsync(String.Format("{0}|!|{1}", message.GetType(), new System.IO.StreamReader(stream).ReadToEnd()));&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Note: I have used |!| as a way to know where the type name ends and the stream begins, I could have said {type}={jsonserilaisedobject} but I chose not too, for neatness though this should be possible I just chose to use a delimiter I knew wouldn't appear in my serialised object.&lt;br /&gt;&lt;h2&gt; Receiving the message and getting the object back&lt;/h2&gt;To get the object back in the other application, after receiving the message from the sender we have to split the string based on the delimeter and then deserialise the object.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;var type = e.Message.Substring(0, e.Message.IndexOf("|!|"));&lt;br /&gt;var data = e.Message.Substring(e.Message.IndexOf("|!|") + 3);&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The DataContractJsonSerializer requires a stram not a string to deserialise an object so next take the data string and turn it into a stream. Then just deserialise.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data));&lt;br /&gt;var serialiser = new DataContractJsonSerializer(Type.GetType(type));&lt;br /&gt;if(type == "OurCustomType"){&lt;br /&gt;    var result = (OurCustomType)serialiser.ReadObject(stream);&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And that's it, obviously handling lots of types would mean not using an if statement, maybe a switch or whatever but the principle is the same.&lt;br /&gt;I hope you find this of use, it certainly made my prototype far more functional and proved a neat way of doing it&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/W2OR3RBwOY8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3674056906619314547/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/08/passing-objects-between-silverlight.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3674056906619314547" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3674056906619314547" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/W2OR3RBwOY8/passing-objects-between-silverlight.html" title="Passing Objects between Silverlight Applications" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/08/passing-objects-between-silverlight.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8107337579348256063</id><published>2011-07-22T21:24:00.000+01:00</published><updated>2012-03-30T10:07:36.743+01:00</updated><title type="text">linq to lucene magic unicorn edition</title><content type="html">This week I started to look at using &lt;a href="http://incubator.apache.org/lucene.net/"&gt;Lucene.Net&lt;/a&gt; again in a project. Previously I have used it directly however whilst on the new look Lucene.Net website I noticed the &lt;a href="http://linqtolucene.codeplex.com/"&gt;linq to lucene&lt;/a&gt; project. Which at first look seemed pretty good. However upon looking at the source I found it only works with XML and LinqToSql, this prototype project however was in .Net 4 and used Sql CE4 with Entity Framework 4.1 Code First.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Rather than abandon linq to lucene I decided it should be easy enough to get it working with EF4.1. DatabaseIndexSet contains the LinqToSql specific code so for the purpose of producing a proof of concept this is where all the changes go.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first item to change is to rescope the generic where clause to be DbContext rather than the linq context.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;&lt;br /&gt; public class DatabaseIndexSet&lt;tdatacontext&gt; : IndexSet&lt;br /&gt;        where TDataContext : DbContext&lt;/tdatacontext&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Next the Write Method needs altering, the LinqToSQL implementation uses the GetTable method, however E.F doesn't really have the same methods. Instead with E.F we can use the Set method with our entity as the generic, this will allow us to obtain all of the records&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finally the GetTableTypes method needs "tweaking", I say tweak as so far its a bit of bodge. The GetTableTypes method is used to find all of the "tables" within our database context which are then later used to create lucene index files. The original LinqToSql method ensured that each property was a generic type and that it is assignable from the base type. For our initial run as our entity classes don't inherit anything I have removed that check, just ensuring the properties are generic. This will be added back in for the final release.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;With those changes made we can then use LinqToLucene as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;&lt;br /&gt; var index = new EnquiriesIndexContext();&lt;br /&gt;            index.Write&lt;part&gt;();&lt;br /&gt;            var query = from p in index.Parts&lt;br /&gt;                        where p.PartNumber == "ghjtyugfhj-61"&lt;br /&gt;                        select p;&lt;br /&gt;           Console.WriteLine("Simple Query:");&lt;br /&gt;           ObjectDumper.Write(query);&lt;br /&gt;           Console.WriteLine("Query Output: {0}", query.ToString());&lt;br /&gt;           &lt;br /&gt;            var results = query.ToList();&lt;br /&gt;            Console.WriteLine("SimpleDemo returned {0} results", results.Count);&lt;br /&gt;&lt;/part&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Have a go of the &lt;a href="http://development.mjjames.co.uk/scripts/ASPNET/DOWNLOADS/Lucene.Linq.4.0.zip"&gt;prototype code that is attached&lt;/a&gt;, I'll be aiming to tidy it up and get it pushed back to the main project on codeplex over the next week. Enjoy&lt;br /&gt;&lt;br /&gt;Update 29/03/2012&lt;br /&gt;I have finally gotten around to updating this and submitting it to CodePlex, further details at &lt;a href="http://blog.mjjames.co.uk/2012/03/revisting-lucenetolinq.html"&gt;http://blog.mjjames.co.uk/2012/03/revisting-lucenetolinq.html&lt;/a&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/TTc_X-XzeaA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8107337579348256063/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/07/linq-to-lucene-magic-unicorn-edition.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8107337579348256063" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8107337579348256063" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/TTc_X-XzeaA/linq-to-lucene-magic-unicorn-edition.html" title="linq to lucene magic unicorn edition" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/07/linq-to-lucene-magic-unicorn-edition.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-576044058288147624</id><published>2011-05-08T00:30:00.000+01:00</published><updated>2011-11-06T00:00:27.131Z</updated><title type="text">Using the Razor Engine to create PDFs</title><content type="html">&lt;p&gt;I've been using MVC 3 and the Razor syntax for a while now, and a while ago whilst reading how people were using Razor for their email templates I had the idea to use Razor to help create PDF templates.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now sadly it's been a while since I played around with this but I have only just started getting back on top of things so here's how I've done it.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Components Used&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;My solution is to write HTML templates using the Razor syntax and then to make use of the Razor View Engine for filling in the dynamic data. Then for the PDF creation to make use of &lt;a href="http://sourceforge.net/projects/itextsharp/"&gt;iTextSharp&lt;/a&gt; library to generating the PDF documents from the generated HTML.&lt;/p&gt; &lt;p&gt; &lt;a href="http://sourceforge.net/projects/itextsharp/"&gt;iTextSharp&lt;/a&gt; is a free library that allows you to create PDF's using C#, unfortunatley its API is a bit of a pain to use natively so I have made use of &lt;a href="http://www.hugoware.net"&gt;Hugo Bonacci's&lt;/a&gt; HtmlToPdfBuilder.cs class to simply my interaction with the library.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The first thing to do is to generate the HTML markup for out PDF. So fire up a new RazorViewEngine and load the view (template) you wish to use. We load the view by using the view engines FindView method. This method requires a ControllerContext so if you are using in an MVC site you can pass the current context, which is how for my protoype I used it, or you need to pass a custom one.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt; var frontPageData = new RazorViewEngine().FindView(this.ControllerContext, "Newsletter", "", false);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In my example I wanted my Newsletter template, I have decided to not use a master view or caching but in a real application you may want to enable view caching.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Next you need a view context, a view context also needs a controller context, the view you found previously, a viewdatadictionary, a tempdatadictionary and a textwriter. The viewdatadictionary should be used to pass a model to your view or viewdata items, these will then be used within the view to populated your dynamic data items. The textwriter will be the object that the final generated HTML will be written to and this is what we will use to generate the PDF from.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;  var textwriter = new StringWriter();&lt;br /&gt;        var dataDict = new ViewDataDictionary&amp;lt;NewsletterData&amp;gt;()&lt;br /&gt;        {&lt;br /&gt;            Model = new NewsletterData{ Name = "Mike" }&lt;br /&gt;        };&lt;br /&gt;        var context = new ViewContext(this.ControllerContext, frontPageData.View, dataDict, new TempDataDictionary(), textwriter);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br &gt;&lt;br /&gt;&lt;p&gt;The final thing we do to get our generated HTML is call the Render method on our view, this render method requires our viewcontext and the text writer.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;frontPageData.View.Render(context, textwriter);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now the HTML is generated we can make use of the HtmlToPdfBuilder class to take our HTML and generate a PDF document. This is as simple as creating a new builder with a provided pagesize, calling add page and then appending our HTML. Hugo's HtmlToPdfBuilder class expects an array of values to use in the HTML, as it expects the HTML to have placeholders in the String.Format fashion {0} {1} etc. We don't need to do this as we have already finalised our HTML, if this was going to be production code I would seriously consider not using the HtmlToPdfBuilder class and instead write one that only uses iTextSharp and the RazorViewEngine, however for this simple prototype it makes things alot simpler.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code class="csharp"&gt;&lt;br /&gt;var myHtmlPdfBuilder = new HtmlToPdfBuilder(PageSize.A4_LANDSCAPE);&lt;br /&gt;//add a new page&lt;br /&gt;myHtmlPdfBuilder.AddPage();&lt;br /&gt;//using the current page take our html data from our view and write it&lt;br /&gt;myHtmlPdfBuilder[0].AppendHtml(data, new object[]{ });&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;p&gt;Now the PDF has been generated we can call the RenderPDF method on our HtmlPdfBuilder class to get an array of bytes back that represent the PDF. We can then use this array and write it to disk as a PDF document or to a response stream to have a dynamic PDF page on a website.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It really is that simple, I hope this prototype shows you the power the RazorViewEngine gives you especially when you start combining its output with other third party libraries. You can &lt;a href="http://development.mjjames.co.uk/scripts/aspnet/downloads/RazorPdf.zip"&gt;download my protoype MVC 3 site&lt;/a&gt; with this in and have a poke. It includes a simple PDFActionResult along with the above code.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Update&lt;/h2&gt;&lt;br /&gt;&lt;p&gt; Whilst writing this blog post up I have decided to roll this prototype into a proper component which should simplfy the above and not require the use of Hugo's class. I will blog about this component when it is finished and publish it on CodePlex or something similar.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/vwaFR8RkIk4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/576044058288147624/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/05/using-razor-engine-to-create-pdfs.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/576044058288147624" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/576044058288147624" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/vwaFR8RkIk4/using-razor-engine-to-create-pdfs.html" title="Using the Razor Engine to create PDFs" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/05/using-razor-engine-to-create-pdfs.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2108950501814895221</id><published>2011-01-31T21:20:00.000Z</published><updated>2011-11-06T00:00:27.098Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><title type="text">Using DeferredLoadListBox in a Pivot Control</title><content type="html">&lt;p&gt;Recently I've been using the &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/10/04/there-s-no-substitute-for-customer-feedback-improving-windows-phone-7-application-performance-now-a-bit-easier-with-lowprofileimageloader-and-deferredloadlistbox-updates.aspx"&gt;DeferredLoadListBox&lt;/a&gt; It's a fantastic way of improving the performance of your list views. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I started using the DeferredLoadListBox within a Pivot control but occasionally found that the app would randomly crash throwing the following exception: &lt;pre&gt;All containers must have a Height set (ex: via ItemContainerStyle), though the heights need not all need to be the same.&lt;/pre&gt; This usually means you haven't set the &lt;delay:DeferredLoadListBox.ItemContainerStyle&gt; properly. However I had ensured I had set the style height. I then got the source and started poking around.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;What I found was although in the UnmaskItemContent method the container had a height if you inspected the ActualHeight property this was 0. I did a bit of research and found the following on MSDN: &lt;pre&gt;ActualWidth and ActualHeight are calculated based on the Width/Height property values and the layout system.  There is no guarantee as to when these values will be "calculated"&lt;/pre&gt; So the problem appeared to be with timing.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After contacting the very helpful David Anson and exchanging a few ideas on solving the issue I decided to implement a retry counter. The concept being the first two times we find the container height is 0 drop out of the unmask method and try again later. If we still don't have a height on the third attempt an error must have occurred.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Implementing the counter was very simple and the most important thing is that this simple retry counter allows time for the height to be calculated and work as expected. The only minor side effect of this counter is that you can notice a slight pause in the UI however as this exception doesn't occur everytime this seems fair enough.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Find the modified source below and I hope it can be of use to you. &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;// Copyright (C) Microsoft Corporation. All Rights Reserved.&lt;br /&gt;// This code released under the terms of the Microsoft Public License&lt;br /&gt;// (Ms-PL, http://opensource.org/licenses/ms-pl.html).&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Windows;&lt;br /&gt;using System.Windows.Controls;&lt;br /&gt;using System.Windows.Data;&lt;br /&gt;using System.Windows.Media;&lt;br /&gt;&lt;br /&gt;namespace Delay&lt;br /&gt;{&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Implements a subclass of ListBox based on a StackPanel that defers the&lt;br /&gt;    /// loading of off-screen items until necessary in order to minimize impact&lt;br /&gt;    /// to the UI thread.&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    public class DeferredLoadListBox : ListBox&lt;br /&gt;    {&lt;br /&gt;        private enum OverlapKind { Overlap, ChildAbove, ChildBelow };&lt;br /&gt;&lt;br /&gt;        private ScrollViewer _scrollViewer;&lt;br /&gt;        private ItemContainerGenerator _generator;&lt;br /&gt;        private bool _queuedUnmaskVisibleContent;&lt;br /&gt;        private bool _inOnApplyTemplate;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Handles the application of the Control's Template.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public override void OnApplyTemplate()&lt;br /&gt;        {&lt;br /&gt;            // Unhook from old Template elements&lt;br /&gt;            _inOnApplyTemplate = true;&lt;br /&gt;            ClearValue(VerticalOffsetShadowProperty);&lt;br /&gt;            _scrollViewer = null;&lt;br /&gt;            _generator = null;&lt;br /&gt;&lt;br /&gt;            // Apply new Template&lt;br /&gt;            base.OnApplyTemplate();&lt;br /&gt;&lt;br /&gt;            // Hook up to new Template elements&lt;br /&gt;            _scrollViewer = FindFirstChildOfType&lt;ScrollViewer&gt;(this);&lt;br /&gt;            if (null == _scrollViewer)&lt;br /&gt;            {&lt;br /&gt;                throw new NotSupportedException("Control Template must include a ScrollViewer (wrapping ItemsHost).");&lt;br /&gt;            }&lt;br /&gt;            _generator = ItemContainerGenerator;&lt;br /&gt;            SetBinding(VerticalOffsetShadowProperty, new Binding { Source = _scrollViewer, Path = new PropertyPath("VerticalOffset") });&lt;br /&gt;            _inOnApplyTemplate = false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Determines if the specified item is (or is eligible to be) its own item container.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="item"&gt;The specified item.&lt;/param&gt;&lt;br /&gt;        /// &lt;returns&gt;true if the item is its own item container; otherwise, false.&lt;/returns&gt;&lt;br /&gt;        protected override bool IsItemItsOwnContainerOverride(object item)&lt;br /&gt;        {&lt;br /&gt;            // Check container type&lt;br /&gt;            return item is DeferredLoadListBoxItem;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Creates or identifies the element used to display a specified item.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;returns&gt;A DeferredLoadListBoxItem corresponding to a specified item.&lt;/returns&gt;&lt;br /&gt;        protected override DependencyObject GetContainerForItemOverride()&lt;br /&gt;        {&lt;br /&gt;            // Create container (matches ListBox implementation)&lt;br /&gt;            var item = new DeferredLoadListBoxItem();&lt;br /&gt;            if (ItemContainerStyle != null)&lt;br /&gt;            {&lt;br /&gt;                item.Style = ItemContainerStyle;&lt;br /&gt;            }&lt;br /&gt;            return item;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Prepares the specified element to display the specified item.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="element"&gt;The element used to display the specified item.&lt;/param&gt;&lt;br /&gt;        /// &lt;param name="item"&gt;The item to display.&lt;/param&gt;&lt;br /&gt;        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)&lt;br /&gt;        {&lt;br /&gt;            // Perform base class preparation&lt;br /&gt;            base.PrepareContainerForItemOverride(element, item);&lt;br /&gt;&lt;br /&gt;            // Mask the container's content&lt;br /&gt;            var container = (DeferredLoadListBoxItem)element;&lt;br /&gt;            if (!DesignerProperties.IsInDesignTool)&lt;br /&gt;            {&lt;br /&gt;                container.MaskContent();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            // Queue a (single) pass to unmask newly visible content on the next tick&lt;br /&gt;            if (!_queuedUnmaskVisibleContent)&lt;br /&gt;            {&lt;br /&gt;                _queuedUnmaskVisibleContent = true;&lt;br /&gt;                Dispatcher.BeginInvoke(() =&gt;&lt;br /&gt;                {&lt;br /&gt;                    _queuedUnmaskVisibleContent = false;&lt;br /&gt;                    UnmaskVisibleContent();&lt;br /&gt;                });&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static readonly DependencyProperty VerticalOffsetShadowProperty =&lt;br /&gt;            DependencyProperty.Register("VerticalOffsetShadow", typeof(double), typeof(DeferredLoadListBox), new PropertyMetadata(-1.0, OnVerticalOffsetShadowChanged));&lt;br /&gt;        private static void OnVerticalOffsetShadowChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            // Handle ScrollViewer VerticalOffset change by unmasking newly visible content&lt;br /&gt;            ((DeferredLoadListBox)o).UnmaskVisibleContent();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void UnmaskVisibleContent()&lt;br /&gt;        {&lt;br /&gt;            // Capture variables&lt;br /&gt;            var count = Items.Count;&lt;br /&gt;&lt;br /&gt;            // Find index of any container within view using (1-indexed) binary search&lt;br /&gt;            var index = -1;&lt;br /&gt;            var l = 0;&lt;br /&gt;            var r = count + 1;&lt;br /&gt;            while (-1 == index)&lt;br /&gt;            {&lt;br /&gt;                var p = (r - l) / 2;&lt;br /&gt;                if (0 == p)&lt;br /&gt;                {&lt;br /&gt;                    break;&lt;br /&gt;                }&lt;br /&gt;                p += l;&lt;br /&gt;                var c = (DeferredLoadListBoxItem)_generator.ContainerFromIndex(p - 1);&lt;br /&gt;                if (null == c)&lt;br /&gt;                {&lt;br /&gt;                    if (_inOnApplyTemplate)&lt;br /&gt;                    {&lt;br /&gt;                        // Applying template; don't expect to have containers at this point&lt;br /&gt;                        return;&lt;br /&gt;                    }&lt;br /&gt;                    // Should always be able to get the container&lt;br /&gt;                    var presenter = FindFirstChildOfType&lt;ItemsPresenter&gt;(_scrollViewer);&lt;br /&gt;                    var panel = (null == presenter) ? null : FindFirstChildOfType&lt;Panel&gt;(presenter);&lt;br /&gt;                    if (panel is VirtualizingStackPanel)&lt;br /&gt;                    {&lt;br /&gt;                        throw new NotSupportedException("Must change ItemsPanel to be a StackPanel (via the ItemsPanel property).");&lt;br /&gt;                    }&lt;br /&gt;                    else&lt;br /&gt;                    {&lt;br /&gt;                        throw new NotSupportedException("Couldn't find container for item (ItemsPanel should be a StackPanel).");&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;                switch (Overlap(_scrollViewer, c, 0))&lt;br /&gt;                {&lt;br /&gt;                    case OverlapKind.Overlap:&lt;br /&gt;                        index = p - 1;&lt;br /&gt;                        break;&lt;br /&gt;                    case OverlapKind.ChildAbove:&lt;br /&gt;                        l = p;&lt;br /&gt;                        break;&lt;br /&gt;                    case OverlapKind.ChildBelow:&lt;br /&gt;                        r = p;&lt;br /&gt;                        break;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (-1 != index)&lt;br /&gt;            {&lt;br /&gt;                // Unmask visible items below the current item&lt;br /&gt;                for (var i = index; i &lt; count; i++)&lt;br /&gt;                {&lt;br /&gt;                    if (!UnmaskItemContent(i))&lt;br /&gt;                    {&lt;br /&gt;                        break;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                // Unmask visible items above the current item&lt;br /&gt;                for (var i = index - 1; 0 &lt;= i; i--)&lt;br /&gt;                {&lt;br /&gt;                    if (!UnmaskItemContent(i))&lt;br /&gt;                    {&lt;br /&gt;                        break;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private bool UnmaskItemContent(int index)&lt;br /&gt;        {&lt;br /&gt;            var container = (DeferredLoadListBoxItem)_generator.ContainerFromIndex(index);&lt;br /&gt;            if (null != container)&lt;br /&gt;            {&lt;br /&gt;                // Return quickly if not masked (but periodically check visibility anyway so we can stop once we're out of range)&lt;br /&gt;                if (!container.Masked &amp;&amp; (0 != (index % 16)))&lt;br /&gt;                {&lt;br /&gt;                    return true;&lt;br /&gt;                }&lt;br /&gt;                // Check necessary conditions&lt;br /&gt;                if (0 == container.Height)&lt;br /&gt;                {&lt;br /&gt;                    throw new NotSupportedException("All containers must have a Height set (ex: via ItemContainerStyle), though the heights need not all need to be the same.");&lt;br /&gt;                }&lt;br /&gt;                // If container overlaps the "visible" area (i.e. on or near the screen), unmask it&lt;br /&gt;                if (OverlapKind.Overlap == Overlap(_scrollViewer, container, 2 * _scrollViewer.ActualHeight))&lt;br /&gt;                {&lt;br /&gt;                    container.UnmaskContent();&lt;br /&gt;                    return true;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static bool Overlap(double startA, double endA, double startB, double endB)&lt;br /&gt;        {&lt;br /&gt;            return (((startA &lt;= startB) &amp;&amp; (startB &lt;= endA)) ||&lt;br /&gt;                    ((startB &lt;= startA) &amp;&amp; (startA &lt;= endB)));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static OverlapKind Overlap(FrameworkElement parent, FrameworkElement child, double padding)&lt;br /&gt;        {&lt;br /&gt;            // Get child bounds relative to parent&lt;br /&gt;            var transform = child.TransformToVisual(parent);&lt;br /&gt;            var bounds = new Rect(transform.Transform(new Point()), transform.Transform(new Point(/*child.ActualWidth*/ 0, child.ActualHeight)));&lt;br /&gt;            // Return kind of overlap&lt;br /&gt;            if (Overlap(0 - padding, parent.ActualHeight + padding, bounds.Top, bounds.Bottom))&lt;br /&gt;            {&lt;br /&gt;                return OverlapKind.Overlap;&lt;br /&gt;            }&lt;br /&gt;            else if (bounds.Top &lt; 0)&lt;br /&gt;            {&lt;br /&gt;                return OverlapKind.ChildAbove;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                return OverlapKind.ChildBelow;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static T FindFirstChildOfType&lt;T&gt;(DependencyObject root) where T : class&lt;br /&gt;        {&lt;br /&gt;            // Enqueue root node&lt;br /&gt;            var queue = new Queue&lt;DependencyObject&gt;();&lt;br /&gt;            queue.Enqueue(root);&lt;br /&gt;            while (0 &lt; queue.Count)&lt;br /&gt;            {&lt;br /&gt;                // Dequeue next node and check its children&lt;br /&gt;                var current = queue.Dequeue();&lt;br /&gt;                for (var i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 &lt;= i; i--)&lt;br /&gt;                {&lt;br /&gt;                    var child = VisualTreeHelper.GetChild(current, i);&lt;br /&gt;                    var typedChild = child as T;&lt;br /&gt;                    if (null != typedChild)&lt;br /&gt;                    {&lt;br /&gt;                        return typedChild;&lt;br /&gt;                    }&lt;br /&gt;                    // Enqueue child&lt;br /&gt;                    queue.Enqueue(child);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            // No children match&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/fWBJgsVXx1s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2108950501814895221/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/01/using-deferredloadlistbox-in-pivot.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2108950501814895221" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2108950501814895221" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/fWBJgsVXx1s/using-deferredloadlistbox-in-pivot.html" title="Using DeferredLoadListBox in a Pivot Control" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/01/using-deferredloadlistbox-in-pivot.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-4568964585343016888</id><published>2011-01-22T11:40:00.000Z</published><updated>2011-11-06T00:00:27.126Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><title type="text">Windows Phone 7: Security Exception on deactivate</title><content type="html">&lt;p&gt;This morning I have been finishing the tombstoning part of one of my Windows Phone applications I have been developing. Whilst testing I found that when the application deactivated or terminated that a SecurityException was thrown. Looking at the stack trace I noticed that it was occurring whilst trying to serialise some data to the Applications State store.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now I knew I was putting some data into state so this wasn't to hard to find however, when I looked at what I was putting into state it was nothing more complicated than a custom type that exposed a collection of POCO classes. Why would this cause a security exception. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I decided to do a simple Google search for the exception "windows phone 7 security exception" and the second result looked similar: "c# - SecurityException was unhandled when using isolated storage" [&lt;a href="http://stackoverflow.com/questions/4209280/securityexception-was-unhandled-when-using-isolated-storage"&gt;http://stackoverflow.com/questions/4209280/securityexception-was-unhandled-when-using-isolated-storage&lt;/a&gt;]. So I had a look, and guessed that if you can't put internal classes into IsolatedStorage you also can't do it for ApplicationState, which makes sense when you think about it. So I made my type public and not internal and all was good in the world again.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Another week another tip.... I wonder what I will find out next week&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/v-36bJjaS0c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/4568964585343016888/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/01/windows-phone-7-security-exception-on.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4568964585343016888" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4568964585343016888" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/v-36bJjaS0c/windows-phone-7-security-exception-on.html" title="Windows Phone 7: Security Exception on deactivate" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/01/windows-phone-7-security-exception-on.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-4203209774027555005</id><published>2011-01-15T18:57:00.000Z</published><updated>2011-11-06T00:00:27.121Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio 2010" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title type="text">Windows Phone Development and Designer Exceptions</title><content type="html">&lt;p&gt;I've been building a few Windows Phone applications recently and have been learning lot's along the way and am hopefully releasing a couple of these in the near future. However on my current project I have been constantly hounded by the designer view of my xaml pages throwing exceptions.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Tonight I decided to finally look into why these occur, I have managed to ignore them previously due to the weird nature of them. My exception scenario consists of a page that contains a pivot control and inside one of the pivot items there is a user control. The user control contains a simple list view which has some data bound to it&lt;/p&gt; &lt;p&gt;Now I have always got past the exceptions as if you use the designer view for the user control it works fine, however as soon as I put it into a page or a pivot the designer starts kicking off.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The actual exception is as follows: &lt;pre&gt;Could not load type 'System.Net.HttpUtility' from assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.&lt;/pre&gt; It then goes on to tell me the line number and location etc of this. At first glance this exception looks a bit weird as in the code view and if you run the application the exception is never thrown. &lt;/p&gt; &lt;p&gt;The first thing I did to try and resolve this issue was to find where System.Net.HttpUtility lives, in the desktop version of Silverlight it lives in &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.browser.httputility(v=vs.95).aspx"&gt;System.Windows.Browser &lt;/a&gt; But as the Windows Phone version of Silverlight doesn't include System.Windows.Browser the development team moved the httputility type into the System.Net namespace and put it into the System.Windows assembly, &lt;a href="http://msdn.microsoft.com/en-us/library/dd470087(v=vs.95).aspx#Assemblies"&gt;http://msdn.microsoft.com/en-us/library/dd470087(v=vs.95).aspx#Assemblies&lt;/a&gt;. This explains why the project builds and runs etc, however it doesn't explain why the designer has such a bad time with it. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sadly I couldn't find a source or information on this exception, my guess is the designer is loading an older version of the assembly, a missing designer tool update from the RTM or something similar {Edit see my update below}. However what I have found is that Silverlight does have another way of encoding and decoding URL strings. &lt;a href="http://msdn.microsoft.com/en-us/library/system.uri.escapeuristring(v=VS.95).aspx"&gt;System.Uri.EscapeUriString&lt;/a&gt;, if you use this the phone and the designer all work happily. A minor change and a headache eased :) I'm hoping the next tools update fixes the issue but until then this seems the safest method of escaping url strings.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Update&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;As I oddly found this issue intriguing I decided to investigate further. I opened another Visual Studio attached it to the Visual Studio process I had my project in and turned on catch all exceptions. Then when the exception was thrown I looked at the AppDomains assembly list, System.AppDomain.CurrentDomain.GetAssemblies(), 55 in all were loaded. I then looked through this list for the assembly referenced in the exception. This assembly then had the following location value:   Location "c:\\Program Files (x86)\\Microsoft Silverlight\\4.0.51204.0\\System.Windows.dll". This is the main Silverlight 4 runtime, NOT the Windows Phone version which is 3.7.x, to be certain I then opened the assembly in Reflector to be sure the System.Net.HttpUtility was missing and it was.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So as suspected the designer is loading the wrong assembly thus the error, the assembly it should be loading is in the referenced assemblies folder, C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\System.Windows.dll , hopefully reporting this on Connect will result in a hotfix / update. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/yy472lihMd0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/4203209774027555005/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2011/01/windows-phone-development-and-designer.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4203209774027555005" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4203209774027555005" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/yy472lihMd0/windows-phone-development-and-designer.html" title="Windows Phone Development and Designer Exceptions" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2011/01/windows-phone-development-and-designer.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-999475797472850135</id><published>2010-12-16T23:43:00.000Z</published><updated>2011-11-06T00:00:27.143Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio" /><title type="text">MVC 3 RC2 Install Error (0x80070643)</title><content type="html">&lt;p&gt;This evening I came to installing MVC3 RC2 on both my desktop and laptop. The laptop installed first time, however I found that on my desktop it refused to install. Citing the following error in its install log: &lt;strong&gt;Installation failed with error code: (0x80070643)&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After poking around in the log file I found that the VS10-KB2465236-x86.exe patch was where it was falling over. To try and get more information I found the temp directory with this file in and ran the installer manually. This also as expected errored, however this time when I looked in the log file I found a slightly different error: &lt;strong&gt;Install failed on product (Microsoft Visual Studio 2010 Express for Windows Phone - ENU)&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The next obvious place for me to go next was to uninstall the Windows Phone Developer Tools, I figured I can always reinstall them. Upon removing this I then tried to install MVC3 RC2 again. This time it still failed, with the same error I had previously but this time for Visual Studio 2010. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As a final shot I wondered if the Visual Studio 2010 SP1 beta may have had the patch in and was causing some sort of a conflict. As such if I skipped the KB2465236 patch and simply installed the rest of MVC3 seeing if it would work OK. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It turns out I did manage to get it all installed, I had to grab the MSI Installers out of the temp directory that the main MVC installer creates and then run the installers in the following order: aspnetwebpages.msi, aspnetwebpagesvs2010tools.msi, aspnetmvc3.msi, aspnetmvc3vs2010tools.msi and finally nuget.msi &lt;br /&gt; VS2010 now has the new templates and so far everything looks in order. This is a bit of a risky way of installing MVC3 RC2 but for me it works, if you have this issue and want to try bypassing the KB patch then I hope this has helped&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/zTd_cyY7b1g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/999475797472850135/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2010/12/mvc-3-rc2-install-error-0x80070643.html#comment-form" title="12 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/999475797472850135" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/999475797472850135" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/zTd_cyY7b1g/mvc-3-rc2-install-error-0x80070643.html" title="MVC 3 RC2 Install Error (0x80070643)" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>12</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2010/12/mvc-3-rc2-install-error-0x80070643.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2919811019147003272</id><published>2010-04-13T21:04:00.000+01:00</published><updated>2011-11-06T00:00:27.103Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTMLHelper" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title type="text">MVC DateTime Suffix HTMLHelper</title><content type="html">&lt;p&gt;Recently I have been working on an MVC Project, and tonight I got to the point where I wanted to output a date in a specific format, for example Tuesday 13th April 2010. Sadly DateTime formatting still doesn't allow you to specify output a suffix, you can do Tuesday 13 April 2010 but not what I wanted.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I decided that I could achieve what I wanted by writing a quick HTMLHelper, this would then allow me to specify a datetime format string with a magic / special character which I could then replace for the appropriate suffix.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Writing the helper was very quick and easy, if you want to learn about HTMLHelpers and how to write your own I recommend looking at &lt;a href="http://stephenwalther.com/blog/archive/2009/03/03/chapter-6-understanding-html-helpers.aspx"&gt;Stephen Walther's Post on HTMLHelpers&lt;/a&gt; .&lt;/p&gt; &lt;p&gt;The code for my datetimehelper is below: &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace mjjames.MVCHelpers&lt;br /&gt;{&lt;br /&gt; public static class DateTimeExtensions&lt;br /&gt; {&lt;br /&gt;  public static string DateTimeFormat(this HtmlHelper helper, string dateTimeFormat, DateTime dateTime){&lt;br /&gt;            var dateTimeOutput = dateTime.ToString(dateTimeFormat);&lt;br /&gt;            if (dateTimeFormat.Contains("~"))&lt;br /&gt;            {&lt;br /&gt;                dateTimeOutput = dateTimeOutput.Replace("~", GenerateDaySuffix(dateTime.Day));&lt;br /&gt;            }&lt;br /&gt;      return dateTimeOutput;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Generates a Day Suffix from the Day Number&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;param name="day"&amp;gt;Day Number&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;returns&amp;gt;Suffix String&amp;lt;/returns&amp;gt;&lt;br /&gt;     private static string GenerateDaySuffix(int day)&lt;br /&gt;     {&lt;br /&gt;         var suffix = "";&lt;br /&gt;            //find out if the day matches a suffix which isn't th&lt;br /&gt;         switch(day)&lt;br /&gt;         {&lt;br /&gt;             case 1:&lt;br /&gt;                case 21:&lt;br /&gt;                case 31:&lt;br /&gt;                 suffix = "st";&lt;br /&gt;                    break;&lt;br /&gt;                case 2:&lt;br /&gt;                case 22:&lt;br /&gt;                 suffix = "nd";&lt;br /&gt;                 break;&lt;br /&gt;                case 3:&lt;br /&gt;                case 23:&lt;br /&gt;                 suffix = "rd";&lt;br /&gt;                    break;&lt;br /&gt;                default:&lt;br /&gt;                 suffix = "th";&lt;br /&gt;                 break;&lt;br /&gt;         }&lt;br /&gt;         return suffix;&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then to use it first include the namespace in your view:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code class="csharp"&gt;&lt;br /&gt;&amp;lt;%@ Import Namespace="mjjames.MVCHelpers" %&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;And then to use it call Html.DateTimeFormat passing the format string and the DateTime value. To use the day suffix include the ~ character. Note you can use it with.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;&amp;lt;%= Html.DateTimeFormat("dddd d~ h", Model.StartDate) %&amp;gt;&lt;br /&gt;&amp;lt;%= Html.DateTimeFormat("dddd d h", Model.EndDate) %&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;There we go, nice and easy, if you want to use this feel free I hope it helps&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/ocUin1HlNKI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2919811019147003272/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2010/04/mvc-datetime-suffix-htmlhelper.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2919811019147003272" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2919811019147003272" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/ocUin1HlNKI/mvc-datetime-suffix-htmlhelper.html" title="MVC DateTime Suffix HTMLHelper" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2010/04/mvc-datetime-suffix-htmlhelper.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3622330408947484874</id><published>2010-04-06T16:01:00.000+01:00</published><updated>2011-11-06T00:00:27.110Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="DotRAS" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title type="text">Using DOTRas - An Overview and some things I've learnt</title><content type="html">&lt;p&gt;Yesterday I decided to starting knocking together a quick application to help me backup my server to some local storage. The idea being that at any point I have a local copy of my server setup a maximum of a day old. The point of this application and how I've gone about writing it, what libraries I'm using etc will be part of a future blog post.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I decided early on that I however I wanted to transfer files I wanted to do this over a VPN to the server. I had several reasons for this, being able to expose my files over a network share, more secure etc. My Application will be running on an old laptop, so I first thought about just always having it connected to a VPN using windows, and run the application as normal. However I then thought what if the VPN disconnects and I don't notice, how long would it take until I noticed etc. So I decided to make the application create a VPN Connection at start up and then disconnect from it upon completion. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I figured that there would be a good library that would help with this and it turns out there is. &lt;a href="http://dotras.codeplex.com/"&gt;DotRAS&lt;/a&gt; provides remote access service (RAS) components for .NET languages , it's tag line is "WindowsRAS made easy" and I have to say so far it has lived up to that.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A quick example of how to open the computers RAS PhoneBook : &lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;using(var phoneBook = new RasPhoneBook())&lt;br /&gt;{&lt;br /&gt;     phoneBook.Open();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You could then find an existing entry within the phonebook to make a connection too and open a connection:&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;var entry = phoneBook.Entries.FirstOrDefault(e =&gt; e.Name.Equals("mikes test entry");&lt;br /&gt;if(entry != null){&lt;br /&gt;    entry.Open();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now there's obviously alot you can do with it, create and manage connections programatically etc, use phone dialers but so far I'm just tinkering with VPN's. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Tips and Tricks&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Now to what I wanted to post about, tips and tricks. Sadly whilst working with DOTRas I found a few gotcha's that I wanted to post about. I will also update this list as I find more. It's worth noting that all of these apply to DotRAS 1.1 and I'm using the Win2k8 build, some of these I know also apply to the XPSP2 build. And my development machine is Windows 7 x64.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Invalid Default PhoneBook Location&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;The default phonebook location, which is called when you just do phonebook.Open(), is set to use RasPhoneBookType.AllUsers, now this maps to : C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk which for me doesn't exist. The folders exist up to connections, I have no Pbk folder. &lt;/p&gt; &lt;br /&gt; &lt;p&gt;I could obviously check for this and then create the phonebook entry but really you should always use RasPhoneBookType.User which uses the phonebook located within the current users AppData. &lt;/p&gt;&lt;br /&gt;&lt;h3&gt;The entry is not associated with a phone book&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Actually quite an obvious issue but worth commenting on, If you create a new phonebook entry &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;var entry = RasEntry.CreateVpnEntry(_connectionName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default,                                 RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;And then try to set the user's credentials without first adding the entry to the phonebook:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;entry.UpdateCredentials(new NetworkCredential(authenticationDetails.UserName, authenticationDetails.Password));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Everything goes horribly wrong, instead add the entry to the phonebook and then set the credentials.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="csharp"&gt;&lt;br /&gt;phoneBook.Entries.Add(entry);&lt;br /&gt;entry.UpdateCredentials(new NetworkCredential(authenticationDetails.UserName, authenticationDetails.Password));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Keep an eye on this post, I'll update it as I continue to use DotRAS and then on a later date post about my application in full.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/_Ch-ObowXLs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3622330408947484874/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2010/04/using-dotras-overview-and-some-things-i.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3622330408947484874" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3622330408947484874" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/_Ch-ObowXLs/using-dotras-overview-and-some-things-i.html" title="Using DOTRas - An Overview and some things I&amp;#39;ve learnt" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2010/04/using-dotras-overview-and-some-things-i.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8999845332600228745</id><published>2010-02-09T22:08:00.000Z</published><updated>2011-11-06T00:00:27.142Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="SVN" /><category scheme="http://www.blogger.com/atom/ns#" term="SubVersion" /><title type="text">Unable to merge or create branches with SVN</title><content type="html">&lt;p&gt;I've been using SubVersion for a while, several years infact, I use VisualSVN on my server and TortoiseSVN on my machines.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Until recently I had never experienced any problems or glitches with it. However at some point within the last two months one of my main repositories started playing up. It's the only repository I have ever branched. The problem occurred when after working on a branch for several months I decided it was time to merge it back into the head. However when I tried to use the merge function and take the branch into the head I was given the following error message: &lt;blockquote&gt;[branch] is not a child of repository root URL [trunk]&lt;/blockquote&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I tried several attempts at trying to do this, rechecking out the branch and trunk in case they were corrupt but to no avail. I then decided to try creating a new branch to see if the repository was totally broken and I indeed got an error.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;Repository moved permanently to [svn server address] please relocate;&lt;/blockquote&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So it looked liked the reopsitory was broken. On a bit of a whim I noticed that my file path looked something similar to f:\development\shared\a repository name\trunk and similarly the branch was f:\development\shared\a repository name\1.6 The SVN url however was http://[svn-url]/svn/arepositoryname , I was wondering if somehow the directory path was confusing SVN, was it always expecting the directories to be checked out in the same folder structure as the server.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So I tried creating a new directory called arepositoryname and then checked out the trunk and version 1.6 underneath it. I then tried to merge the 1.6 repository back into the trunk and create a new branch and it all worked fine!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So it indeed seemed that TortoiseSVN was getting confused by my folder structure not replicating the servers, simply fixing this, maybe it was just removing the spaces need to possibly try that further, resolved my issue.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Just to add clarification if you stumble across this trying to solve your issue that I was running VisualSVN 2.1 and Tortoise 1.6 on a Windows 7 x64 machine. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Some crazy behaviour but I least I figured it out after &lt;strong&gt;several&lt;/strong&gt; hours ... hope this helps.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/KFvoTccPMBM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8999845332600228745/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2010/02/unable-to-merge-or-create-branches-with.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8999845332600228745" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8999845332600228745" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/KFvoTccPMBM/unable-to-merge-or-create-branches-with.html" title="Unable to merge or create branches with SVN" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>3</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2010/02/unable-to-merge-or-create-branches-with.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-61107788201211030</id><published>2010-01-22T18:50:00.000Z</published><updated>2011-11-06T00:00:27.133Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="vista" /><category scheme="http://www.blogger.com/atom/ns#" term="streams" /><category scheme="http://www.blogger.com/atom/ns#" term="drivers" /><category scheme="http://www.blogger.com/atom/ns#" term="unblock" /><title type="text">Drivers Causing "This file came from another computer and might be blocked to help protect this computer" On Startup</title><content type="html">&lt;p&gt;This weekend I had to reinstall a driver for a laptop touch pad. I went to the Sony site and got the driver, it came in a zip file and looked pretty standard. A load of driver files and an install file.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It install all OK and the touchpad started to have its scroll options, however then I rebooted and found each time the laptop started up Windows Vista kept asking to confirm I wanted to run the programs, "This file came from another computer and might be blocked to help protect this computer". Straight away I thought it had to be the file was blocked from running as it came from a download. I went to the files unblocked them all, clicked apply and rebooted again only to find it happen again.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Just to ensure I hadn't forgotten to click apply I tried this again only to find the same thing. After Googling for the issue I found the issue was that the installer had simply copied the drivers and files. This meant that the NTFS information was also copied, this information contained the flag "downloaded from internet" along with others.&lt;/p&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;p&gt;The solution was to strip these files of this information, luckily you can obtain a free tool to do this. &lt;a href="http://www.microsoft.com/technet/sysinternals/utilities/Streams.mspx"&gt;"Streams"&lt;/a&gt; from Sysinternals,  I simply downloaded this,http://www.microsoft.com/technet/sysinternals/utilities/Streams.mspx, ran it on the directory, command prompt only, and rebooted to find all was well.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Certainly one to remember as I have came across this before and removed the program.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/ubNdmU-yybI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/61107788201211030/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2010/01/drivers-causing-file-came-from-another.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/61107788201211030" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/61107788201211030" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Mjjames-WebDeveloper/~3/ubNdmU-yybI/drivers-causing-file-came-from-another.html" title="Drivers Causing &amp;quot;This file came from another computer and might be blocked to help protect this computer&amp;quot; On Startup" /><author><name>Michael James</name><uri>https://plus.google.com/109817868602331007533</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-5cUQD2Vnu9I/AAAAAAAAAAI/AAAAAAAAAWM/c64cpELTaM0/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2010/01/drivers-causing-file-came-from-another.html</feedburner:origLink></entry></feed>
