# Thursday, March 01, 2012

In case you haven’t heard the beta version of Visual Studio 11 was released on February 29th.  You can get the bits here.  I ran into an issue when I was installing VS 11 Beta on 3 of my 4 machines and according to Microsoft.Connect others are encountering the same issue.

The issue is that the install runs just fine to about 98% complete and then hangs on Applying ultimate_finalizer.  I let this step chug away for a good hour during the my first 2 installs and then eventually canceled it.  After cancelling it you receive a message stating something along the lines of “97 of 99 components installed successfully”.  My first try I was happy with that result, those last 2 components probably weren’t all that important anyway Smile.  At first everything worked fine but then when it was time to do some actual coding and pull source down from TFS Preview I kept encountering all kinds of cryptic errors.  My first thought was to uninstall, but then I thought I would try the ‘repair’ functionality included on the VS11 Beta install.  The repair chugged for awhile and required 2 restarts.  The original install only required 1 restart.  Come to find out that 2nd restart is important because it wraps the entire process up.  So after running the repair everything is working fine.

So if you encounter this issue, this is currently the only workaround.  Check out Microsoft.Connect for details on the issue and to see if an actual bug has been found related to this issue.

posted on Thursday, March 01, 2012 8:23:05 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
# Monday, February 13, 2012

I am currently in the process of getting my Microsoft Certification mainly because I was told I should.  I have started the process 3 times previously in my career but quickly “fell of the wagon” due to priorities I deemed more important such as bringing you this awesome blog content Smile.  I guess I have never really placed a lot of importance in certifications and figured that my past work/reputation are enough.  Anyone can pass a test with enough memorization of content, but not everyone can deliver quality software applications.

My thoughts on certification

  • I have never lost an opportunity as a consultant because I was not certified.
  • Certification is beneficial to new grads/ new entries in the software development work force.
  • Experience and proven track record should far out way a certification.
  • The content, at least in Microsoft exams, does not reflect the world.
  • You should be reimbursed for your time and fees should be covered by your employer and /or a comparable bonus should be awarded.

So, the point of this post, other than to get something out quick so I can get back to studying for said certification exam 1, is to ask a few questions to you my loyal audience.

  1. Are you certified in any technology/methodology/software practice?
  2. If you are certified:
    1. What are you certified in?
    2. Why did you get certified? 
    3. Did the content you study reflect the real world?
    4. Did you ever lose an opportunity prior to certification because you where not certified?
    5. Since becoming certified have you gotten an opportunity because you are certified?
    6. Did your employer provide compensation/bonus for becoming certified?
    7. What have you gained by becoming certified?
    8. Was it worth it?
  3. If you are not certified:
    1. Why aren’t you?


I would love to hear what everyone has to say on this.  Thanks for your time.

posted on Monday, February 13, 2012 4:27:00 PM (Central Standard Time, UTC-06:00)  #    Comments [2]
# Monday, February 06, 2012

I have been working a lot with MVC sites lately and experimenting with how to make them *usable* on mobile browsers.  This is post is about the single line of mark-up you can add to your sites Master Page, or in this case your _Layout.cshtml.

Before I get to that line I am going to show you a quick screen shot of a vanilla MVC 3 application, that can be downloaded here.

First is a screen shot of the site running in a desktop browser.



Next, is the site rendered on Windows Phone 7, Android, and iPhone.

Windows Phone 7

Opera Mobile (Android)


image image image


The first thing you notice is that iOS does a fairly good job adaptively rendering the site, damn Apple!  Next you will notice that all WP7 and Android do is zoom out so the site fits on the device.  A site of any significant content or functionality would be almost useless because of the amount of panning and zooming that would be required.  I am sure we have all dealt with sites on our mobile devices like that.  So what can we do to make the site render better in WP7 and Android?

You can actually get a long way towards perfect mobile rendering of your site by adding one simple html tag.

  1. <meta name="viewport" />

The meta viewport tag can be used to control how HTML content is displayed in mobile browsers.  The meta viewport tag has properties like width, height, minimum-scale, and maximum-scale.  In this example the particular property we are concerned with is the width property.  We want to tell the the browser to render our content width at the width of device.

  1. <meta name="viewport" content="width=device-width">

Let’s see what happens when we add that tag to the head of our _Layout.cshtml file


As you can see above, because the meta viewport tag only effects mobile browsers our desktop version looks exactly the same.  Let’s check on the mobile browsers.

Windows Phone 7

Opera Mobile (Android)


image image image

The site looks much better on Windows Phone 7 and Android, and still looks the same in Apple.  So by adding that single line of mark-up we where able to give our mobile users a much better user experience.

Stay tuned for a future post on using CSS Media Queries to improve the mobile experience even further.

posted on Monday, February 06, 2012 8:15:38 AM (Central Standard Time, UTC-06:00)  #    Comments [2]
# Monday, January 30, 2012

The var keyword was introduced with C# 3.0 and the .NET Framework 3.5 to allow the declaration of implicitly typed variables.  The driving force behind the need for implicitly typed variables was the introduction of Anonymous Types

If you are using var outside of truly anonymous types you are doing so out of laziness.  I know this is a bold statement that a lot of developers are going to disagree with, so let me explain.

First off I totally agree that using var can speed up your lines per minute coded and I do use var in this manner.  But, I always replace var with the actual type after the fact.  You can do this with out requiring a large amount of time after the fact using a tool such as ReSharper and setting up you Clean Up Code” functionality to replace all usages of var with the actual type when possible.

Now for my supporting arguments:  *All of which only pertain to using var when the type is not truly anonymous.*

  • C# is not a Dynamic Language!  This may be bad or not ideal but it is fact.  The truth is not everyone is fluent in dynamic languages and they are not expecting to read code coded in a dynamic fashion when dealing with C#.
  • Code written in a dynamic fashion, i.e. implicitly typed , is harder to read, especially when you are not use to reading it.  I know what you are saying how is this hard to read?:
    1. var x = "This is not hard to read and understand what x is!";

    And you are correct, that example is not hard to read and figure what x is.  What about this?
    1. var x = from custs in dataContext.Customers
    2.         join orders in dataContext.Orders
    3.             on custs.CustomerId equals orders.CustomerId
    4.         join lines in dataContext.OrderLines
    5.             on orders.OrderId equals lines.OrderId
    6.         join products in dataContext.Products
    7.             on lines.ProductId equals products.ProductId
    8.             where products.Name.Contains("FooBar")
    9.         where custs.LastName.Contains("Smith")
    10.         select products

    I would much rather see and read;
    1. IQueryable<Product> x = from custs in dataContext.Customers
    2.                         join orders in dataContext.Orders
    3.                             on custs.CustomerId equals orders.CustomerId
    4.                         where custs.LastName.Contains("Foo")
    5.                         join lines in dataContext.OrderLines
    6.                             on orders.OrderId equals lines.OrderId
    7.                         where lines.Quantity > 10
    8.                         join products in dataContext.Products
    9.                             on lines.ProductId equals products.ProductId
    10.                         where products.Name.Equals("FooBar")
    11.                         where custs.LastName.Contains("Smith")
    12.                         select products;

              The truth is you know what your result is, at least you better or you have no business writing the code in the first place, so just declare it as such!

              One more thing,  var has no place in demo code, tutorials, and blog posts. The purpose of demo code, tutorials, and blog posts are to provide education and in doing so the code should be clean and concise and accessible to the masses.

              OK, let me have it.

              posted on Monday, January 30, 2012 10:00:02 AM (Central Standard Time, UTC-06:00)  #    Comments [12]
              # Monday, January 23, 2012

              Support for spatial data was introduced in SQL Server 2008.  What this allows you to do is capture data related to 2D geometric or geographical images in SQL Server.  It actually allows you to do much more than just storing a bunch of numbers representing this data.  In the initial releases of Entity Framework the spatial data type was not available for use, but with the Entity Framework June 2011 CTP release this functionality is now available.

              I am once again working with the code from my Entity Framework Code First Demo post.  This simple application is dream car tracker that tracks manufacturers and models of cars that someday I would love to own.  As part of the manufacturer data I currently store the Country but would like to be able to map out the corporate headquarters for the day when I get to take a trip and take delivery.  I am able to retrieve the latitude and longitude from Google Maps by knowing the address.

              The Ferrari factory located at: Via Abetone Inferiore n. 4, I-41053 Maranello Italy has a latitude and longitude of 44.53244, 10.86412.  At this point if you are new to the spatial data type, like I was, you are probably thinking “that is just a decimal and you could always store decimals in SQL Server” and you are correct.  I could certainly just add two decimal properties to my model that represent latitude and longitude and go on my merry way but using spatial data functionality introduced in the June CTP I get so much more.

              Because I am dealing with geographical data and not geometric data I am going to use the DbGeography type, that can be found in System.Data.Spatial, and add a Location property to my Manufacturer model.

              1. public class Manufacturer {
              3.     public long ManufacturerId { get; set; }
              5.     [Required]
              6.     [StringLength(40)]
              7.     public string Name { get; set; }
              9.     [Required]
              10.     [StringLength(40)]
              11.     public string Country { get; set; }
              13.     [Required]
              14.     public DbGeography Location { get; set; }
              16.     #region << Navigation Properties >>
              18.     public virtual IList<Model> Models { get; set; }
              20.     #endregion
              22. }

              Once I have Entity Framework Code First regenerate my database I can take a look and see that the .NET Framework type DbGeography translates to the SQL Server type Geography.


              Now that I have my property I can populate the Location data by converting my latitude and longitude values to a DbGeography using the static parse method.  I can add this to my SeedManufacturer method.

              1. private void SeedManufacturer(DataContext context) {
              2.     _ferrari = new Manufacturer {Name = "Ferrari", Country = "Italy"};
              3.     _lamborghini = new Manufacturer {Name = "Lamborghini", Country = "Italy"};
              4.     _astonMartin = new Manufacturer {Name = "Aston Martin", Country = "United Kingdom"};
              5.     _porsche = new Manufacturer {Name = "Porsche", Country = "Germany"};
              6.     _ferrari.Location = DbGeography.Parse("POINT(44.53244    10.86412)");
              7.     _lamborghini.Location = DbGeography.Parse("POINT (44.65934    11.12693)");
              8.     _astonMartin.Location = DbGeography.Parse("POINT (52.18708    -1.48351)");
              9.     _porsche.Location = DbGeography.Parse("POINT (48.83498    9.15231)");
              10.     new List<Manufacturer> {_ferrari, _lamborghini, _astonMartin, _porsche}.ForEach(x => context.Manufacturers.Add(x));
              11. }

              Now if you look at the data in SQL Server you an see that the data is now represented as a nasty looking hex.


              I know you are still wondering what the point is, pun intended!  Well, now I can get to the cool part.  I can use the methods that come along with DbGeography to do things such as getting distance between two manufacturers as illustrated below in line 3.

              1. Manufacturer ferrari = dc.Manufacturers.First(x => x.Name == "Ferrari");
              2. Manufacturer lamborghini = dc.Manufacturers.First(x => x.Name == "Lamborghini");
              3. double distanceInKilometers = ferrari.Location.Distance(lamborghini.Location);
              4. double distanceInMiles = distanceInKilometers/1609.344;
              5. string outputText = string.Format("{0} is {1} miles from {2}", ferrari.Name, distanceInMiles, lamborghini.Name);

              You can also use the methods in LINQ.  The query below finds all the manufacturers that are within a 100 mile radius of my house.

              1. DbGeography myHouse = DbGeography.Parse("POINT (4.65934    1.12693)");
              2. IList<Manufacturer> closeToMe = manufacturers.Where(x => (x.Location.Distance(myHouse)*.00062) <= 100).ToList();
              posted on Monday, January 23, 2012 8:30:40 AM (Central Standard Time, UTC-06:00)  #    Comments [3]