New update for RTE News Reader app coming out shortly

I've just submitted a new update to the Windows Marketplace for my RTE News Reader app. This update is only a minor update but includes a fix to a nasty bug that was forcing some news articles to not display.

The bug was caused by badly formatted XML from RTE.ie - rogue ampersands to be precise. I was able to track down that it was badly formatted XML by using a simple XML validate checker - http://validator.w3.org/feed/ This checker highlights everywhere that the feed could be failing.

Once I could see the issues I then had to put in a workaround. The problem with just replacing &'s is that they are also going to be used for valid html encoded values in the XML. I had to ensure that I was replacing single ampersands only. I was able to do this by using a regular expression to find single instances of ampersands in the text and replaced them with html encoded versions of themselves. This Stackoverflow article discusses how to implement such a fix: http://stackoverflow.com/questions/121511/reading-xml-with-an-into-c-sharp-xmldocument-object

The app is now going through the usual approval processes in the App Hub. All going well, it should be available for download by the end of next week.

 

How to fix the DataTables.net Internet Explorer error: "Unable to get value of the property 'style': object is null or undefined"

On one of my latest management projects I had to test and ensure that the project would work as expected in Internet Explorer. With the exception of a few style issues, which are to be expected when IE testing, I noticed that my DataTables.net code was returning the following error: Unable to get value of the property 'style': object is null or undefined. This was only happening in Internet Explorer 7 and below.

Usually IE would return this error message if the number of columns I was declaring in the DataTables javascript did not match the number of headers I had in my HTML. However, I knew that I did have the correct number of headers as the code works as expected in all the other browsers.

When I went to investigate my code I noticed a rogue coma on the last element in my column collection when I was declaring my DataTable. My code looked something like this:

$(document).ready(function () {
            oTable = $('#dt').dataTable({
                "sAjaxSource": 'AllUsers/',
                "aoColumns": [
			            { "mDataProp": "Firstname" },
			            { "mDataProp": "Surname" },
			            { "mDataProp": "Email" },
		            ]
            });
        });

When I removed that last coma after my Email column everything worked as expected. Now my code looks like this:

$(document).ready(function () {
            oTable = $('#dt').dataTable({
                "sAjaxSource": 'AllUsers/',
                "aoColumns": [
			            { "mDataProp": "Firstname" },
			            { "mDataProp": "Surname" },
			            { "mDataProp": "Email" }
		            ]
            });
        });

It's weird that IE had an issue with this and the other browsers were ok with it. I guess it's just down to the different rendering engines in the browsers. It was incorrect before but the other browsers ignored the issue. Thankfully this was an easy fix!

How to force your database name using Entity Framework migrations in a multi-project solution

If you're using Entity Framework migrations in a multi-project solution you might have noticed that when you run the 'Update-Database' action your database was given the name 'yourdatabase.Data.DataContext'. Some people don't mind this default naming scheme but I want to call my databases something a bit cleaner.

My typical MVC solution contains many projects to help keeps things separated. My database code is in my 'Data' project but my web.config file handling my connection string is usually contained in my 'Web' project. I noticed that even if I have given my database a name in my connection string this was not being picked up by the Entity Framework Migrations code.

Luckily all you have to do to force entity framework to use the database name you want is put the database name into your Context file. For example:

public class DataContext : DbContext
    {
        public DataContext() : base("DatabaseNameHere")
        { }

        public DbSet Table1 { get; set; } 
        public DbSet Table2 { get; set; }
    }

How to avoid the entity framework migrations error: 'Could not load file or assembly or one of its dependencies.'

I've been using Entity Framework migrations for a few weeks now and I'm having a great time with. However, I've notice that every now and then Entity Framework throws an error when I try to run the 'Update-Database' command.

Whenever you get a message 'Could not load file or assembly or one of its dependencies. The system cannot find the file specified.' there are a few steps that I've noticed you can do to help work around this type of error.

  • Step 1: Firstly, ensure that your models and any relationships that you've setup are correct. Sometimes this error means that you have incorrectly setup a join or a relationship previously setup is broken. At present the error messaging returned by migrations is a tad lacking and it returns the above error for broken model relationships.
  • Step 2: If you change your models I find that unless I edit my Data Context file I get this error. My solutions usually contain many projects. I don't know if that is the reason I get this error message but if I update one of my models without altering the context file migrations continues to return the above message for me. If I don't need to alter the context file (usually I don't as I've just added a new column) then simply pressing space and re-saving the context file does the trick.
  • Step 3: Check your database isn't 'blocking' migrations from running. I ran into a few occurances where I would have manually deleted my database and occasionally this would stop migrations from creating a new database. This is a simple fix. Just right click on the Databases heading in SQL Server and click on 'refresh'. If a refresh doesn't solve the issue, try closing SQL Server Management Studio down and restarting it again.
  • Step 4: Clean your build history and try a rebuild before running 'Update-Database'.
  • Step 5: Lastly, try forcing code first to run by using '- Force'. For example 'Update-Database -Force'. This command is also useful for telling migrations to carry out a task that would result in a data loss.

If you continue to get the error message mentioned above then the issue is nearly always down to your code. Recheck it and try again. I'm sure as Entity Framework Migrations matures they will be able to return better, more meaningful, error messages.

A little Spring cleaning! RichardReddy.ie gets a new lick of paint.

richard reddy .net web developer

I've been very bust over the last few weeks working on some interesting MVC 3 projects but one of the things I was meaning to get around to was redoing my own RichardReddy.ie website. I had let the domain just sit there for about 12months but thankfully I had some time over the weekend to get a simple 'CV' style site up and running.

I will be launching another 2 personal sites very soon to highlight my mobile work. I've been having a great time developing for Windows Phone and I'm hoping to make some more apps for the phone very soon so having a website/portal showcasing my work makes sense. All going well these should be live before the end of March.

RTE News Reader hits the Windows Marketplace

RTE News Reader App for Windows Phone

Over Christmas I decided to dip my toes into making a Windows Phone app for my Lumia 800. If there's one app that I was missing when I moved over to Windows Phone from iOS it was the RTE app. There was no official app so I went about making a quick little app to pull in their RSS feed and make readings the news stories a bit easier to consume on the phone.

I ran into issues straight away as the RTE feed does not support RSS 2.0 which a lot of the code samples out there seem to be using. Thankfully as I've been using Linq to XML so much in my job I did a little workaround to allow me take in the feed in the app. After that any other issues I had were just your basic 'getting to grips' issues. Funny things like finding out that Windows Phones can't support GIF images out of the box or that they only have 16bit displays so gradients look crappy caught me off guard as I coded up the app.

Thankfully I could work around these limitations. Making the app was a great learning experience and was actually surprisingly easy to do for a typical .net developer. If I have one complaint it would be that the App Hub website is a bit dodgy right now. This is the website you register your app on. The website is really slow and while they have implemented ajax calls for most operations, it can take upwards of 25secs to see any results with zero indication that anything is actually loading for the user.

Having said that, there is nothing sweeter than the satisfaction of thinking that there are people out there who are using your app (and hopefully enjoying it!). I have tons of new features I'd like to add to make the app a lot more useful for others. As soon as new updates are out I'll let you know here or on my Twitter feed.

I was also a little shocked that my app went to number 1 in the Irish News section and number 6 in the overall top free downloads for the Irish Marketplace! That's pretty sweet :)

RTE News Reader app for Windows Mobile is number 1 news app in Ireland

If you want to check out the app yourself, head on over to the Marketplace and give it a whirl! I respond to all emails sent through the app so don't be shy and get in touch. I don't mind if it's good or bad. If there's a feature you'd like and I can add to the app than I'll do it :)

How to get ApplicationBarIconButton images to display

I ran into an issue the other day where I wanted to use one of the default icon set images for my new Windows Phone app. I followed the guides online and took the images from the Windows Phone SDK on my computer and pasted them into my project.

However, every time I ran my project I noticed the image was not displaying. I would just get a nice looking X in a circle (I guess it's the new "red X"!). To resolve this issue you need to right click on the icon(s) you want and select Properties. When the Property window opens change the Build Action to Content. For me, this was defaulting to Resource and was the reason that the image would not appear for me in the application bar.

IIS7 ASP Routing not working on live server

We had an issue at work the other day where one of the developers was having an issue with asp routing in IIS7. It was the first time this particular server was asked to run a .net 4 website so naturally some fine tuning was required. When we tried to navigate to the webpage the following error appeared: 403: Access Permission Denied

I thought this looked odd as all permissions were applied correct and the webpage in question was coming up for us when we included it's extension. I took a look at the web.config file and noticed the rule to use asp routing was missing so we added that:

         
    
        
        
    

However, this didn't fix our issue. I was puzzled and spent a further 30mins exploring all the different options and settings in IIS. Eventually I took a look at the Global.asax where the page routing was detailed. I noticed that there was a folder by the same name as the page we were calling. We had Directory Browsing turned off - hence the Access Denied Permission error that was throwing me off!

So I guess the bottom line is, add the above code to your web.config and if it's still not working then make sure you don't have a folder in the project with the same name that you're trying to route to!!

Entity Framework v4.2 upgrade not working

This particular error caused me some headaches so I decided to blog about it in the hope that it'll help some other poor soul! I have a pretty standard MVC 3 project that uses Entity Framework Code First for handling the database side of things. I decided to update my project to ensure it was using the latest version of all of the packages in use on my project (ninject/entity framework/etc). This particular project was using Entity Framework v4.1, which I had previously updated using NuGet without any problems, so I decided to download and install the latest version from NuGet - ver 4.2.

The Problem:

I know after installing any new version of Entity Framework it's always wise to restart Visual Studio and do a clean rebuild of your project but when I went to run this project locally it threw up the following error:

 

Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

 

It was fairly obvious that my project was looking for the wrong version of EF but I couldn't tell why. I went looking for any hard coded mention of EFv4.1 but nothing was returned. Next I did some searching online but nothing seemed to match my particular error. I took a closer look at the detailed error log and noticed it was looking for the entityframework.dll file but was not finding it.

The Solution:

I took a look in the 'Packages' folder that NuGet installs the files to. I could see 2 Entity Framework folders. One folder was for the older v4.1 and one was for the new v4.2. I took a look inside the v4.2 folder  and could see the dll files in there so I knew the files had downloaded. Then I took a look in the v4.1 folder and noticed that the folder structure was different.

  • I went back into the v4.2 folder (Packages\EntityFramework.4.2.0.0\lib\) and could see a folder called 'net40' that contained the dll files.
  • I cut the 2 files out of there and placed them into the 'Packages\EntityFramework.4.2.0.0\lib' folder (up 1 folder level).
  • I went back into Visual Studio, did a rebuild and everything went back to work for me.

Reading back over this post I can't believe how easy and simple the fix was. Up until now NuGet had always worked so it never crossed my mind that it would have botched the update. Hopefully this solution will help you out if you see that dreaded error message. Fingers crossed NuGet won't do anything like that again to me.

Dec05

New posts on the way!

Wow, it's been ages since my last post here. I've been super busy with some new exciting work over at Dragnet Systems lately which is coming to an end shortly giving me more time to post some new articles.

Over the coming weeks I'll post some articles explaining how to get the most from MVC3 for real world scenarios. A lot of my work at the moment focuses on MVC3 with Entity Framework Code First, Twitter's BootStrap and jQuery to build amazing web apps for businesses.

I've also been taking the time to learn how to setup my MVC projects to use dependency injection so that my code is much neater and tidier. It took ages to get my head around it initially but it's starting to pay off now which is great.

So there you have it. I'm still here and there will be more new posts very soon :)