Annoying C# Web Exception …

System.Net.WebException

The request was aborted: The request was canceled.

Cannot close stream until all bytes are written.

If you’re getting that exception, make sure that the timeout for the webrequest is set sufficiently to handle the request. The default as of .NET 3.5 SP1 seems to be 100 seconds. I’m working on an fix to SnugUp and discovered that large files would throw the exception above. I thought it must be a problem on the SmugMug side, but couldn’t come up with a rational reason why it would just fail with my application … and then it dawned on me that it was closing the stream early because it had exceeded the timeout!

So, if you’ve seen that exception, and can’t figure it out … consider checking the timeout. (Also, verify the content-length is set properly – that’s another reason this exception might be thrown).

Creative Gift Carding …

My parents, on Christmas Eve wanted to surprise everyone with a gift card to a store. But for fun, they wanted it to be a bit random. So, they taped a gift card to the bottom of all of the plates (in a buffet style dinner), so that when someone grabbed a plate, they discovered a gift card! They didn’t mention they were doing this – so at first we didn’t get it – but then … hey! Gift Cards! Cool!

Do you worry about the URL?

Guess what content this URL points to…

image

Hard to guess, isn’t it?

If you guessed the WEATHER, you’d be right.

I had typed in the domain name followed by /weather, thinking that would take me immediately to the weather page, but was greeted by a 404 Error Page (not a nice one … just the one built into the browser).

When you’re coding a web application, do you make it so well known/used destinations are easy to reach by using clean/simple URLs?

Do you like it when a web application uses URLs that are understandable, rather than everything being codified?

Silverlight’s ItemsPanelTemplate, Horizontal Only?

Have you tried to create a horizontally oriented ListBox in Silverlight with a custom ItemsPaneltemplate, with a Panel of type other than StackPanel? If you have, you’ll likely have run into the same problem I have – you can’t really do it. Unfortunately, the ItemsControl (which the ListBox derives from), eventually checks the Panel type of the ItemsPanel (the ItemsHost), and it only reacts properly to a Vertical orientation if the Panel type is a StackPanel.

internal bool IsVerticalOrientation()
{
    StackPanel itemsHost = base.ItemsHost as StackPanel;
    if (itemsHost != null)
    {
        return (itemsHost.Orientation == Orientation.Vertical);
    }
    return true;
}

You might try deriving from StackPanel, but unfortunately, ArrangeOverride and MeasureOverride are both sealed methods on the StackPanel. So, you can’t. This behavior certainly limits what you can do with a ListBox layout.

What happens if you try something vertically oriented without a StackPanel host? The behavior is that the ListBox won’t properly scroll and activate the current ListBoxItem. Calling ScrollIntoView has no impact (as the math doesn’t work correctly when the IsVerticalOrientation isn’t properly handled).

Yet another feature of WPF that you’ll need to ignore for the time being. :)