<?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.mjjames.co.uk/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-2088695286535567324</id><updated>2012-02-02T05:01:20.772Z</updated><category term="VBScript" /><category term="Visual Studio" /><category term="reflection" /><category term="MVC" /><category term="Lamda Expressions" /><category term="Build Error" /><category term="SiteMaps" /><category term="youtube" /><category term="Visual Studio 2010" /><category term="HTTP Headers" /><category term="Data Type" /><category term="ASP.NET MVC" /><category term="ASP.NET" /><category term="chrome" /><category term="Windows Phone" /><category term="Multi Threading" /><category term="TDD" /><category term="HTMLHelper" /><category term="Google SiteMap Generator" /><category term="Content-Disposition" /><category term="DotRAS" /><category term="Yahoo" /><category term="Packt" /><category term="Threading" /><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="Hack Day" /><category term="XML" /><category term="streams" /><category term="IIS" /><category term="Google" /><category term="google chrome" /><category term="VS2008" /><category term="SubVersion" /><category term="C#" /><category term="vimeo" /><category term="unblock" /><category term="Firefox" /><category term="drivers" /><category term="flickr" /><category term="FCKEditor" /><category term="openhackdaylondon" /><category term="Bandwidth" /><category term="Battery" /><category term="SVN" /><category term="DataTypes" /><category term="Tips and Tricks" /><category term="WIndows 7" /><category term="vista" /><category term="Hardware Interupts" /><category term="Silverlight" /><category term=".NET" /><category term="Books" /><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://profiles.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>29</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.mjjames.co.uk/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-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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-8883897898356451200?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-5070903227580261065?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-6492627802917597867?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&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="0 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://feeds.mjjames.co.uk/~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://profiles.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/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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3332808871596753148?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3674056906619314547?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&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://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/W2OR3RBwOY8/passing-objects-between-silverlight.html" title="Passing Objects between Silverlight Applications" /><author><name>Michael James</name><uri>https://profiles.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>2011-11-06T00:00:27.138Z</updated><title type="text">linq to lucene magic unicorn edition</title><content type="html">&lt;p&gt;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;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&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;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&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;/p&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;br /&gt;&lt;/code&gt;&lt;/pre&gt; &lt;br /&gt;&lt;p&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;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&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;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;With those changes made we can then use LinqToLucene as follows:&lt;br /&gt;&lt;/p&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;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&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;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-8107337579348256063?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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="0 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://feeds.mjjames.co.uk/~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://profiles.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/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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-576044058288147624?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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="0 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://feeds.mjjames.co.uk/~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://profiles.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/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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-2108950501814895221?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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="0 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://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/fWBJgsVXx1s/using-deferredloadlistbox-in-pivot.html" title="Using DeferredLoadListBox in a Pivot Control" /><author><name>Michael James</name><uri>https://profiles.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/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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-4568964585343016888?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-4203209774027555005?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-999475797472850135?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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="11 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://feeds.mjjames.co.uk/~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://profiles.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>11</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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-2919811019147003272?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/ocUin1HlNKI/mvc-datetime-suffix-htmlhelper.html" title="MVC DateTime Suffix HTMLHelper" /><author><name>Michael James</name><uri>https://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3622330408947484874?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-8999845332600228745?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-61107788201211030?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&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://feeds.mjjames.co.uk/~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://profiles.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><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-673547167221542281</id><published>2009-10-01T23:07:00.000+01:00</published><updated>2011-11-06T00:00:27.135Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="reflection" /><title type="text">Why we have to be more careful about what we read and more importantly what we write</title><content type="html">&lt;p&gt;In this day and age it is very uncommon to not use the internet to research or solve problems. Our reliance on printed reference books and even reference sites has dwindled massively.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;As developers, especially budding developers, we often just Google our problems, in fact I think most of our senior dev's often say to us "have you Googled it?" When asked about something.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Now googling things of course has changed our industry, we can often solve problems or get good starting points within seconds. &lt;br /&gt; This on its own is not a bad thing, we google we get the results and we crack on. The problem however is when you pick the first item or a random article and use what someone else has written as FACT.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The problem with our "Google" culture, this applys to more than programming, is that we often don't filter what we read. We suffer from fps, first page symdrom. If its on the first page of our results it has to be correct.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Sadly though all too often the actual blogs or forum posts we end up reading are from FACT. Today I was investigating an issue with a JS tab solution I had wrote and sadly found a ton of some very poor "tutorials". These articles / blogs although well presented and often written with the best intentions often lead people to learn / pick up bad habits. I won't name the article that prompted me to write this but to say the solution was so far wrong is an understatement.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;New developers will always trust what they read, I think it stems from how our education systems work. I believe we need to refine our "google" culture tendencies and in particular our FPS.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;How do we change this? Firstly we need to encourage people to not just read the first article / blog they reach from a search. Instead to open several tabs of articles on the subject matter and then read each one, and then and only then look at the common concepts / answers they provide. We need to consider multiple sources before something is FACT.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Also I believe blog and article writers also have an obligation to research / check out what others think or do regarding a subject before they post onto the internet. This also applies to big sites like the BBC, in fact the bigger you are the more this applies.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Its great to share solutions to problems and to write about things we like, things we have done, things we think are cool but we must ensure that what we write is technically sound, otherwise we continue to breed a culture and community of half baked products and websites.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;This is where I believe sites like stack overflow and all their derivatives will help.  As these sites continue to grow and questions with highly voted answers appear in our search engines, hopefully quality will begin to cut through the noise.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Our "google" culture no doubt makes things easier and quicker and I'm a believer in "have you Googled for it?" , but I do think us as writers and us as searchers need to be more analytical of what we read in order to produce things of higher quality and to grow in our profession.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-673547167221542281?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/yD6_YuMJ78A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/673547167221542281/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/10/why-we-have-to-be-more-careful-about.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/673547167221542281" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/673547167221542281" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/yD6_YuMJ78A/why-we-have-to-be-more-careful-about.html" title="Why we have to be more careful about what we read and more importantly what we write" /><author><name>Michael James</name><uri>https://profiles.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/2009/10/why-we-have-to-be-more-careful-about.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-1748793228946226809</id><published>2009-08-26T16:37:00.000+01:00</published><updated>2011-11-06T00:00:27.094Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="masterclass" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="TDD" /><title type="text">TDD Masterclass in the UK</title><content type="html">&lt;p&gt;Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of "The Art of Unit Testing" (http://www.artofunittesting.com/), a leading tdd &amp; unit testing book; he maintains a blog at http://iserializable.com (which amoung other things has critiqued tests written by Microsoft for asp.net MVC - check out the testreviews category) and has recently been on the Scott Hanselman podcast (http://bit.ly/psgYO) where he educated Scott on best practices in Unit Testing techniques. For a further insight into Roy's style, be sure to also check out Roy's talk at the recent Norwegian Developer's Conference (http://bit.ly/NuJVa). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Full Details here: http://bbits.co.uk/tddmasterclass&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;bbits are holding a raffle for a free ticket for the event. To be eligible to win the ticket (worth £2395!) you MUST paste this text, including all links, into your blog and email Ian@bbits.co.uk with the url to the blog entry.  The draw will be made on September 1st and the winner informed by email and on bbits.co.uk/blog&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-1748793228946226809?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/ckfAO7NbYus" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/1748793228946226809/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/08/tdd-masterclass-in-uk.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/1748793228946226809" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/1748793228946226809" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/ckfAO7NbYus/tdd-masterclass-in-uk.html" title="TDD Masterclass in the UK" /><author><name>Michael James</name><uri>https://profiles.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/2009/08/tdd-masterclass-in-uk.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3434656666841909879</id><published>2009-06-26T20:16:00.000+01:00</published><updated>2011-11-06T00:00:27.105Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="vimeo" /><category scheme="http://www.blogger.com/atom/ns#" term="flickr" /><category scheme="http://www.blogger.com/atom/ns#" term="Plugin" /><category scheme="http://www.blogger.com/atom/ns#" term="FCKEditor" /><category scheme="http://www.blogger.com/atom/ns#" term="youtube" /><title type="text">FlickVimTube - An FCKEditor Plugin</title><content type="html">&lt;p&gt;First things first, ignore the random title for this post, it does have a meaning and it's the best I could up with ;)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The other evening I was hitting some downtime and rather than carry on playing FarCry 2 I decided I'd write a quick &lt;a href="http://fckeditor.net"&gt;FCKEditor&lt;/a&gt; plugin which I've been meaning to write for a while. By default the editor comes with functionality to insert flash files into your content which works well however I wanted to have a way to only insert online videos from Flickr,  Vimeo or YouTube. To insert these I was having to manually go into source view, paste in the embed code etc. A chore and a heartache.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So enough was enough and I banged together a quick plugin that would take a YouTube Embed URL and then insert the appropiate embed HTML for it. This was actually quite simple. I worked out there was four main steps, 1. Extract the video ID from the URL 2. Create suitable embed markup and insert into the editor 3. Create a preview video so you can ensure it works before clicking ok. 4. Be able to view and update the video after inserting.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Extracting the video ID I'm sure could be done using some clever regex expression however for simplicity and speed I opted to simply slice the YouTube url at ?v= bit and then use the remainder as the ID. As the official embed url is in the format http://www.youtube.com/watch?v={id} I have decided for my first version of this plugin I can nievly split, however I should really parse it properly.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;To insert the embed object I made use of some build in FCKEditor methods to create the object and then assign the attributes to it. &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;br /&gt;e = FCK.EditorDocument.createElement('EMBED');&lt;br /&gt;SetAttribute(e, 'src', embedUrl);&lt;br /&gt;&lt;br /&gt;SetAttribute(e, 'type', 'application/x-shockwave-flash');&lt;br /&gt;SetAttribute(e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer');&lt;br /&gt;&lt;br /&gt;SetAttribute(e, "width", GetE('txtWidth').value == '' ? 360 : GetE('txtWidth').value);&lt;br /&gt;SetAttribute(e, "height", GetE('txtHeight').value == '' ? 150 : GetE('txtHeight').value);&lt;br /&gt;SetAttribute(e, "allowscriptaccess", "always");&lt;br /&gt;SetAttribute(e, "allowfullscreen", "true");&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;After getting the basics working I decided to add support for Vimeo and Flickr. This was a case of just working out which service it was and then parsing out the id's and then setting the correct embed URL on the embed object.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;FCKEditor plugin's are dead easy to configure, in your fckeditor settings file simply register the plugin using FCKEditor.Plugins.Add and ensure your custom toolbar settings include the button, 'OnlineVideo' &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;br /&gt;FCKConfig.ToolbarSets["mjjames"] = [&lt;br /&gt;    ['Cut','Copy','PasteText','-','SpellCheck',&lt;br /&gt;    '-','Image','OnlineVideo','Table','Rule','Smiley','SpecialChar','-',&lt;br /&gt; 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat','-','Link','Unlink','Anchor','-','Source'],&lt;br /&gt; ['Style','FontFormat','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull',&lt;br /&gt; '-','Bold','Italic','Superscript','OrderedList','UnorderedList','-','Outdent','Indent'] &lt;br /&gt;];&lt;br /&gt;&lt;br /&gt;FCKConfig.Plugins.Add('OnlineVideo', 'en');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The plugin file includes language settings for english, however adding additional languages can be added by simply providing translations for the labels and then changing your plugin registration to include the new file name. If you want to add French for example create a file called fr.js in the plugins languages and then the plugin registration becomes:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;br /&gt;FCKConfig.Plugins.Add('OnlineVideo', 'fr');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The following language settings are available: &lt;br /&gt;&lt;br /&gt;OnlineVideoTip, DlgOnlineVideoTitle, DlgNoVideo, DlgInvalidVideoUrl, DlgOnlineVideoURL, DlgOnlineVideoWidth, DlgOnlineVideoHeight, DlgOnlineVideoQuality, DlgOnlineVideoLow, DlgOnlineVideoHigh. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The plugin can be downloaded as a &lt;a href="http://development.mjjames.co.uk/scripts/JS/FCKEditorOnlineVideoPlugin.zip"&gt;zip file&lt;/a&gt; and is licensed under &lt;a href="http://creativecommons.org/licenses/by-sa/3.0/"&gt;Creative Commons Attribution-Share Alike 3.0 License &lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the future I intend to extend this further, maybe to allow users to find and search for videos using the various API's provided by the video sources but that will be at a later date.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3434656666841909879?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/CNpI_2ZHk_8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3434656666841909879/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/06/flickvimtube-fckeditor-plugin.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3434656666841909879" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3434656666841909879" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/CNpI_2ZHk_8/flickvimtube-fckeditor-plugin.html" title="FlickVimTube - An FCKEditor Plugin" /><author><name>Michael James</name><uri>https://profiles.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>4</thr:total><feedburner:origLink>http://blog.mjjames.co.uk/2009/06/flickvimtube-fckeditor-plugin.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-2769122038803153437</id><published>2009-05-19T20:58:00.000+01:00</published><updated>2011-11-06T00:00:27.101Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Image Resizing" /><category scheme="http://www.blogger.com/atom/ns#" term="Bandwidth" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><title type="text">Wasting Bandwidth One Image at a Time....</title><content type="html">&lt;p&gt;Content Management Systems are great, they allow the average Joe to have a great level of control over their website. Gone are the days of clients asking for static pages to be amended, we live in the database powered give the power of editing and updating content to the client&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Our clients get to use Rich Text Editors like FCKEditor. They look and feel just like Microsoft Word, they can play with text, upload images, resize them simply by dragging them and are very often really happy.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;However this often comes at a cost. Most RTE's by default simply resize images by sticking on the HTML img attributes height and width. As many people are aware this doesn't actually resize the image, it just simply tells the browser take this massive image and render it smaller. The end user still has to download the huge image, I have seen on some sites 2000px x 1200px images being downloaded and then only shown at 250px x 120px!, which can take a while to load dependant their internet connection and ultimately we the developers have to pay the bandwidth cost for those images.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Tonight I decided to come up with something I could put on my church websites to combat this. It's more to aid the overall user experience rather than bandwidth cost but it all helps ;)&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;The Solution&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;The solution is actually really simple.&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Take the CMS content from the database &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Before rendering it to the page, parse it into a HTML Parser&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Using the parser find all the image tags&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Using the height,width and src attributes to generate a new URL to an image resizer app&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Replace the images src attribute with the new URL &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Render the content to the page&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;Parsing HTML in ASP.Net really is easy nowadays. Previously it was a pain, regex would never work properly or you could risk parsing your page as XML but luckily there are now tons of 3rd party libraries.  I chose &lt;a href="http://www.codeplex.com/htmlagilitypack"&gt;HTML AGility Pack&lt;/a&gt; as alot of people seemed to recommend it on &lt;a href="http://stackoverflow.com"&gt;stackoverflow&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;For my solution I simply did the following:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="c#"&gt;&lt;br /&gt;HtmlDocument doc = new HtmlDocument();&lt;br /&gt;doc.LoadHtml(page.body);&lt;br /&gt;HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img");&lt;br /&gt;if (imgs != null)&lt;br /&gt;{&lt;br /&gt;    foreach (HtmlNode img in imgs)&lt;br /&gt;    {&lt;br /&gt;        if (img.Attributes["height"] != null &amp;&amp; img.Attributes["width"] != null)&lt;br /&gt;        {&lt;br /&gt;            HtmlAttribute src = img.Attributes["src"];&lt;br /&gt;            string imgurl = src.Value;&lt;br /&gt;            src.Value = String.Format("/loadImage.aspx?image={0}&amp;action={1}&amp;width={2}&amp;height={3}", imgurl, "resizecrop",img.Attributes["width"].Value, img.Attributes["height"].Value);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;mainContent.Text = doc.DocumentNode.InnerHtml;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;So what's going on here? Well first I create a new HtmlDocument, provided by the HTMLAgilityPack. I then load my html from my db model, page.body, then I use a nice simple XPATH syntax to pull out any img tags within the content and stick them into a HTMLNode collection. Next after ensuring I have some nodes, I spin through each of them and check to see if they have a height and width attribute. If they do then I use these and the original image url to write a new url, in my case I have a page that does this, ideally though this should be a httpmodule or something to be nice and tidy. Then with the img tags updated I render the HtmlDocument back out to the page.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;That's it, a few line's of code. Now I was concerned I may have slowed down my page, as parsing and spinning through tag's could be CPU intensive however I found on my machine and quickly playing with it, I noticed no real difference. In production I'd output cache the page for a period of time anyway.  I noticed 100KB difference on one of my site's home pages and they weren't massive images, so I think it's well worth it.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There you have it, at the end of the day CMS's provide users with alot of power / flexibility but we have to ensure as developers that we provide systems that cater for users abusing the system, be this uploading massive images or otherwise. In the case of images simply having something that resizes the images on render keeps the frontend responsive whilst allowing the client to provide high resolution images if needed, in this case it wasn't alot of effort and the improvement alone was worth it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-2769122038803153437?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/kJs33tpr8vY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/2769122038803153437/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/05/wasting-bandwidth-one-image-at-time.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2769122038803153437" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/2769122038803153437" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/kJs33tpr8vY/wasting-bandwidth-one-image-at-time.html" title="Wasting Bandwidth One Image at a Time...." /><author><name>Michael James</name><uri>https://profiles.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/2009/05/wasting-bandwidth-one-image-at-time.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3660413617993832131</id><published>2009-04-29T16:01:00.000+01:00</published><updated>2011-11-06T00:00:27.112Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTTP Headers" /><category scheme="http://www.blogger.com/atom/ns#" term="internet explorer" /><category scheme="http://www.blogger.com/atom/ns#" term="Content-Disposition" /><category scheme="http://www.blogger.com/atom/ns#" term="VBScript" /><category scheme="http://www.blogger.com/atom/ns#" term="chrome" /><category scheme="http://www.blogger.com/atom/ns#" term="google chrome" /><category scheme="http://www.blogger.com/atom/ns#" term="Firefox" /><title type="text">Content Disposition in different browsers</title><content type="html">&lt;p&gt;Today I had to resolve an issue where in different browsers the filed dynamically generated download worked very differently / at all&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The setup, we had an xml file with a custom extension, say .mj, which was being served up by ASP. The HTTP Header had a content disposition header and a response type set.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="vbscript"&gt;&lt;br /&gt;Response.AddHeader "Content-Disposition", "attachment; filename=""our file.mj"""&lt;br /&gt;Response.ContentType = "text/xml"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This worked fine in Internet Explorer, the file was downloaded as "our file.mj". However FireFox and Chrome acted very differently, in FireFox the file was downloaded as just "our", and Chrome as "our file.xml".&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In FireFox it appears that the issue is caused by having a space in the file name, this &lt;a href="http://www.webmaster-talk.com/asp-forum/35962-content-disposition-does-nto-work-firefox.html"&gt;forum post by funkdaddu&lt;/a&gt; helped me on this, so by removing the space FireFox could now download the file as "ourfile.mj".&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Chrome however did not want to play ball. It was still insisting on changing the file extension to ".xml". I guessed it was because we were telling it we serving up text/xml mime/type under a different file extension, I decided to change the response type to "Application/Save" just to see if this would make a difference, and amazingly it did. Amazing!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So there we have it, changing the file name to have no spaces and ensuring that the content type is set to "Application/Save" seems to make all browsers behave at least some what consistently with the Content Disposition header. Its worth noting that Scott Hanselman has a great blog post &lt;a href="http://www.hanselman.com/blog/TheContentDispositionSagaControllingTheSuggestedFileNameInTheBrowsersSaveAsDialog.aspx"&gt; The Content Disposition Saga&lt;/a&gt; which talks alot about how the different of IE handles it. Also GreenBytes has a ton &lt;a href="http://greenbytes.de/tech/tc2231/"&gt;Test Cases for HTTP Content-Disposition header&lt;/a&gt; which I certainly found helpful.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3660413617993832131?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/0Yfm7VXyAlE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3660413617993832131/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/04/content-disposition-in-different.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3660413617993832131" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3660413617993832131" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/0Yfm7VXyAlE/content-disposition-in-different.html" title="Content Disposition in different browsers" /><author><name>Michael James</name><uri>https://profiles.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/2009/04/content-disposition-in-different.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-3855515153656369163</id><published>2009-04-23T16:59:00.000+01:00</published><updated>2011-11-06T00:00:27.118Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="SiteMaps" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Lamda Expressions" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ" /><title type="text">Looking for a URL using Linq and SiteMaps</title><content type="html">&lt;p&gt;I've been off sick from work with Man Flu but this afternoon I was getting bored of staying in bed for the second day so I got out my laptop just to have a play in between blowing my nose.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I wanted to write a quick way of looking up the full url path for a page within a sitemap. The only bit of information I know is the key of the page. Now I knew that I could possibly make use of the IndexOf method. This expects a SiteMapNode of the value you are looking for and returns the index of the node, you then need to get the node out of your collection of nodes, example below.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code class="c#"&gt;&lt;br /&gt;SiteMapNodeCollection nodes = SiteMap.RootNode.GetAllNodes();&lt;br /&gt;int nodeIndex = nodes.IndexOf(new SiteMapNode(SiteMap.Provider, pagekey));&lt;br /&gt;return nodes[nodeIndex].Url ?? String.Empty;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now that method does work, however it felt dead clunky, I was sure I could write a more .Net 3.5 shiny one line way of doing this using Linq. In fact it was dead easy. First I still needed to get all the nodes, SiteMap.RootNode.GetAllNodes(), but I then cast these to SiteMapNode, I could then use FirstOrDefault with a nice lambda expression that matches the key property. Code below. &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code class="c#"&gt;&lt;br /&gt;SiteMapNode node = SiteMap.RootNode.GetAllNodes().Cast&lt;SiteMapNode&gt;().FirstOrDefault(n =&gt; n.Key.Equals(pagekey));&lt;br /&gt;return node != null ? node.Url : String.Empty;&lt;br /&gt;//note: the &amp;lt;/sitemapnode&amp;gt; is not part of the code, the code highlighter JS is randomly adding it.&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Simple, my only concern is that the bigger the sitemap becomes the more memory / slower this becomes, especially if called multiple times per page. It may make sense to cache the sitemapnodecollection for the duration of the page however that's beyond the scope of this brief article.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;What hopefully you can see though is that a little bit of Linq and Lambda expressions can take chunks of code that seem long winded and turn them into nice neat one liners, which I think is usually more readable.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-3855515153656369163?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/jZm5WMkfWzQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/3855515153656369163/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/04/looking-for-url-using-linq-and-sitemaps.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3855515153656369163" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/3855515153656369163" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/jZm5WMkfWzQ/looking-for-url-using-linq-and-sitemaps.html" title="Looking for a URL using Linq and SiteMaps" /><author><name>Michael James</name><uri>https://profiles.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/2009/04/looking-for-url-using-linq-and-sitemaps.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8090897226830933739</id><published>2009-04-22T14:25:00.000+01:00</published><updated>2011-11-06T00:00:27.136Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Packt" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Book Review" /><title type="text">Book Review: ASP.Net MVC 1.0 Quickly</title><content type="html">&lt;p&gt;So this month I again have the privaledge of writing another book review. This time in an area I have particular interest. ASP.Net MVC has recently been released and there are no end of books coming out of the market, one of these being &lt;a href="http://blog.maartenballiauw.be/"&gt;Maarten Balliauw&lt;/a&gt;'s &lt;a href="http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book/mid/300309msa6ak"&gt;ASP.NET MVC 1.0 Quickly.&lt;/a&gt;&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;p&gt;When the book arrived I first noted how it used the traditional orange Packt colour scheme with an interesting picture of a pair of glasses on the beach. This I preferred over the look of the &lt;a href="http://urls.mjjames.co.uk/bookreview1"&gt;last book I reviewed&lt;/a&gt;, however I am yet to work out the significance of the picture if there even is one?&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;p&gt;The book starts by saying that the book will take you through "the essential tasks" and "does not cover every single feature in detail". This is my opinion is not a bad thing. It is not a full reference book like ... but more of a rapid guide to get developers to start using MVC and know the basics preety much everything, you can then get the in depth knowledge as you go along.&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;p&gt;The book covers the following topics, not necessarily in order:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;What MVC Is&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Brief comparison between ASP.NET web forms and ASP.NET MVC&lt;/li&gt;&lt;br /&gt;&lt;li&gt;What a Controller, View and Model is and how you go about creating them in VS&lt;/li&gt;&lt;br /&gt;&lt;li&gt;What the process of a page is and how you handle interactions&lt;/li&gt;&lt;br /&gt;&lt;li&gt;What is routing and what you can do with it&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Customizing the framework&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Using Web Forms features in MVC&lt;/li&gt;&lt;br /&gt;&lt;li&gt;JQuery and AJAX in MVC&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Testing and Mocking&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Deployment&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It then has three appendices which I recommend NOT skipping, It has a full application with source code, information on the MockHandlers available and finally tons of links on where to get more information on topics. The links help to fill in the gaps that the book has left due to its "quickly" approach and for me at least have been the most thumbed pages of the book.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The format of the book is very clear, lots of examples in C#, screenshots where appropiate and well worded. In particular I like areas where Maarten Balliauw takes the time to explain all the options for an attribute. For example in Chapter 4 he outlines Action Method Attributes, rather than just give a brief description of what they are, Marten takes the time to outline briefly all the possible attributes with a simple piece of source code if appropiate. Again this highlights how the book is just trying to make you aware of what exists so when you come to write something you think about what you could use and then go away and find out more if needed. &lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;p&gt;I have to admit I really like the book as an intro into MVC and to get people aware of it, it highlights alot and get's you thinking about design methodologies. It's one I recommend others to read.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Scores&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Presentation&lt;/strong&gt; 8/10 - Overall this book feels well put together and everything is clearly laid out&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Code Examples&lt;/strong&gt; 9/10 - Quite a high score for this, the book it littered with short code snippets and examples but what really does it for me is the example application included in the appendices. Simply working through this highlights everything you have read so far and highlights more. Well worth looking at&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Quality of Content&lt;/strong&gt; 8/10 - Again repeating what I have said earlier but I feel the content has been well put together and arranged in a manner that is clear and conjusive to learning &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Overall&lt;/strong&gt; 8/10 - If you are looking at just finding out about this ASP.NET MVC is all about and just want an outline to get you started this book is for you. It's not claiming to be a reference but a starting block to use to get you started, the links in the back give you some where else to go afterwards. Well worth a read.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-8090897226830933739?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/s9OlPmHsNYA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8090897226830933739/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/04/book-review-aspnet-mvc-10-quickly.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8090897226830933739" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8090897226830933739" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/s9OlPmHsNYA/book-review-aspnet-mvc-10-quickly.html" title="Book Review: ASP.Net MVC 1.0 Quickly" /><author><name>Michael James</name><uri>https://profiles.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/2009/04/book-review-aspnet-mvc-10-quickly.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-1979778224628175965</id><published>2009-03-28T14:41:00.000Z</published><updated>2011-11-06T00:00:27.096Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Google SiteMap Generator" /><category scheme="http://www.blogger.com/atom/ns#" term="IIS" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Google" /><title type="text">Google SiteMap Generator + Input validation failed Error</title><content type="html">&lt;p&gt;Since Google release their &lt;a href="http://code.google.com/p/googlesitemapgenerator/"&gt;Google Site Map Generator&lt;/a&gt; I have been using it on my web server for the sites that I manage. Setting it up and getting it running was fine and I haven't had a problem, that was until this week. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This week I noticed that as I was only letting the generator update the sitemap from actual URL hits quite often a few of my sites aren't hit for a day at a time which was resulting in empty sitemaps. This then causes Google WebMaster Tools to whinge at you which isn't a good thing. So I decided to update my settings to include parsing my IIS Log Files in the hope it would use previous days ones and not generate blank files.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is where I hit a road block. When ever I changed a setting and clicked save the generator would be really useful and tell me that "Input Validation Failed" and to basically sort myself out. I was confused to say the least as everything was fine, no field was highlighted as being erroneous so I ended up giving up and leaving it.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Today I came back to it and tried again but the same error occurred. So I started to poke around and decided to manually update the sitesetttings xml file, usually located: C:\Program Files (x86)\Google\Google Sitemap Generator\sitesettings.xml. And this is when I noticed the issue that was affecting me.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Each site within your IIS setup has a node in the sitesettings xml file, here it has information about it's host name, whether it's setup for sitemaps etc. But it also contains the location of the IIS log files regardless of whether you are parsing them or not. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now a few weeks ago I decided to move all my sites log files from the default location of C:\WINDOWS\system32\LogFiles\{site} to a more convenient location, for this example lets say E:\LogFiles\{site}, now this was all well and good for IIS etc but upon creation of sites the Google SiteMap Generator is logging these locations. So when I had moved the log files the generator was still looking at the old location, a bit of guessing / how I would do it lead me to believe that upon saying parse log files for sitemaps the generator checks to see if it can read the log files, but as they have moved it cant find them and errors. &lt;/p&gt;&lt;br /&gt;&lt;br  /&gt;&lt;br /&gt;&lt;p&gt;Now all I did to fix this was manually do a find and replace on the log file locations within sitesettings.xml saved the file and restarted the generator to find it was finally happy and working OK. Hopefully Google in the next release of this generator will remove this issue / make it clearer what is wrong. Ideally upon startup or even when you choose to use log file parsing it should look at IIS to see if the path to the log files is the same as it has, if not update it before it validates. This would save heartache for a few people at least.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So I'm now happy again with the generator, the problem wasn't that hard to fix and upon spotting it made alot of sense, it just shows what a little bit of investigating can do.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-1979778224628175965?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/75SCPiseNH0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/1979778224628175965/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/03/google-sitemap-generator-input.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/1979778224628175965" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/1979778224628175965" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/75SCPiseNH0/google-sitemap-generator-input.html" title="Google SiteMap Generator + Input validation failed Error" /><author><name>Michael James</name><uri>https://profiles.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/2009/03/google-sitemap-generator-input.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-8288643836216901461</id><published>2009-03-20T19:55:00.000Z</published><updated>2011-11-06T00:00:27.140Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="Packt" /><category scheme="http://www.blogger.com/atom/ns#" term="Books" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Book Review" /><category scheme="http://www.blogger.com/atom/ns#" term="Multi Threading" /><title type="text">Book Review: C# 2008 and 2005 Threaded Programming</title><content type="html">&lt;p&gt;So last month &lt;a href="http://www.PacktPub.com"&gt;Packt Publishing&lt;/a&gt; contacted me regarding sending me a promotional copy of &lt;a href="http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book"&gt;C# 2008 and 2005 Threaded Programming&lt;/a&gt; to review. This is the first time I have been asked to do a book review and decided to take them up on the offer.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Now I have been using ASP.Net for around three years now but I've never had to or decided to look into writing multi-threaded apps so the fact that this book was aimed at beginners meant that I was an ideal target audience for this book.&lt;br /&gt;&lt;a href="http://www.PacktPub.com"&gt;Packt&lt;/a&gt; shortly sent me the book and upon first looking at it thought it looked a bit ugly! I know you can't tell a book by its cover but this cover did put me off, the green and picture didn't do it for me but alas I carried on anyway.&lt;/p&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The book is organised into several chapters and is example driven. What I mean by this is that it doesn't give you bags of theory and then an example, it takes the approach of you following along the code examples and then it has gaps explaining bits and pieces. More on this later. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The chapters within the book are organised in a way that as you progress each chapter delves into multi threading more. First of all it explains what multi threading is, then it looks as basic thread techniques, background workers, debugging multi threaded apps, thread pools all the way up to exploring the new future of multi threaded apps and new framework extensions to help with this. On the whole the chapter organisation made a lot of sense to me and allowed you to use what you had learnt before and build upon it. The one thing that struck me was that I expected ThreadPools to be talked about way before chapter 9 but that’s a minor thing.&lt;/p&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;One of the things I especially liked about this book is that at the end of each chapter you are given a quick pop quiz on the chapters content, this for me at least provided a quick way of ensuring I had understood the chapter and if I hadn't to go back and re read it, so this was good.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;As I mentioned earlier the book is based on learning using examples and less about theory. Personally I'm not a huge fan of this technique; the writer Gastón C. Hillar does try to provide examples that are practical however I find that by simply following these you don't really learn what is going on; you learn how threading roughly works and that it’s there but when you need to use it in a real life application or you need to work out why something isn't working as expected you are left without the knowledge to solve these issues. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I do realise that this book is for beginners and is meant to get developers to look into and start writing multi-threaded apps and not be a complete resource, but personally I would prefer a touch more theory. In particular locking is over looked, what setting a WinForms app to [MTAThread] really means (you can't use dialogues for example). This was probably left out to try and keep things simple for beginners but not discussing locking or exceptions could mean bad practices are picked up and carried into production code.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It is worth mentioning that his book solely focuses on WinForm apps, it doesn't look into WPF or WebForms, and this is both a blessing and a curse in my eyes. With that said  WinForms is simple to learn and the examples really do cover everything you need to get them working so if you have never used WinForms don't be put off reading this book, by the end of it you will not only know more about multi-threading but also how to write simple WinForm apps. &lt;br /&gt; Also the book says that you can use Visual Studio 2008 Standard edition to debug multi threaded apps, I found out that sadly this isn't the case. In order to have the threads debug window you need the Pro edition or above version of Visual Studio.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;br /&gt;Overall I find the book alright, personally the presentation of the book, colour schemes, internal typography could do with an improvement, the headings look like they are in Impact which is wrong on so many levels, and the examples can seem slightly farfetched but the book does cover a lot. As someone new to multi-threading by the end of it I felt confident enough in what I had learnt to write a simple multi threaded WinForm app for work to perform some tests. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Scores&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Presentation&lt;/span&gt; - 6 / 10 - Although it’s clear to read the bulk of the content, the cover and headings for me let it down. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Code Examples&lt;/span&gt; – 7/10 – The code examples are clearly written and cover all the detail you need I feel that they aren’t as real life as they could be which hinders taking what they are meant to show you and apply it to real life scenarios. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Quality of Content&lt;/span&gt; – 7/10 – Overall I felt the quality content was quite good, potentially a bit over the top in places about being a “multi threaded guru” but overall OK. One down fall was to say that Visual Studio Standard edition can be used to debug multi threaded apps when it can’t. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Overall&lt;/span&gt; - 6.5 / 10&lt;br /&gt;In light of everything I'm not going to suggest this is a book that everyone should read / own unlike over books like the pragmatic programmer etc. However if you are looking at learning about multi-threading and want something to ease you into it then this is for you, it will cover the basics of everything you need to know and what to expect in the future.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-8288643836216901461?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/BALnFnylBqY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/8288643836216901461/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/03/book-review-c-2008-and-2005-threaded.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8288643836216901461" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/8288643836216901461" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/BALnFnylBqY/book-review-c-2008-and-2005-threaded.html" title="Book Review: C# 2008 and 2005 Threaded Programming" /><author><name>Michael James</name><uri>https://profiles.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/2009/03/book-review-c-2008-and-2005-threaded.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-2088695286535567324.post-4848675661663548599</id><published>2009-03-19T23:35:00.000Z</published><updated>2011-11-06T00:00:27.129Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Build Error" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Type" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips and Tricks" /><title type="text">MVC Snippets: must be a reference type in order to use it as parameter 'TModel' in the generic type or method 'System.Web.Mvc.ViewUserControl'</title><content type="html">&lt;p&gt;Recently I have been playing with &lt;a href="http://asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, in particular I have been building myself a new website. I thought it might be good to post any peculiar things / lessons I learn during this build. Tonight I stumbled across one of these lessons. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;When you strongly type a view or partial view the type must be a reference type. Otherwise this means you get a HttpCompilation Error: "your data type" must be a reference type in order to use it as parameter 'TModel' in the generic type or method 'System.Web.Mvc.ViewUserControl&lt;TModel&gt;'. Initially I couldn't figure out what this meant as I was passing my type through, it existed etc. However it was then I realised I had declared my type as a struct not a class.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;If you are unsure of the difference between a class and a struct I recommend looking it up, the gist of it is that a class is a reference type and a struct isn't. As a struct isn't a reference type you can save memory due to it not having to allocate additional memory for referencing each object, this is great for short structures, but not for models in ASP.Net MVC&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;After changing my type to a class all was sorted and my view could compile again. A lesson learned, one of many I am sure ;) &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2088695286535567324-4848675661663548599?l=blog.mjjames.co.uk' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Mjjames-WebDeveloper/~4/WyHV9AXQXCE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.mjjames.co.uk/feeds/4848675661663548599/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.mjjames.co.uk/2009/03/mvc-snippets-must-be-reference-type-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4848675661663548599" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2088695286535567324/posts/default/4848675661663548599" /><link rel="alternate" type="text/html" href="http://feeds.mjjames.co.uk/~r/Mjjames-WebDeveloper/~3/WyHV9AXQXCE/mvc-snippets-must-be-reference-type-in.html" title="MVC Snippets: must be a reference type in order to use it as parameter &amp;#39;TModel&amp;#39; in the generic type or method &amp;#39;System.Web.Mvc.ViewUserControl&amp;#39;" /><author><name>Michael James</name><uri>https://profiles.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/2009/03/mvc-snippets-must-be-reference-type-in.html</feedburner:origLink></entry></feed>

