Richard Howells' Blog
Author: RichardHowells Created: 11 March 2008
Notes about the interesting (my definition) bits I discover in my programming. Plus, of course, the occasional tar pit.

Start here with lots of good stuff from Tomas

As mentioned, the JSON serializer returns Dictionary<string, object>.  This is inconvenient in a strongly typed environment like C#.   The entries in the dictionary vary through being both ArrayLists and further Dictionaries.  In C# we’d normally need to keep casting them to the correct type before we access properties and methods.

Enter dynamic!  In C#, dynamic allows you to simply assume that methods and properties will be there at run time.  That truth is checked at run time so you may see exceptions if you are wrong.  It did allow me to retrieve a JSON result from Google's Geocoding service and extract data from it like so…

                var geoData = jsSerializer.Deserialize<Dictionary<string, dynamic>>(rv);

                if (geoData["status"] == "OK")

                    latitude = Convert.ToSingle(geoData["results"][0]["geometry"]["location"]["lat"]);

Not the prettiest code in the world, but short.

As Tomas points out in his article, you can get to the same answer, more strongly typed, by creating a series of classes to map the JSON.  But when you want a quick and short answer, this will do.


Read More »

I was trying to upgrade a VS2008 project to VS2012 – After upgrade I had the message ‘Application’ is ambiguous in the namespace ‘Microsoft.Office.Interop.Excel’

Back in the original VS2008 project there was a Warning message about unable to find an assembly.  It seemed to be related to Excel, but had not stopped the app working in years and had been ignored.  Deciding that the original complaint in VS2008 was probably the root cause of the ambiguity I set out to try and fix it.

Eventually I tracked it down.  The project had a COM reference to Excel and a .Net reference to the Excel Primary Interop Assembly.  I only discovered this by poking about in the vbproj file with a text editor.  I didn’t find a way of seeing, or removing, the COM reference through the VS UI.  Eventually I excised the entire COMReference node starting COMReference Include="Microsoft.Office.Interop.Excel" using the text editor.  Saved the project and all was well.  Back in VS2008 it built without the warning.  Converted to VS2012 it built without the ambiguity message.

Read More »

I just tried setting up a staging version of a site.  I used _Staging as a suffix everywhere.  I found that IE would not let me login. (It worked with Chrome.)

I changed the url to use instead of the suffix and the problem went away!

My network (largely Windows 7 machines) partly stopped working, from my laptop.  Explorer would not browse to other machines, the network always showed empty.  OTOH I could map drives by IP address and I could ping them cheerfully.

Other machines seemed unaffected - it was just me.

Hours of Googling got me nowhere.

Yesterday I just lucked onto it.  On my laptop, the windows firewall thought my home network should be treated as public.  Setting it back to a private network seems to have fixed all my woes.

Yahay! :-)

A – Because the browser does not work the way you think it should.  When you press F5 the browser requests the resource it is currently on AND resources directly linked to that page – images.  I set up a web site to serve images with an expiry time.  The idea is that most of the graphics in the skin change rarely.  The browser does not need to down load a fresh copy for each request.

Fired up fiddler, pressed F5 a few times and got stumped.  Every time the browser was making a fresh request for each image.  When I moved to requesting the page via a link, even a link on the same page, I saw the cache work as I expected and the requests vanished.


 Add this (or similar) to the URL

"?SkinSrc=Portals/_default/Skins/MinimalExtropy/index full"

I posted this so that I would be able to find it easily for myself.  You can do somthing similar with ContainerSrc too.

Shows how to create a set of hierarchical check boxes.  Checking/unchecking a box at the higher level automatically checks/unchecks the ones at the next level down.

Read More »

I wanted a very simple logging table. I wanted it to be time ordered and I decided to include a smalldatetime column in the primary key.

This failed badly with Entity Framework. Inserts resulted in a failure message indicating that zero rows were affected. This because a .Net DateTime value is not guaranteed to round trip into SqlServer and back. The SqlServer datetime (and smalldatetime) column types cannot store values with the same precision as the .Net DateTime type.

EF uses a query like this [1] to store the row and recover the freshly inserted identity column. The DateTime value is ‘rounded’ to suit SQL Server as it is inserted and the Select fails to read the freshly inserted row back because the datetime values are no longer equal.

I solved this by removing the datetime column from the primary key. It was not crucial for it to be in the primary key.

Moral – do not mix datetime and identity columns in your primary key.

[1] Entity Framework Generated Query exec sp_executesql...
Read More »

 You need all these MIME types.  Most of them are probably inherited from higher up but I needed to add a couple - could have been a version thing!


I found this StackOverflow question useful

 If you came on the 327 course (C++) I taught at Learning Tree week of 16Feb and have been waiting for your follow up email please accept my apologies.

Somehow I lost the pile of papers with your email addresses and I have no way of contacting any of you.  Send me an email address and I'll send you the promised material.

Copyright 2002-15 by Dynamisys Ltd