Loose Lips...

Updated on Thursday, November 12, 2015

LooseLips

XamlParseException and 256x256 icons

Updated on Saturday, September 29, 2018

When testing out a WPF app on XP I got an unhelpful XamlParseException error report. 

I was a little puzzled because I was hooking up error reporting in App.xaml.cs:

My error handler was attempting to create a XAML window to report the error, and evidently this was bombing out as well triggering the good doctor Watson. I added a MessageBox call instead and discovered that the XamlParseException was wrapping a FileFormatException and the stack trace indicated that the problem was with setting the icon for the window. After removing the icon the app started up fine. Weird.

It turns out that WPF chokes on a compressed 256x256 icon on XP and Vista (Windows 7 seems to cope fine). Saving the icon without compression fixes the problem. I use IcoFX and you can set this at Options -> Preferences -> Options -> Compress 256x256 images for Windows Vista. Of course the consequence is that the icon is a couple of hundred kilobytes larger.

Space and multibyte character encoding for posting to Twitter using OAuth

Updated on Saturday, November 2, 2019

I've spent the last day learning how to use OAuth and XAuth to post to Twitter. There are rumblings that Twitter will start to phase out basic authentication later this year, and more importantly you can only get the nice “via...” attribution if you use OAuth (for new apps, old ones are grandfathered in).

I coded up my own OAuth implementation, referring to Twitter Development: The OAuth Specification on Wrox and the OAuthBase.cs class from the oauth project on Google Code. Both are great references, but both fail with multibyte characters. The problem is that each byte needs to be separately escaped. OAuthBase.cs encodes characters as ints rather than breaking out the bytes and the Wrox article incorrectly suggests using Uri.EscapeDataString(). 

Here's a method to correctly encode parameters for OAuth:

NoEncode chars is a list of the permitted characters:

An impact of this encoding is that spaces must be encoded as %20 rather than plus. I was worried that each space would end up counting as three characters towards the 140 character limit. I tested this and it isn't true, so use HttpUtility.UrlEncode() to calculate the number of characters in the post OAuthUrlEncode() or similar to actually encode post parameter.

Reviews and links for March 2010

Updated on Friday, February 24, 2017

Juliet, Naked by Nick Hornby

3/5

Classic Hornby. It's fairly close to High Fidelity with it's themes of love and music obsession-ism and so feels slightly too comfortable but certainly worth a read if you're a fan. 3/24/2010 2:00:00 AM

 

The Girl with the Dragon Tattoo (Millennium, #1) by Stieg Larsson

3/5

Slow, but highly atmospheric mystery. The first half of the book is dedicated to setting the scene and then the pieces start to fit into place like a glacier melting. The pace makes the occasional punctuation of extreme sexual violence all the more shocking. Fun enough, so I'll probably read the rest of the trilogy and try to catch the film (which has to be a profoundly truncated version).3/22/2010 2:00:00 AM

 

Practical WPF Charts and Graphics by Jack Xu

4/5

Be aware that this book is 90% code, 5% mathematics and 5% explanation. This isn't a criticism, Dr. Xu builds up a complete charting library that includes 2D, WPF 3D and manual 3D methods. The mathematics covers the theory and practice of 2D and 3D transforms as well as techniques for smoothing, interpolating and trending data. It's a fast read to get a sense of the content and then a great reference work to dip back into as needed. 3/14/2010 3:00:00 AM

 

C# Design and Development: Expert One on One by John Paul Mueller

1/5

This book is just atrocious. Each section sells itself as providing all the information you need about a certain topic, then provides trivial and often incorrect or at least highly subjective details. A couple of examples:

The chapter on error handling makes the point that you should catch the most specific Exception possible, but then goes on to demonstrate catching a FormatException, a DivideByZero exception and then just System.Exception. The whole point is to avoid catching Exceptions that you can't handle. There's a legitimate debate here between trying to plaster up the cracks with general catches and letting the application die with a useful stack, however this book doesn't discuss it. There's also very brief coverage of creating your own derived Exception but it doesn't touch on serialization.

Serializing an XML file is somehow included in the section on "Special Coding Methodologies", and labors over calling both .Flush() and .Close() on a StreamWriter. Despite the fact that you only need to call Close(), and that StreamWriter is IDisposable and so a using statement is really the way forward for this example.

I could go on, but won't. Avoid. 3/8/2010 2:00:00 AM

 

Links

- Dorothy Erskine Park Exists from Spots Unknown (Must go find this park.).

- Casttoo from jwz (I want to break my arm again...).

- Woman murdered over Facebook photo from BBC News | News Front Page | World Edition (Somehow I don't think the photo being on Facebook was the important part of the story...).

- Petition against Pope's UK visit from BBC News | News Front Page | World Edition (A better petition would be to get the Pope and Dawkins together on Question Time.).

- 'Heart risk' at football stadiums from BBC News | News Front Page | World Edition (Surprisingly few are equipped to remove gall stones as well.).

- Postal Service's emerging model: Never on Saturday from SFGate: Top News Stories (How about once a week. While you're at it recycle the junk at the post office and don't bother hauling it out for delivery.).

Email marketing - don't shoot yourself in the foot

Updated on Friday, February 24, 2017

If you send email to customers it's important that you let them know where the email will come from and then use then use this address consistently. Using different email addresses is a recipe for getting trapped in spam filters. This is equally important for marketing and other messaging like bills and canceled flights.

I bring up flights because I'm flying to the UK later today and was planning to return on Sunday. British Airways' Cabin Crew is going on strike this weekend and my return flight has been canceled. Instead of sending a text message BA tried to notify me by email. This would have been fine if they used the address they've used for years, but instead they used a new address and a new domain. In fact in the process of canceling and re-booking I (eventually) got email from britishairways.com, my.ba.com, email.ba.com and pop3.amadeus.net.

Since I've had the same email address for twelve years now I get a fair amount of spam. I use SpamArrest to keep myself sane:

94.9% of my email is spam. Since I started using the service SpamArrest has eaten 482,494 messages for me. I'm far from alone in using white list based email filtering so if you want your message to get through transparency and consistency are the way to go.

Is Intuit Insane?

Updated on Wednesday, February 22, 2017

Yes.

Some more color. I use Intuit's assisted payroll service, which is fantastic. You run payroll straight out of QuickBooks and Intuit handles all the tax disbursement and filing for you.

I got an email today with an attachment called securedoc.html claiming to be a message from Intuit. The idea is that you open the attachment and then login to view the message.

It really couldn't look any more like a phishing email, however I called Intuit and remarkably it's a real message. They seriously expect me to open an email attachment and provide account information. The support person at Intuit was able to read the message to me and it was just a routine acknowledgment that some tax rates had been updated.

Intuit is seriously training its customers to fall victim to phishing attacks. The right approach would be to say that a message is available and to log in to your account to retrieve it, or better still to send a message through the existing system in QuickBooks. Securedoc.htm is just begging customers to provide their account information to the bad guys.

Intuit's payroll service stores bank account information, employee Social Security numbers and other data that you really don't want to expose. If you're an Intuit Payroll customer please call and complain. If you've received one of these messages I'd also recommend forwarding it to [email protected], their address for reporting phishing attacks. 

 

Reviews and links for February 2010

Updated on Friday, February 24, 2017

Programming WPF by Chris Sells

4/5

A highly detailed and well written reference to WPF. Note that this second edition is still based on Visual Studio 2005 / .NET 3.0 so a little out of date now. I still found the book to be very useful and would recommend it both for picking up WPF basics and to refer back to for more advanced topics when needed.2/26/2010 2:00:00 AM

 

Professional C# 2008 by Christian Nagel

4/5

I'm in the process of upgrading to VS2008 and loved the 2005 version of this book so picked up the 2008 update. It's a broad language and framework reference, perfect for understanding what's available in .NET 3.5 and how to get started. My only complaint is that it could have used a "what's new" section or guide to separate out completely new technologies from those familiar from .NET 2.0. Not a big problem though, it's easy to skim through the old stuff and then pay attention when you reach something new. I'll probably pick up the 2010 version in 2015 or so ;)2/15/2010 2:00:00 AM

 

Links

- UK NHS urged to buy Fairtrade tools from BBC News | News Front Page | World Edition (Fair enough, but what about having developing countries pay to train doctors and nurses and then poaching them to work for the NHS?).

- Brown 'upset' by bullying claims from BBC News | News Front Page | World Edition (And when he finds those responsible he's going to turn purple, squint and twat them.).

- CBS runs free ad for "magic" energy box from Boing Boing (A slightly more skeptical take. Magic box plus natural gas...).

- French halal burger sparks appeal from BBC News | News Front Page | World Edition (So eat somewhere else. You're in France and not about to starve.).

- One inch equals $30,000 in online dating world from Boing Boing (I'm worth $2.2 million :)).

- Video: Mantis vs. Cursor from Boing Boing (OK, I need a Preying Mantis to entertain me like this while I work...).

- Toyota recalls 8,000 US vehicles from BBC News | News Front Page | World Edition (And they're not even real propellers. They're just the joke ones you can attach to your tow hitch.).

- Britain reveals how U.S. treated detainee from SFGate: Top News Stories (Miliband against the "principle of their disclosure by an English court against U.S. wishes"!).

- Mariposaaah!!! from Spots Unknown (Feels steeper walking up it.).

BlogEngine.NET most popular pages widget using Google Analytics

Updated on Wednesday, February 22, 2017

I finished off my BlogEngine.NET migration yesterday missing a couple of useful sections from the previous incarnation of this blog. The first is a list of the most popular posts based on Google Analytics data. I've just finished porting this from a UserControl to a widget for BlogEngine.NET. To use this just download and extract this zip file to your widgets directory:

MostPopularFromGA.zip (5.22 kb)

You can see the widget in action under the Most Popular heading to the left if you're reading this post on the blog.

Most of the settings should be pretty obvious. The Google Analytics profile is the exception. This isn't the ID included in your tracking code. To get the profile log in to Google Analytics and click Edit next to the profile you want to use. At the top of the page you'll see a Profile ID. You need to use this number prefixed by ga: (i.e. ga:1234567). Once you have this and your account credentials entered you should be up and running.

The Post must match settings is a regular expression used to filter the Google Analytics report to only include blog posts. The default value corresponds to a default BlogEngine.NET install and only includes pages that start .../post/ (the regular expression is ^/post/). If your posts are under .../blog/posts/ then just update accordingly (^/blog/posts/). If you want to include the most popular pages regardless of the path just leave this setting blank. 

If you have any questions or feature requests leave a comment below. 

Migrating from Blogger to BlogEngine.NET

Updated on Friday, December 27, 2019

(Update June 22, 2010: I've released a tool, Blogger2BlogML, that converts Blogger's ATOM export file to BlogML. I ended up doing this because of problems with comments when I migrated this blog — I had to fix these up manually which was painful. I'm now working on some larger blogs where this would be impossible…)

In January I got an email from Blogger announcing that they're killing FTP support. Apparently only 0.5% of Blogger blogs are published using FTP and it's a huge pain to support, mainly because many hosting providers restrict FTP access to certain IP addresses and if the Google servers running Blogger that moment aren't listed it's technical support time. 

Fair enough, but a bit painful for me as I have five blogs running on top of Blogger. I need FTP publishing as the templates I use end up running as ASP or ASP.NET pages. I Thought He Came With You is the first to move - if you're reading this post then it's up and running on BlogEngine.NET. This is an open source ASP.NET blogging platform. If it works out for this blog over the next month I'll start migrating the others. 

Getting up and running with BlogEngine.NET is easy enough - download the latest release and follow the getting started guide. I added the default install to a new Visual Studio web site project and was able to run it fine in the development server, no need to configure IIS. 

The challenge was moving posts and comments from Blogger into BlogEngine.NET. BlogEngine.NET happily imports and exports BlogML, Blogger spits out it's own Atom export format

Luckily Aaron Lerch has knocked up a PowerShell script to export Blogger to BlogML. This takes your Blogger ID as a parameter and exports all the blogs associated with that ID. You can just pull the <blog> element you need out of the export if necessary. If you use this tool follow the syntax closely from the example on the post. If you're new to PowerShell run this as administrator to start with and enter "Set-ExecutionPolicy RemoteSigned" to give permission to run the script. Then exit and run a non-admin instance of PowerShell to run the script.

After getting the export BlogEngine.NET refused to import it. I kept getting an invalid username or password error from the BlogML importer. Digging into the code a bit I found that a crash was occurring in api/BlogImporter.asmx when a blank category was passed to AddCategories(). I patched this function to skip blank/null categories and was then able to import successfully. I added a bug report for the problem so please vote for it if you hit the same issue.

The blog was in pretty good shape after the import. Categories were lost so I had to create them again in BlogEngine.NET and then apply them to each post. I also found that the date for comments had been set to the date they were imported. This can be fixed by editing each post directly (the files in App_Data\posts). I fixed the timestamps and also added back the URL for each comment where I had one from Blogger. I also edited my own comments to match my new BlogEngine.NET account so they got decorated as "by the author".

At this point the blog was good to go, but using the default template.

I've now whipped up a new template to match the old blog - I was pleasantly surprised by how easy this was to do. At this point I Thought He Came With You is going live on BlogEngine.NET. 

Almost everything is working at this point. I had a couple of user controls I need to move over - one shows the number of people who haven't visited the blog, the other figures out the most popular posts using the Google Analytics API. I'll see if I can implement at least the latter as a Widget so that other people can use it - watch this space (Update - now available here). 

Overall, I'm impressed. I resisted the urge to just write my own blogging platform which is a testament to how easy it is to both get BlogEngine.NET running and to customize the look and feel. Now I just need to work up the enthusiasm to do the same for my remaining four Blogger based blogs...

Catfood.Shapefile.dll 1.10

Updated on Sunday, May 3, 2020

I've just released v1.10 of my ESRI Shapefile Reader (Catfood.Shapefile.dll). This is a .NET 2.0 forward only parser for reading shapefile content.

Sharon Tickell was kind enough to report two bugs with suggested updates. These have both been fixed in 1.10.

While working on these fixes I also discovered that there are no 64-bit Jet drivers (since releasing the first version I've upgraded to a 64-bit box for development). This is an easy fix, just target any application using Catfood.Shapefile.dll at x86. I've updated the demo application accordingly.

Download Catfood.Shapefile.dll from GitHub.