No Free Time

Because my therapist says I need to let things out

Archive for the ‘Uncategorized’ Category

Linq to SQL and Serialization : A circular reference was detected while serializing an object of type [whatever]

Posted by andrewmyhre on November 4, 2009

Okay so I created a Linq to SQL model today. It includes tables for Blog Posts and Blog Comments which have a one-to-many relationship, hence a BlogComment has a .BlogPost property and a BlogPost has a .BlogComments property. Pretty standard.

When I attempted to serialize a collection of BlogPosts and their related BlogComments I was met with the following error:

A circular reference was detected while serializing an object of type BlogPost.

Fairly obvious why – the serializer is working through each property on a BlogPost using reflection, then enumerating each comment on the blog post, enumerating each property on the comment which includes a reference back to the blog post – which is where the circular reference joins up.

Obvious problem, but how to get around it? What I actually need to do is instruct the XmlSerializer to ignore the BlogComment.BlogPost property – I want it to enumerate the comments attached to a blog post but I don’t want it to walk back up to the blog post. To accomplish this I don’t want to have to mess with my DBML file or the C# class definitions, because as soon as I modify the database in the future I’ll have to reimplement those changes. A partial class implementation won’t help me because I need to modify the original class, not patch new functionality onto it. I was thinking I needed to add an [XmlIgnore] attribute somewhere, and that this would be a nightmare.

Well it turns a much simpler solution is to just mark the relationship as an Internal property in the Linq to SQL designer.

linq_to_sql_designer_association_property

This works because the XmlSerializer only serializes public properties.

Posted in Uncategorized | 1 Comment »

AltNet Beers October 28

Posted by andrewmyhre on October 27, 2009

AltNet Beers tomorrow night (October 28, 2009) is being hosted by Tequila London at their office at 82 Dean St in Soho. Nearest tube is Tottenham Court Road station which is on the Central and Northern lines.

Map with directions from the tube station: http://tinyurl.com/tequilalondon

To get there after StackOverflow DevDays your best route is to walk north from Kensington Town Hall to Notting Hill Gate station which is on the central line. From there travel east to Tottenham Court Road station.

Directions from Kensington Town Hall to Notting Hill Gate: http://tinyurl.com/ylrvekz

See you at Tequila!

Posted in Uncategorized | Tagged: | Leave a Comment »

I’m Back and a Non-Programming Related Reference

Posted by andrewmyhre on July 16, 2009

Well I’m finally back from an extended stay in my home country, New Zealand. The particulars that brought about my prolonged visit to NZ are boring and long-winded so I won’t go into them here. While I’m grateful to my employers for allowing me to work remotely while I was over there, I’m also thoroughly grateful to be back home, in London. Yes, my time back in NZ has brought the realisation into stark relief that London is, presently at least, home. It’s a nice feeling.

Moving swiftly to the point of this post, that being what I want to share.

It’s a testament to the connected world we live in that keeping up to date with the latest findings and speculations of scientific research no longer requires subscriptions to obscure publications and painstaking focus, analysis and consideration. Nowadays you can just have that stuff piped straight into your computer apparatus and consequently into your brain, in a much more passive and relaxing way. How, you may ask? YouTube!

I was introduced to Daniel Dennett a few weeks ago, and I’ve added him to my list of Great Human Beings. If you don’t know who he is, here’s a nice taster for his work: Ants, Terrorism, and the Awesome Power of Memes. It’s a quick TED lecture, so it’s a sample of his ideas which is suitable for untraumatic digestion, whatever your persuasion. If you watch that video and find yourself hungry for more, there are schools of in-depth, full-length lectures available on the YouTube also, so you know how to plunge further into this sumptuous mind-steak. This lecture for instance is a fuller expansion on the TED talk linked above. Let me google that for you.

I’d be interested in hearing from anyone at all in London who finds the above interesting and would enjoy meeting up to, er, talk utter nonsense about it? Leave a comment or hit me on twitter. If there are, say, half a dozen such doomed souls I’ll organise something.

Posted in Uncategorized | Leave a Comment »

Google Chrome OS

Posted by andrewmyhre on July 9, 2009

Posted in Uncategorized | Leave a Comment »

Design Your Experience

Posted by andrewmyhre on June 16, 2009

Gratuitous money shot

So I deployed a personal website last week which I was quite happy with at the time but over the last few days I’ve thought of some features I wanted to add. I wanted visitors to be able to do a couple of things when they view my website:

  • pause and skip the music (not everyone likes minimal-tech-dub)
  • choose which videos are in rotation
  • i also want the UI not to get in the way when not in use

Everybody needs options

So I added an options panel. It presents you with a pause/play button and a skip button to control the music. Most people, including myself, hate it when websites play music and you can’t stop it so here’s the option. I used the WebDings font for the button icons which I copied from my windows folder into my solution and embedded it.

Further below in the options panel you have a list of checkboxes which determine what kinds of videos are circulating in the pool that can be selected to play. Uncheck the ‘cows’ tag to any videos everything featuring cows, for instance. I use System.Linq methods to regenerate the pool on each click, like so:

if (c.IsChecked.HasValue && c.IsChecked.Value)
{
tagSet = tagSet.Union(new string[] { tb.Text }).ToArray();
}
else
{
tagSet = (from t in tagSet where !t.Equals(tb.Text) select t).ToArray();
}
string[] tagSet = new string[10];
if (c.IsChecked.HasValue && c.IsChecked.Value)
{
    tagSet = tagSet.Union(new string[] { tag }).ToArray();
}
else
{
    tagSet = (from t in tagSet where !t.Equals(tag) select t).ToArray();
}

In the above snippet, tagSet is my collection of active tags, it’s just a string array as I’ve indicated with the declaration on the first line. The first logic branch is adding the selected tag to the array using a Union() and the second logic branch removes it by performing a select where not equal. I wonder if this is awfully inefficient.

Finally at the very bottom of the options panel there are some blurry lines which now and then shrink and expand. These are gauges which indicate the current buffering and download progress of the videos. If you look closely you can see four distinct lines. The 1st and 3rd lines indicate buffering progress while the 2nd and 4th lines indicate download progress.

Now you know what these do

What’s actually happening behind the scenes is that while one video is playing another one is silently buffering. Once the background video source is ready to play and the timing is right a cross-fade transition will occur. As soon as the transition is completed the video source that was previously in the foreground begins buffering the next video in the pool, and so on the so forth. I can see what’s happening by switching into my diagnostics view:

Diagnostics view shows both video sources

I’m reasonably happy with the way that the options panel slides out smoothly to meet the mouse cursor as you move it towards the left-hand side of the screen, and retracts discretely in the same way. I’ve wanted to experiment with this method of revealing/hiding UI for a while and I like this as a prototype. I’m not a designer though so I’m pretty sure the whole thing could be much slicker.

One more thing I’ve added is a little ‘loading’ note with initial buffering gauges. There are two separate white bars which indicate the loading process – these are for source A and source B which I load both of initially before video starts. Sometimes however (actually, quite frequently) Silverlight is loading a cached video, so it doesn’t need to buffer in which case Silverlight reports a buffering progress of 0.0. This isn’t the desired behaviour in my case, because it means I have to set up some hacks to detect this case and show a full buffering gauge instead. From my point of view this is a bug.

Posted in Uncategorized | Tagged: , | Leave a Comment »

Silverlight Streaming and Google Analytics

Posted by andrewmyhre on June 12, 2009

I can’t seem to find a way to implement page/event tracking from Silverlight using Google Analytics when hosted using Silverlight Streaming. The usual solution to do this with with a regular Silverlight app is to reference the Google Analytics ga.js script and call HtmlPage.Window.Invoke() from Silverlight. But a difficulty arises because that javascript is executed in the context of the Silverlight application, which (in my case at least) is inside an iframe, and therefore can’t use the ga.js script.

One of the features available with creating a Silverlight Streaming application is to include javascript files with your Silverlight app so that you can use them from Silverlight, but ga.js isn’t my script so I can’t do that. Unless I downloaded the obfuscated version using Firebug or something… but… ugh!

I’m sure there will be some combination of HtmlPage.Window.Parent.Parent.Whatever I can use to do what I want to do, but I’m already into my second glass of wine for the evening and my brains starting to go on holiday. Any UK devs just waking up want to tackle this problem?

I guess you could simulate the issue yourself by adding a new .html page to your standard Silverlight hosting website containing an iframe with loads the Silverlight test page. In fact that’s how I’ll start tackling it tomorrow.

For now, I’m going to call it a night.

I see I’m getting a little bit of new traffic/twitter follows which I guess I can attribute to my new website… not because I think it’s brilliant but because there aren’t many actual cases of websites making use of Silverlight Streaming, so the Silverlight enthusiasts on Twitter seem to be retweeting. Maybe I’m wrong but if I’m right, thanks everyone, and please provide feedback about what I’ve made. I’ll be really pleased to hear from you.

Posted in Uncategorized | Tagged: | Leave a Comment »

The Windows Hosts File Just Saved My Skin

Posted by andrewmyhre on May 4, 2009

I had an issue today where a virtual machine couldn’t connect to our team foundation server. I had connected the client machine to the VPN, could ping by IP but not by hostname. I suspect it was to do with the fact that my VM is not part of the AD. I didn’t want to connect it to the AD because keeping a VM off the domain saves headaches. So after a few moments trying to think of a workaround I remembered the Windows Hosts file. I added an entry to map the IP for the TFS server to the domain name it should have and – voila – my visual studio solution was able to connect as normal. I’ve never ever used that file to do anything useful before, so this was a first. :)

Posted in Uncategorized | Tagged: | Leave a Comment »

One of those cookie quirks

Posted by andrewmyhre on January 12, 2009

Today I discovered a weird thing that happens if you’re creating an authentication cookie and you’re setting the domain of the cookie.

Let’s say my site is http://mysite.somedomain.com and I set the domain of the cookie to “mysite.somedomain.com”. If I attempt to log in the cookie won’t be saved, meaning I can’t log in. Setting the cookie domain to “somedomain.com” on the other hand works fine. Is this weird behaviour or am I just cookie-ignorant?

Posted in Uncategorized | Leave a Comment »

A wonderful trick for discovering the public key token of an assembly you’re building

Posted by andrewmyhre on January 7, 2009

Follow the steps in this article to add a simple shortcut to Visual Studio that will tell you the public key token of the assembly you’re working on. My previous method was: strongly sign the assembly, drop it in the GAC, open the GAC and look up the key token…. so I’m very pleased to have discovered this!

Posted in Uncategorized | Tagged: | 2 Comments »

London .Net User Group 28 January

Posted by andrewmyhre on January 7, 2009

The next London .Net User Group takes place 28 January from 6pm at the Tequila London office (map). I *think* I’m doing a grok talk.

Posted in Uncategorized | Leave a Comment »