Epic Blog of Awesome


Use ViewData and Implement ViewModel Classes: The Official Microsoft ASP.NET Site

Using a ViewModel Pattern

The ViewData dictionary approach has the benefit of being fairly fast and easy to implement. Some developers don’t like using string-based dictionaries, though, since typos can lead to errors that will not be caught at compile-time. The un-typed ViewData dictionary also requires using the "as" operator or casting when using a strongly-typed language like C# in a view template.

An alternative approach that we could use is one often referred to as the "ViewModel" pattern. When using this pattern we create strongly-typed classes that are optimized for our specific view scenarios, and which expose properties for the dynamic values/content needed by our view templates. Our controller classes can then populate and pass these view-optimized classes to our view template to use. This enables type-safety, compile-time checking, and editor intellisense within view templates.

via Use ViewData and Implement ViewModel Classes: The Official Microsoft ASP.NET Site.

Experience ASP.NET MVC 3 Beta – the Razor View Engine

Razor is designed to be an alternate view engine for ASP.NET MVC. Initially introduced in WebMatrix and now shipped as part of ASP.NET MVC 3 Beta, Razor allows developers to replace the clunky <% %> syntax with a much cleaner coding model mainly around the sign @. Moreover, it provides some excellent features for Master Page scenarios, while at the same time you won’t lose access to any features you are already familiar with, such as HTML helper methods.

via Experience ASP.NET MVC 3 Beta – the Razor View Engine.

ASP.NET MVC View Model Patterns

Since MVC has been released I have observed much confusion about how best to construct view models. Sometimes this confusion is not without good reason since there does not seem to be a ton of information out there on best practice recommendations.  Additionally, there is not a “one size fits all” solution that acts as the silver bullet. In this post, I’ll describe a few of the main patterns that have emerged and the pros/cons of each. It is important to note that many of these patterns have emerged from people solving real-world issues.

via ASP.NET MVC View Model Patterns.

>Debugging Data Bindings in a WPF or Silverlight Application – WPF & Silverlight Designer – Site Home – MSDN Blogs


Debugging Data Bindings in a WPF or Silverlight Application

The WPF and Silverlight platforms use late bound data binding resolution for bindings in XAML files. This feature allows a DataContext to be set at run-time and the objects within that DataContext to resolve their property bindings then. This late binding enables cool features like DataTemplates, composable applications and run-time loading of loose XAML.

A side effect of late bound binding resolution that can cause developers some minor frustration is that their controls do not display the expected data at run-time.

This article will explain troubleshooting techniques that can help you locate and correct the problem.

Data Binding Overview

Data binding is fundamental to WPF and Silverlight. You will struggle with your application designs, coding and troubleshooting until you understand data binding in these platforms.

The best data binding resource available is the MSDN Data Binding Overview topic. If you have not read or don’t fully understand the material in this topic, please take the required amount of time to learn this material.

Ounce of Prevention is Worth a Pound of Cure

Visual Studio 2010 has great tooling to wire up data bindings and checked them at design-time. Please read this article: How to Enable Using the Binding Builder in WPF and Silverlight Applications.

Visual Studio 2010 has excellent design-time sample data support. If you use design-time sample data, you’ll immediately see controls that don’t have expected data values at design-time.

For a detailed examination of sample data in the WPF and Silverlight Designer for Visual Studio 2010, please read this article: Sample Data in the WPF and Silverlight Designer.

Troubleshooting List

  • Verify that DataContext is set in either XAML or code
  • Run the application and view the output in the Debug Output Window
    • For WPF applications you can increase or decrease the amount of information displayed in the Debug Output Window by changing the WPF Trace Settings, Data Binding value
  • Name the control that has DataContext assigned, set a break point in the code, and view the named control’s DataContext property in the debugger
  • If binding to a CLR object, put a breakpoint in the source property getter to see that its actually being queried
  • Add a converter to a binding, then put a breakpoint in the converter

Verify that DataContext is set in either XAML or Code

This tip is along the lines of, “if the TV won’t turn on, check that it’s plugged in.”

This is important for many reasons, but one is easily overlooked; if a DataContext is null, the Debug Output Window will not display any error messages in Silverlight or in WPF.

In WPF you can use the below PresentationTraceSources on a binding and set the TraceLevel to High to view errors related to a null DataContext.

View the Debug Output Window

If you have the DataContext set, any data bindings within that DataContext that can’t be resolved will be listed in the Debug Output Window at run-time.

Sample Debug Output Window Data Binding Error

Sample One

System.Windows.Data Error: 40 : BindingExpression path error: FirstName property not found on ‘object’ ”Object‘ (HashCode=62178992)’. BindingExpression:Path=FirstName; DataItem=’Object‘ (HashCode=62178992); target element is ‘TextBox‘ (Name=”); target property is ‘Text‘ (type ‘String’)

Sample Two

System.Windows.Data Error: 40 : BindingExpression path error: ‘FirstName‘ property not found on ‘object’ ”Customer‘ (HashCode=13640894)’. BindingExpression:Path=FirstName; DataItem=’Customer‘ (HashCode=13640894); target element is ‘TextBox‘ (Name=”); target property is ‘Tag‘ (type ‘Object’)

While the above messages look verbose and complex, you can glean several interesting points of information that will help you correct this data binding:

  • The Binding Path is FirstName. Search your XAML file for FirstName and see if you expect the DataContext to expose a FirstName property whose scope will allow this binding to resolve this property.
  • The Source object in Sample One is of Type Object. There is a good chance the Type Object does not have a FirstName property.
  • The Source object in Sample Two is of Type Customer. Check your Customer Type; does it have a FirstName property?
  • Notice in Sample Two, the target property is Tag. In all likelihood, the Text property was the desired target property and not Tag. Also the Type of Tag is Object; you would probably be expecting String when binding to the FirstName property.


  • Verify the property name is spelled correctly
  • Verify the property name has the correct character casing. FirstName is not the same as firstName.
  • Verify the property is a member of the DataContext Type
  • Verify the target element is the correct Type
  • Verify the target property name and Type are correct

Posted via email from Mocha Brain Freeze

>MVVM 101


Model: the Data. Holds the information, but not behaviors or services that manipulate the information.

View: the presentation of the data (ex. the xaml in Silverlight). Contains behaviors, events, and data-bindings that ultimately require knowledge of the underlying model and viewmodel. Not responsible for maintaining its state. Instead, it will synchronize this with the viewmodel. Bindings are the integration/synchronization points with the viewmodel (ex. <TextBlock Text="{Binding FullName}" />

ViewModel: the Controller. Liason between Model and View. Might take input from the view and place it on the model, or it might interact with a service to retrieve the model, then translate properties and place it on the view. Maintains state of the View. Triggers events in the view.

source: http://csharperimage.jeremylikness.com/2010/04/model-view-viewmodel-mvvm-explained.html

Posted via email from Mocha Brain Freeze

>HTTP Error 500.19 – Internal Server Error + IIS 7.5 | Andrew Murphy’s E-Memory


This is the error that faced me the first time I deployed a .net Framework 3.5 web site to IIS via Visual Studio 2010 and then tried to run it.  After a couple of hours of digging I traced it back to the application pool but I thought it worthy of a write-up.


Attempting to run a .net framework 3.5 web site hosted in IIS 7.5 (deployed via Visual Studio 2010) gives the following error information:



Error message:

There is a duplicate ’system.web.extensions/scripting/scriptResourceHandler’ section defined

The error points to sections in the web.config file that ships with the site, a clearer view of which is here:

1: <configSections>

2:   <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

3:     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

4:       <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

5:       <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

6:         <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

7:         <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

8:         <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

9:         <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

10:       </sectionGroup>

11:     </sectionGroup>

12:   </sectionGroup>

13: </configSections>

This is strange because:

  1. The site runs fine in Visual Studio 2010.
  2. It works when deployed into IIS via Visual Studio 2008 (on a different development machine and in live).
  3. This site works if you alter the framework target to be .net 4.0 and then deploy to IIS and run as normal.


This web site was originally developed in Visual Studio 2008 but desperate to try 2010, I followed the procedure below:

  1. Installed 2010 on a clean machine (nothing in IIS).
  2. Converted the 2008 solution but kept the framework target as 3.5.
  3. Ran from Visual Studio.
  4. Deployed to IIS and attempted to run from there.

Fault Finding

My first thoughts were:

  1. That IIS thinks this is a .net Framework 4 site rather than a 3.5.  I find this hard to check as aspnet_regiis –lk does not work on Windows 7 (my development OS) and finding anything in IIS 7 is a pain in the neck.
  2. Visual Studio 2010 has messed something up.

Confirming the versions of the target assemblies for the site was problematic however.  When the site was built as .net 4 and so worked, I was able to view the Handler Mappings for the site.  When it was built for .net 3.5 and so broke, I couldn’t view the mappings as IIS displayed the same error as at run-time:



It turned out that IIS was confused about the .net framework to use after all, or at least about the application pool version to use.

Viewing the application pools in IIS showed that I had the following:


As you can see, my application was sitting with the default web site inside the DefaultAppPool, which is configured to target .net 4.  Moving the site into the Classic.NET AppPool fixed the issue and worked a treat.

It would have been nice for this to have worked out of the box but you live and learn.

This entry was posted on Tuesday, April 20th, 2010 at 19:02 and is filed under .Net Framework, ASP.Net, Errors, IIS, Misc. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Posted via email from Mocha Brain Freeze

>SpaceX Flight 4 Success



A week spent reviewing data has confirmed that the flight went really well, including the coast and restart. The mood here at SpaceX is just ecstatic! This is the culmination of six years of hard work by a very talented team. It is also a great relief for me, who led the overall design of the rocket (not a role I expected to have when starting the company). I felt a little sheepish receiving the AIAA award for the most outstanding contribution to the field of space transportation two weeks before this flight.

Orbit was achieved with the first burn terminating at 330.5 km altitude and 8.99 degree inclination. The goal for initial insertion was a 330 km altitude and a 9.0 degree inclination, so this was right on target! Accuracy far exceeded our expectations, particularly given that this was the first time Falcon 1 reached orbit.

The primary purpose of the second burn was to test the restart capability and then burn as long as possible. The upper stage coasted for 43.5 minutes and then burned for 6.8 seconds, which is 4 seconds longer than needed to circularize. Most of the burn was actually done sideways to avoid creating a highly elliptical orbit, hence a change in inclination to 9.3 degrees. The final orbit, confirmed by US Space Command, was 621 km by 643 km.

As an added bonus, we picked up several minutes of video and data from the upper stage when it passed over Kwajalein one orbit later, which showed the stage to be in good condition.

After one complete orbit, the SpaceX Falcon 1 Flight 4 vehicle
passes over its launch site at the Kwajalein Atoll,
and returns a view of the Earth.

While Falcon 1 was the world’s first privately developed liquid fuel rocket to reach orbit, I would like to acknowledge and express appreciation for the role of DARPA, the Air Force and the ORS Office of the Department of Defense. They played an important role as early “beta” customers of Falcon 1. There are many individuals in those organizations, as well as in NASA, NRL, FAA, USAKA/RTS, other departments of the US government and the private sector to whom we owe gratitude for their support and advice. You didn’t have to help, but you did, often at risk of career and credibility, so you have my deepest thanks.

The next flight of Falcon 1 is tentatively scheduled for March next year and will carry a Malaysian primary satellite, as well as US government secondary satellites, to near equatorial orbit. Flight 6 will probably be a Defense Department satellite in the summer and Flight 7 a commercial satellite mission in the fall. In 2010, I expect the launch cadence for Falcon 1 to step up to a mission every two to three months.

Below is a highlight reel of the Falcon 1 flight, including the restart and video footage from the upper stage when it does its first orbit back over Kwajalein. Some of this has not been show before, so there is something new even if you watched the live webcast.

Liftoff of Falcon 1, Flight 4 from the
Kwajalein Atoll on September 28, 2008 (UTC).