Everything was working great and my Visual Studio 2010 Beta 2 stopped starting.  I tried to reinstall VS2010B2 and that did not fix the problem.  I just got this stupid error:


The application cannot start.

Some google searches turned up Weston Hutchins blog on the issue.  I tried several of the steps and noted this difference on my system.

He says that your personal settings files are stored here:

%USERPROFILE%\Documents\Visual Studio 2010\Settings

I actually found them in:

%USERPROFILE%\Documents\Visual Studio 10\Settings

Weird.  So I blew them away and restarted.  Got the same error.  So this tells me there is more to it than just the settings files.  There must be a settings file elsewhere that is the culprit.  So I moved on to the next step that actually worked for me.

Load the Visual Studio 2010 Beta 2 command prompt and type: devenv /resetuserdata

Viola!  This worked and I got the following screen:


After this I got the screen asking you how you want the development environment to be configured and it sets up the IDE in the default manner.  But everything is working great now!

Every aspect of a Silverlight application is customizable.  This customizability runs deep, even the check in a standard checkbox control can be modified.  In this demo I will show you how to customize a visual element of a standard checkbox to make the check bigger.


Below is a functioning Silverlight example:

Achieving this is surprisingly easy.

1) Place a checkbox on your design surface and right click on it.  You will see the following menu:


2) Choose Edit Template | Edit a Copy.  What does this mean?  This feature of Blend 3 is really cool.  It lets you create a copy of the built in system style / XAML of an object.  In the next several steps you will see that you have complete control of the visual rendering of the control.  You can break it down all the way to the XAML path used to draw the check!

3) You are creating a copy of the template for the checkbox and you must name it and tell Blend where to place the XAML.


I named mine CheckBoxStyleBigCheck and placed it in the Application.

4) You now have the checkbox control broken down to its base components.



Check out the layers on the left of the screen.  There are a lot of components in the list.  I found it very useful to click the eye ball button to temporarily hide the part from the visual display.  This lets you quickly see what component the layer affects.

5) We will be increasing the size of the checkbox.


Increase the size of the checkbox by dragging the points on it larger.  You can actually resize it easily with the bounding box which will keep the height and width proportional.


I had to add 4 pixels to the top margin of each of the components because my checkmark extends 4 pixels beyond the top of the box.

6) After you do this you will also need to reorder the checkmark path to the top of the stack of visual elements.  Since the check is larger than some of the other visual elements now you want to make sure a box border does not cut off you fancy new checkmark.


There are several ways to do this.  The easiest is to right click on the checkmark path and choose Bring to Front.  Alternatively you can drag the CheckIcon path layer to the bottom of the containing grid.  These layers are rendered from top to bottom so anything further down the list is rendered after the previous, hence the layering effect.

Download the full Blend 3 project file below.

Bug ID: 502818

When customizing the style/template of a ChildWindow view in blend 3 the in-document style is applied to the child window control by way of this XAML:

When returning to Visual Studio 2010 the XAML parser throws an error and will not render the designer with the message:

Property ‘Style’ does not support values of type ‘StaticResourceExtension’.

However removing that piece of XAML and setting the Style property of the child window control at the control definition like below works:


So to see the design surface in Visual Studio 2010 B2 you must use the Style reference:

Style="{StaticResource ChildWindowStyleBlack}". If you leave the style reference in like this and run the silverlight application it will error out with the following exception:

Unhandled Error in Silverlight Application Cannot find a Resource with the Name/Key ChildWindowStyleBlack [Line: 8 Position: 34]

So, after the control is designed and tweaked in VS 2010 B2 you must remove the style reference that VS2010B2 likes and add back in the Style reference that Blend 3 put in. The app will now execute correctly.

Two words: Code Annotations

Take the code:


Now, when you hover over an object you get the quick watch popup but now it is pinnable.  Just click the little pin.


Once you pin the popup you can expand it like a quick watch and you can annotate the object in the debugger.


Click the down arrow (chevrons) on the menu bar and you can add comments.


Please note that I am still tweaking this article, I just wanted to publish it quickly because I have had a lot of questions from other developers concerning this very topic.  I will remove this note when the article is complete and I will provide a link to a project that implements this functionality from DB –> L2S –> WCF –> Model –> WPF and Silverlight.

I hope that subject was descriptive enough.  Here is the problem:  You are developing applications using an MVVM and want to use your Model code for WPF applications and Silverlight.  You will quickly find that you need to build your Model and ViewModel in a Silverlight targeted assembly.  Many people actually add the Model and ViewModel class files in the Silverlight project file.  That is a) nasty and b) you can not use your model as your data contract for your WCF service.

The solution I found was very simple.  Create your WCF service and use your Model classes as data contracts.  Now your Model classes will all be decorated with DataContract and DataMember attributes.  These are not compatible with Silverlight so you need a solution for this part of the problem.  In short, you need to conditionally compile out the non-Silverlight compatible attributes (yes it is a bit ugly in code, but it saves you a lot of time and it works!).


So lets walk through a simple application that lists Employee records from a database.  The architecture looks like this:


There are a lot of lines there but we will focus on the Silverlight side of things.  The goal is to create one Model class that is shared between the WCF service and the Silverlight application.  This Model class should also be able to be used by WPF applications (and ASP.NET) as well.  I will call the procedure for making the Model work across both architectures Portable Model or pModel. 

Linq / SQL Metal / ADO.NET Entity Framework Objects

Use one of these technologies to get your data from the database into an object.  These objects should NOT (and can not) be passed around through to Silverlight application.  The solution is to use a Portable Model.  In this example I used SQL Metal to generate out a Data Context for my database which has an Employee table.



At my WCF tier I want to perform the following:

  • Query the database and get all the Employees.
  • Convert the DataContext / SQL Metal / Linq objects to a Model object.
  • Send the Model object down the wire to the client.

Traditionally this can be done without issue for WPF applications.  This is because both types of applications are running the full blown CLR.  They can share the same DLL and the WCF proxy will nicely convert the WCF message from the wire into a well typed Model object.

* A note about sending EF or Data Context objects down the wire.  While this will work, technically, if your client uses the full CLR (WPF / ASP.NET), it is highly discouraged.  Take a SQL Metal Data Context object for example.  When you send that type of object down to the client it actually has the ability to talk directly to the database bypassing your WCF layer (and any business logic you should have in your Model or Business Entity code).  Your tiering breaks down at this point your you break many good development practices.

When you throw Silverlight into the mix, the problem becomes a matter of CLR mismatch.  Your traditional Model class that you are sharing between the client and WCF service is built against the full CLR so you can not add the reference to your Silverlight application.  You could use the proxy generated code in the Silverlight application but this really breaks some of MVVM.

Take your ‘Employee’ Model code:

This Model will work for WCF, WPF and ASP.NET but will not work for Silverlight because the agCLR (Silverlight CLR) does not support the DataContract and DataMember attributes.  You could fake it and create a mock attribute in Silverlight but that seems like a poor architecture. 

Enter – Shared Class Files and Conditional Compilation

Visual Studio has had a cool feature for some time that lets you add a ‘Link’ to another source file in a different project.  Both projects will compile the code file and both projects can edit the code.  Physically, only one instance exists.

The Model / CLR dilemma can be solved partially by creating a new Silverlight Class Library project in your solution and adding a Link to the Model class. 

Now your linked class will not yet compile until you tell the compiler to ignore the DataContract and DataMember attributes when building for Silverlight.

You do this by wrapping your attributes in a conditional compilation statement.  This definitely  make the model code look a bit ugly, however the beauty is that now when you build your solution you will end up with a CLR and agCLR compiled version of the assembly.  There are other ways to do this with targeting and platform based builds, however, by doing it this way you can add project references to the Silverlight version of the Model and your project will be much better organized.



Below you will see the CLR Model (VMR.Model project) and the agCLR Model (VMR.Silverlight.Model project).


How do you add one of the Model class code files as a link to the Silverlight Class Library project?


Like normal, add an Existing Item to the Silverlight.Model assembly.  Locate the normal Model class on the disk.


Click the down arrow next to the Add button and choose Add As Link. 

Now you have one source for both your CLR (WPF) and agCLR (Silverlight) Model code.  By doing this the namespaces are the same and message deserialization is transparent on both platforms.  You can now use your ViewModel (your view model will need to be different for WPF and Silverlight because it will need to reference the platform specific version of the model) in your client code to retrieve the Model data and bind it to the XAML in your WPF or Silverlight application.

So here is the skinny:  Your WCF service blew up and that was the extent of your error.

Solution: Figure out why your WCF service blew up.

Some possible solutions:

You are returning too much data and your service config is causing the problem:


Increase your array length or your data length.

You are querying a WCF service cross domain (yes if your wcf service is hosted in Cassini you need to have a correct cross domain policy).


I use this for my development server / Cassini:


<?xml version="1.0" encoding="utf-8" ?>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
        <resource include-subpaths="true" path="/"/>

You are serializing an Enum and failed to decorate the Enum Values with the EnumMemberAttribute.



Still stuck? Turn on tracing and your stack trace will show the true error. (THIS WORKS!!)


Test your service with the WcfTestClient that comes with visual studio.

This will allow you to call the WCF service with a simple little tool.  The GUI allows you to double click on a WCF method and provide the parameters for the method.  The app calls the WCF service and reports the stack trace.

The GUI app is found here on 64 bit computers:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe

and here on 32 bit machines:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe

What is being sent to my WCF service or what is being sent or received by my Silverlight application?


Note:  This tool is VERY good for checking security on your Silverlight application.  I recently heard a company was hacked because they transmitted state information via XML to a server.  The user used an app like this or Fiddler to see the communication between the server and the browser and modified the response.  They stole a lot of $ by doing this.  Be WARNED!  Users are getting a lot smarter, do not assume your XML traffic is safe.

Working with Blend 3 for a Silverlight 3 project I needed to use a special font that I purchased for the project.  I received a warning after choosing the font.  (The font was installed in my fonts directory.)

The warning was:

The font, <font name>, isn’t a built-in Silverlight font.  You must embed this font for it to display in your Silverlight application.


So I poked around in the UI and found the Font Manager tool under Tools | Font Manager


In the Font Manager tool check off the fonts you want to embed.


This takes the .TTF font, adds it to the project under /Fonts.  Additionally when your project is compiled the font is embedded in a Fonts.zip file.  Your XAML will be updated to read FontFamily="Fonts/Fonts.zip#Kalinga".

Very cool!