No Free Time

Because my therapist says I need to let things out

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 »

Calling a footer a footer

Posted by andrewmyhre on September 4, 2009

SharePoint MVP Randy Drisgill points out that if you’re creating a stylesheet for a Sharepoint site with a rule for #footer meaning, ostensibly, the footer for the page, you won’t get the result you intended.

That’s because when the guys created the SharePoint engine they decided to use the element id ‘footer’ for particular div that SharePoint outputs in the middle of your page. Nice going guys! I can’t wait to explain this to the HTML team at our agency.

Posted in sharepoint | Tagged: | Leave a Comment »

New Digital Wall

Posted by andrewmyhre on August 19, 2009

I launched a new Digital Wall this week.
I want to rewrite it already :) .

http://wall.tequila-uk.com/

Posted in Digital Wall | Leave a Comment »

Microsoft.Expression.Blend.Silverlight.targets was not found

Posted by andrewmyhre on July 29, 2009

Recently I encountered the following error when trying to open a Silverlight 3 project:

01

Unable to read the project file ‘X.csproj’.
The imported project “c:\program files\MSBuild\Microsoft\Expression\Blend\3.0\Silverlight\Microsoft.Expression.Blend.Silverlight.targets” was not found.
Confirm the path in the <Import> declaration is correct, and that the file exists on disk.

The scenario is that I had fired up the new RC of Expression Blend 3.0 and created a Silverlight 3 project. At some point along the way I had also been messing with a TextBlock and I had ticked the ‘Embed’ checkbox to embed the font I selected into the project. Then when I tried to open the project on another machine I was met with the above error and my Silverlight project wouldn’t load.

Unni Ravindranathan was helpful enough to point out that when using Blend 3 features such as embedded fonts you must have the Blend 3.0 SDK installed, and sure enough that’s exactly what I’d done. I had thought I needed to installed Expression Blend 3.0 on my machine in order to open the project, but the SDK was all I needed. Unni is Program Manager on the Expression Blend team and I appreciate his quick and direct help.

I’d like to know why I could always embed fonts in Silverlight projects without needing Blend 3.0 but I’m sure there’s a perfectly reasonable explanation. Not to mention – why is the SDK not an optional part of the Silverlight 3 SDK install? It’s only a 3mb download…

Grab the SDK here: http://www.microsoft.com/downloads/details.aspx?FamilyID=F1AE9A30-4928-411D-970B-E682AB179E17&displaylang=en

Posted in silverlight | 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 »

Integrating Google Analytics with your Silverlight Streaming application

Posted by andrewmyhre on June 18, 2009

No dice. Can’t be done. Here’s why.

To track an action you need to invoke the trackPage() function defined in ga.js. The function must be invoked from the same domain registered in your Google Analytics account, in my case that’s “andrewmyhre.com”. So in order to track events from my Silverlight app I need to call up to the parent frame and invoke a function to track the event. Unfortunately, because my Silverlight application is running on an entirely different domain (something like “silverlight.services.live.com”) the browser throws a “Permission denied” error when I try to invoke parent.trackPage().

There is no way around this. That behaviour is by design, in order to prevent cross-site scripting attacks.

So I’ve moved the Silverlight and media files to my hosting account where I can load everything under my own domain. That’s cool because I have 1gb of space there and the total media payload is around 500mb. It’s also a real shame, it was cool to be using a new beta service like Silverlight Streaming, but unfortunately event tracking is a deal breaker for me.

Maybe there are some coders out there who know how to get around this, or maybe the Silverlight Streaming team have a workaround… I can’t really see it happening though. Shame.

On the bright side though, the videos seem to be streaming much more quickly now! :/

Posted in silverlight | Tagged: , | 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 »