About the Author

Adam joined InterKnowlogy in 2004 and oversees the Application Development Practice. He is an accomplished software developer, C# MVP, author, teacher and speaker with over twelve years of experience designing, developing and leading large-scale mission critical software projects. Adam is also very active in the development community where he is a member of Microsoft’s UI Frameworks Council, teaches classes at UCSD Extension, serves on the Board of Directors for the San Diego .NET Developers Group, and is a renowned speaker at user groups and conferences.

Linq to SQL Designer: Buyer Beware

I have been running into this odd error off and on for the past week with the code generated by the Linq to SQL designer. I kept on getting Error 1 Build failed due to validation errors in C:\xxx\DB.dbml…. when I tried to build. Thanks to google (a developers best friend) I ran into a blog entry by Rick Strahl that talked about resetting Visual Studio Packages. Well it turns out this is solves my issue but I had to follow these steps to get it to work.

  1. run devenv /ResetSkipPkgs
  2. clean the solution
  3. recompile

I really hope they fix this with SP2 or in VS 10.

Silverlight DataBinding Modes for the WPF Developer

I was suprised to find out that Silverlight Data Binding uses OneWay as the default binding mode. This really caught me off guard when I was trying to port some code written in WPF over to Silverlight since all of my TextBox.Text bindings did not have an entry for Mode in the binding statement. The reason of course is that by default TextBox.Text uses a Mode of TwoWay in WPF. In fact many of the common controls like TextBox.Text, ComboBox.Text, MenuItem.IsChecked, etc. have TwoWay as their default mode.

If you are writing code that will be used on both platforms I would suggest adding Mode to the binding statement. It’s a pain but it will save you the debugging hassle when your UI is not passing values back to the classes it is bound to.

Writing Debugger Friendly Classes Using the DebuggerDisplayAttribute

In many cases while writing software we fail to think about the users of our code. This is often the case when it comes to debugging since most of use feel it’s easy enough to just jump into the code and see what’s going on. While this is possible it’s the simple things in life that sometimes make the biggest difference. Take for instance the case of debugging some code you didn’t write. In most cases if you look at a type in the locals window all you will see is a ToString() of the type (see Figure 1) which is not very helpful. To lean more about the type you are forced to drill down into the type looking at the properties to see what’s going on. Wouldn’t it be nice to see some high level values instead of the ToString() of type? If we take this even further wouldn’t it be nice to see some values that the designer of the type thought would be important if you were in a debug session. This is where the DebuggerDisplayAttribute come into play.


Figure 1: Debug Locals Window (click to enlarge)

The DebuggerDisplayAttribute determines how a class or field is displayed in the debugger window eliminating the ToString() default you normally see. Take for instance the code in Listing 1. This is the version of SimpleClass that resulted in the locals window view shown in Figure 1 which as we said was not very helpful. The code in Listing 2 shows how we can add the DebuggerDisplayAttribute to the class to see some more interesting information. In this case we added the attribute with the value we wanted to show up in the value column of the debugger window (see Figure 2). The format “Some Interesting Data = {_hiddenInternalInfo}” consists of two parts: (1) the text to be display and (2) the value from the class {_hiddenInternalInfo} we wanted to see. You are not limited to just one value. If we wanted to see the MyProp1 value as well we could change the entry to look like this “Some Interesting Data = {_hiddenInternalInfo}, MyProp1 = {MyProp1}” and get a result that looks like Figure 3. As you can see it’s not really hard to add some additional information to the locals window and help someone who is using your code figure out what’s important.

class SimpleClass
    private string _hiddenInternalInfo;
    public string MyProp1 { get; set; }
    public string MyProp2 { get; set; }

    public SimpleClass()
        this._hiddenInternalInfo = "Hidden data";
        this.MyProp1 = "My intitial data for MyProp1";
        this.MyProp2 = "My intial data for MyProp2";

Listing 1: SimpleClass with no attribute

[DebuggerDisplay("Some Interesting Data = {_hiddenInternalInfo}")]
class SimpleClass
    private string _hiddenInternalInfo;
    public string MyProp1 { get; set; }
    public string MyProp2 { get; set; }

    public SimpleClass()
        this._hiddenInternalInfo = "Hidden data";
        this.MyProp1 = "My intitial data for MyProp1";
        this.MyProp2 = "My intial data for MyProp2";

Listing 2: SimpleClass with DebuggerDisplayAttribute


Figure 2: Debug Locals Window with More Information (click to enlarge)


Figure 3: Debug Locals Window with a List of Information (click to enlarge)

Building RIA Applications for Web 3.0 Sample

The application below is a sample application that demonstrates how to create a Web 3.0 application that combines ASP.NET, ASP.NET AJAX 4.0, AJAX Control Toolkit and Silverlight. The application is a fictitious Rad Bikes company that sells bikes and uses SQLExpress 2008 and the AdventureWorks2008 database to show sales territories and details sales figures for salesman in each territory. The home page demonstrates using a custom behavior to add image rotation capabilities to a standard image control. The Sales menu will take you to the sales information page that demonstrates some of the new data binding features of ASP.NET AJAX 4.0 and how Silverlight can be driven via JavaScript. In this case when a territory is selected the Silverlight portion of the page (the bottom portion) will be updated with sales information for that territory using the HTML Bridge that is part of Silverlight. I have an upcoming article tentatively titled Building RIA Applications for Web 3.0 using the Microsoft Platform in .NET Developers Journal that talks more about how this application works but until then feel free to party on the code.


Home Page (select image to enlarge)


Sales Page (select image to enlarge)

Setup Details

The application has a few steps that you need to perform before you can run it.

  • The application has a vSalesSummaryViewScript.sql script located in the root directory that needs to be run against the database to create a view not included with AdventureWorks2008.
  • The application also uses the following connection strings that will need to be updated if they don’t match your installation.

<add name=”AdventureWorks2008ConnectionString”
connectionString=”Data Source=.\SQLExpress;Initial Catalog=AdventureWorks2008;Integrated Security=True”
providerName=”System.Data.SqlClient” />

Once you have done all of this the application should work like a charm.

Application Download

RIA Sample Application

RIA Talks

Over the next few months I will be covering SoCal doing a talk on Rich Internet Applications (RIA) using ASP.NET AJAX 4.0 and Silverlight. The inspiration for this talk comes from the convergence I see between some of the Web 2.0 technologies and Silverlight and the coming of age of Web 3.0. I am hoping I will be able to cover some of the challenges you will face when interacting with these technologies and provide some guidance as you move forward creating applications of this type.

Information and Dates

Building RIA Applications for Web 3.0


Web 3.0 will prove to be the incarnation that moves us into highly interactive applications that exploit the advances in UI graphics, module web applications and the ever increasing internet connection speed to provide users with an online experience never seen before. In this session we will take a look into how some of the new Microsoft Web technologies (ASP.NET AJAX 4.0 and Silverlight) will play a role in this new frontier. First will take a look at ASP.NET AJAX 4.0 and how some of the new features like templates and data binding are contributing to a pure client-side story for web development. Then we will dive into Silverlight exploring the extensive UI model, robust communication stack and reliance on .NET and how these features provide a robust environment for creating truly interactive module web applications. Finally we will look at how the HTML Bridge in Silverlight provides interaction between the dynamic language world of JavaScript and the static language world of .NET and how to best work in these two environments to provide a rich Web 3.0 experience.

Dates and Locations

Tuesday September 22nd

San Diego .Net User Group


Saturday October 25th

SoCal Code Camp (USC)


Tuesday November 4th

San Diego .Net Developers Group


Tuesday November 11th

Disney .NET Developers Group

Tuesday November 11th

Silverlight User Group SiG


Serializing LINQ Types

So I am using the new Data Designer in VS 2008 to create my LINQ to SQL DataContext and associated data classes and one of the first thing I wanted to do was to send back one of these “data classes” to an AJAX client via a AJAX-enabled web service. I write the code to return a SalesTerritory class “yes I am using the infamous AdventureWorks database” and hook up all of the associated code and try to run the thing. To my surprise things didn’t work. I open up Nikhil Kothari’s Web Development Helper to find out I have a serialization error.

“Type ‘RIASilverlightWeb.Data.SalesTerritory’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.

Well this really bummed me out. I sure the heck didn’t want to decorate all of that generated code with DataContact/DataMember stuff. To my surprise MS has made this easy. All you need to do is go to the properties of the designer and set the SerializationMode to Unidirectional (see below).


What this does is decorate all of your classes with the DataContract attribute and all of your properties with the DataMember attribute. Once you do this the data can be serialized.

This can also be done with SQLMetal using the /serialization:Unidirectional command flag.

ASP.NET AJAX Preview 2 Now On CodePlex

Man Betrand LeRoy and his team are really cranking this stuff out. Following on the heels of last months release they now have a new ASP.NET AJAX Preview 2 release on CodePlex. Here are some of the new features:

  • Observer Pattern. This change makes a plain JavaScript object or array emit change events. For example, you can use the observer pattern to enable live binding of plain data to UI, where changes in the UI are propagated to the data and vice versa.
  • Conversion functions on Binding. Binding now supports a convert function and a convertBack function.
  • Chained bindings. It is now possible to bind A to B and B to C, and have changes to A propagated to C.
  • Reactivating UpdatePanel controls. UpdatePanel controls within an activated region (a region with declarative markup) are reactivated after partial updates.
  • Markup extensions now support nested {{ }} expressions. This may require a rewrite of Preview 1 markup extensions.

I am going to be jamming on this stuff over the weekend (yea I know it’s a holiday weekend). Great job guys!