Silverlight Image Error

While working in Silverlight I ran across a error that seemed rather odd, not because it didn’t make sense but that I couldn’t see anything I did wrong. So the error was

Unhandled Error in Silverlight 2 Application App.xap
Code: 4001
categories: ImageError
Message: AG_E_NETWORK_ERROR

While checking the Image tag in the xaml I simply couldn’t find anything wrong with it. It looked very similar to the following xaml. The user.profile_image was of course a full URI that worked fine when written directly in the browser.

<Image  Grid.Row="0" Margin="0,0,5,0" VerticalAlignment="Top"  Source="{Binding user.profile_image}" ></Image>

So that leaves me with what could the problem be, well it turned out it was simple I was a using a GIF file so http://mydomain.com/foo.gif as a source for an image simply doesn’t work as GIF isn’t supported. But really why would Silverlight not use GIF? Well simply converting the GIF to a PNG then Silverlight can handle the image just fine and display it. Although there are some issues as in Silverlight the only 8 bit and fewer PNG formats support transparency. So if the reason you were using a GIF was for transparency you will have to create an 8 bit or lower PNG. Look for a simple how to next post on converting a GIF to a PNG that Silverlight can display properly with transparency.

Connector/J 5.1.6 vs Connector/J 5.1.7

While deploying a Java based auto import system I ran into a very odd problem. The code was developed and tested just fine with Connector/J 5.1.6 then while pushing to prod there seemed to be a major issue, the import would run download everything parse it and then clear out the old data but then get stuck. I would then get a series of errors java.sql.SQLException: !Statement.GeneratedKeysNotRequested! well it turned out that the prod sever had Connector/J 5.1.7 installed instead of the 5.1.6 which test had installed. This turned out to be allowing for some wrong practices when it came to prepared statements. It was a pretty easy fix yet it took a bit of time to make sure it happened every where. So why there was a change and what happened is well discussed else where and the links to those will follow. But for now here the change that needs to happen.

PreparedStatement postinsert = connection.prepareStatement(sql);

Just changes to the following. But make sure you do the change for all prepared statements that will use generated keys, its easy to miss one and have the whole app fail because of it.

PreparedStatement postinsert = connection.prepareStatement(sql,PreparedStatement.RETURN_GENERATED_KEYS);

So if you would like to read more about whats going on check out these resources:

Silverlight Move Cursor to End of TextBox

While working on in Silverlight I found the need to auto populate a TextBox then shift focus to that TextBox. That was simple to do with the following code.

    txtSearch.Focus();
    txtSearch.Text = "sometext ";

But then there is a problem the cursor is at the start of the text box so if a user starts typing they end up adding to the start when I want them to just add on to the end. So after some hunting I found the SelectionStart property of the TextBox, while this may be obvious to people who work in Silverlight and C# all the time it didn’t jump right out at me so I thought it was worth talking about. So by using SelectionStart and I can move the cursor to the end and users can just append to my started search text.

    txtSearch.Focus();
    txtSearch.Text = "sometext ";
    txtSearch.SelectionStart = txtSearch.Text.Length;

Go Daddy Subdomain Redirects

After seeing this great post from Jamie Thingelstad about using subdomains to redirect people to your LinkedIn or Twitter profile I thought it would be great to add that to my site.

But it was a big process that it shouldn’t have been. I found it very hard to actually find where in the my Go Daddy hosting where to put the subdomain. So if you are doing hosting with Go Daddy and have used their subdomains tied to a folder you have to goto a completely different section to do this type of redirect. It’s in the domain management which one would expect but I look right past the correct section at least a half dozen times, so below there is a picture below the fold with a red box showing exactly where to add the subdomains.

The process is simple once you find the correct section. Simply click add then fill out the “subdomain” and “forward to” fields as an example I did “subdomain”: twitter and “forward to”: http://twitter.com/beckje01 Those simple steps have now set up http://twitter.jeffbeck.info to link to my twitter account.

subdomain

YUI ScriptNodeDataSource Issue

While using the YUI Library, I came across an annoying issue. It is stated places that order matters when dealing with the library includes, yet there are still some issues that come up. The main one I’ve found is with the YAHOO.util.ScriptNodeDataSource this is used for accessing remote data via the YUI Get Utility. But using the configuration from Yahoo the Get library isn’t included by default, yet when you add it after finding that error the system still won’t work.

The Get Utility has to be loaded before the DataSource library, yet this is the only part of the DataSource library that require the Get utility so it isn’t listed as a dependency for that library. I used the YUI Dependency Configurator yet while working without the combined files you can still introduce the ordering issue. Yahoo needs to add a simple check that the Get utility is always loaded before the DataSource Utility yet that haven’t yet. You may not have this issue while using the combined files mode as it will all be executed at once.

So if you see an error message like “this.getUtility is undefined” make sure you have the Get Utility loaded before the DataSource.