Wednesday, December 5, 2012

Silverlight initalization error

So I was copying and pasting some classes into my Silverlight project and when I ran it gave me a pop-up window saying it couldn't initialize the Silverlight app.

A cursory look revealed that I had accidentally deleted the "ClientBin" folder from my Silverlight web project (remember that there is the client piece and the web piece on SL apps).  I added the folder back but the XAP file wasn't there!

I did a search and didn't find the solution for this but I figured it out so I wanted to make it available.

You'll need to go into the project properties (right click on the .WEB project and choose properties).  Under the Silverlight Applications tab you will need to add the application.

Click "Add" then choose "use an existing Silverlight project in the solution" and add the SL project into the project.

As part of this it will also recreate the ASPX and HTML page(s) if you accidentally deleted those as well.

The exact message from the browser is: "Error: Unhandled Error in Silverlight Application
Code: 2104     Category: InitializeError  Message: Could not download the Silverlight application. Check web server settings".

Wednesday, November 28, 2012

Silverlight Binding Error

I ran into an error in Silverlight (v4) today and thought I might take a moment to document the problem in case anyone runs across the same issue.

I created a data grid and was assigning the columns manually.  I decided to leave one column without a binding because it will be a combo box field and I wasn't ready to tackle that yet.

When I ran my app I received and error when I bound my objects to the grid.  Since this is just a sandbox proof-of-concept thing I didn't have it wrapped with a try...catch so it actually came up as an unhandled exception in Internet Explorer.

The error will be "Value cannot be null."  And you might drill down and find an error about an unexpected value as well.

The problem is that you have a field without a binding.  So I removed this field (you may opt to add a binding to it) and problem solved.

Tuesday, September 25, 2012

Unable to install or run the application. The application requires...

Ran into an error today doing a Click Once style deployment on my new PC.  The end-user was getting an error ""Unable to install or run the application. The application requires ..." which proceeds to list the missing DLL and that it needs to be installed in the GAC.

I checked the reference and "Copy Local" was set to true so I knew the DLL was in the directory when the app runs locally but I found out that Click Once has a way of managing its dependency files.

When you right click on the project it brings up the project properties window.  In VS2010 under the "Publish" tab there is an "Application Files" button.  When you click this button it lists all the assemblies and gives you the option under the "Publish Status" column to choose if you want to include these files automatically in the deployment.

If you set to "Include" then its there but if its set to "Prerequisite" it will want that file to be installed on the machine prior to running the Click Once.  Exclude is also an option but I don't think it does the prerequisite check.

Wednesday, May 2, 2012

Detecting Version in C# / .NET

I've found occasion recently to know the version of Windows that a person is using in order to make a call to the correct API.  Mainly, this has been a concern with clients using Windows XP and now moving onto Windows 7 and finding compatibility issues with 3rd party components.

By using System.Environment.OSVersion.Version we can look at the version of Windows running and determine the best source of action.  The two properties we are concerned with are "Major" and "Minor".

You can find a complete list by searching for "System.Environment.OSVersion.Version" but basically, here is the rundown:

Major 5 will be 2000, XP, or 2003.  You can tell by the minor version which one it is.  Window 2000 is 0, XP is 1, and 2003 is 2.

Major 6 will be Vista, 2008, or 7.  Minor 0 is Vista, 2008 is 1, and Windows 7 is 2.

There is also a "Platform" property that will tell you if the machine is running Windows or Unix or WinCE, etc.  Since I know my client is running Windows XP or 7 ...  I don't concern my self with that but you might need to.

So a quick example... maybe I need to load a different form with a Windows XP or Windows 7 specific control.  I could do something like this:

If (System.Environment.OSVersion.Version.Major == 6)
{
     //We're running Vista, 2008, or 7
     //Load a form with the Windows 7 component
}
else
{
     //We're running 2000, XP, or 2003.  Hopefully not still on NT or older!!!
     //Load a form with old Windows components
}

Thursday, February 23, 2012

Database Connectivity in .NET

Something to keep in mind about database connectivity in .NET is to always ensure your connection is being disposed of properly.

Many times as developers we code according to the "happy path" which can lead to some undesirable behaviors when an unhappy path occurs.

Here is a quick example (excuse any typos as I'm doing this from memory):

SqlConnection cnn = new SqlConnection(myConnectionString);
cnn.Open();
SqlDataReader reader = cnn.ExecuteReader(someQueryOrCommand);
cnn.Close();

We open a connection, get some data, and we close the connection.  Easy, right?  Probably works 99% of the time with no problems.

What happens if we timeout during the execution of our SQL query or command?  Most of us are/should be using a try...catch block to catch that exception and deal with that error instead of having the app crash due to an un-handled exception.

A potentially big problem exists regardless of the try...catch block.  Each time this code is executed and fails for whatever reason we are leaving an orphaned connection.  If this happens enough times, we run out of available connections on the server and SQL is not responsive.

Commonly I see this problem when the database is performing slowly and causing a lot of database calls to timeout.  A user may repeatedly retry a piece of functionality or may repeatedly close and re-open the application trying to get it to run.  These orphan connections typically make the problem worse to the point that the server has to be rebooted.

A good way to handle/prevent trashing your available connection is by using a "finally" block in addition to the try...catch.

The finally block will execute regardless if the outcome of the code (IE, regardless if it goes through the try code with no problems or it hits the exception code block).

Pseudocode for this solution looks like this:

SqlConnection cnn = null;

try
{

cnn = new SqlConnection(myConnectionString);
cnn.Open();
SqlDataReader reader = cnn.ExecuteReader(someQueryOrCommand);

}
catch (Exception ex)
{
// do something here
}
finally
{
if (cnn != null && cnn.State == ConnectionState.Open)
    cnn.Close();
}

Thursday, February 16, 2012

Missing .NET Functionality

Something I've noticed recently in .NET4 is that certain functionality doesn't seem to be available.


Consider the following line:

string value = ConfigurationSettings.AppSettings["somevalue"];

I get a warning in the compiler "Warning 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: "This method is obsolete, it has 
been replaced by 
System.Configuration!System.Configuration.ConfigurationManager.AppSettings"

However, when I type ConfigurationManager, nothing shows up in Intellisense!

The solution to this is to go to "Add reference" and add the reference to "System.Configuration" in your solution.  Now, that functionality is available.

This is also the case for the "HttpWebRequest" object location in System.Web.

I'm not sure why 4.0 requires this whereas it just worked in older versions of .NET but it is what it is.

Friday, November 18, 2011

The Power of (Kindle) Fire

I may do a video review of the Fire at some point because I'm tired of silly unboxing videos and people fumbling through the Kindle Fire UI making stupid comments. But for now ... here is my article on the Fire as requested by some friends of mine.

First off let's clear some things up. This device has been dubbed an iPad killer. In some ways (which we will discuss) it could be but in other ways its not. The truth is one is chicken and the other is beef. Some people prefer one, some people prefer the other. And hey, some people might prefer pork of seafood. [Man, I'm getting hungry.] No the Fire doesn't have a camera, 3G, microphone, GPS, or a pretentious price tag. It is a $199 device and an iPad is a $600 device. Personally, I think its a smart move too.

Your smart phone will have all the features I mentioned and already has a data plan attached to it. So for someone like me who is a "bang for the buck" individual I don't want to pay for duplicate features and a second data plan. For some people this won't be an issue or concern. Great! That's fine.

So what is the Kindle Fire? Its a device to consume Amazon content (magazines, books, music, movies, tv shows, etc), run apps, and do some web browsing. In that regard (except for using iTunes content) it sounds just like an iPad at 1/3 the cost.

What do I like about the Fire? It is not too bulky so you can use it with one hand. Content can be stored in the Cloud or on the device. Purchasing content is easy and there is good integration between the Amazon site on your PC and the Kindle device. For example, if I purchase content on Amazon it will be available on the Kindle to download or view.

What don't I like about the Fire? The "8GB" storage is actually closer to 6.5 with everything that is pre-loaded. Since you can store content on the Cloud that's not too big of a deal but if you're trying to load up on movies (less of an issue with books or music) then you might not have enough space. Allegedly you can store about 10 movies on the Kindle Fire. The plus side of this is that if you're connected to wireless you can pull content from your private cloud storage or stream movies.

What do I like about the Amazon content? The selection is there. Most new media is available for download. The pricing is slightly better (say $15 for a new popular movie) vs $20 for the physical media. There is also rental options that make content available for $1.99 - $5.99. Most TV shows are about $1.99 for an episode or the season can be purchased.

Music prices seem to be fairly consistent about $0.99 a song but album prices can vary. Obviously book prices vary along with magazine subscriptions.

With Prime you get free streaming of videos and some limited "loaner book" selections. The content isn't necessarily newer stuff but its not all junk. Where it really shines is the amount of kid friendly content (Sesame Street, etc).

What do I dislike about the Amazon content? I'd prefer newer content over quantity of content for the Prime stuff. As far as I know there is no "add-on" to download music for a flat rate like Zune Pass or others. Some of the content (like Amazon's audio books; Audibles) doesn't seem well integrated with Fire yet.

Apps are lacking as well. I can get some of the more popular apps (Angry Birds, Facebook, Pandora, etc) on my device but ones like ESPN Fantasy Football don't appear to exist.

Amazon Prime? For $80/yr which includes free 2-day shipping on Amazon orders I think Prime is one of the better deals going on. That is basically $6.66 (nice) per month and includes not only streaming content but the loaner books (1 per month). So better deal than Netflix, etc.

Is this device good for kids? Yes, if supervised. There is no filtering/parental controls for web browsing or content downloads. And since even free content requires having all your billing stuff setup there isn't much to prevent your child from running up a huge bill on content.

In the first night of using the Fire and trying to get my kid to bed I was able to read her several children's books and stream episodes of Sesame Street. The finale I bought Kung Fu Panda ($6.99) and was able to stream it instantly. I later downloaded it so we can watch it on the go.

Other thoughts? Kindle doesn't have much in the way of inputs. It has a mini stereo jack and a power plug. The included power cable is a wall cable so I'm not sure if you had a USB cable with the correct connector if you could access the Fire or not. (IE as a mounted drive.)

Since you're purchasing digital content (not tied to a device) it seems like you could watch the same content on a computer or connect a computer to your TV and watch it that way. That seems pretty neat to me because now you're not having to re-purchase media.

Again, no SD ports or anything but you can upload content on the Amazon site to their cloud so that is handy. I think you can even upload non-Amazon music content as well.

Web browsing experience is closer to PC than Smart Phones are. Wasn't overly fast but wasn't overly slow either.

Final verdict: Great device if you have modest needs and the price is very reasonable.