Silverlight Listbox binding to itemssource does not work

by 31. January 2011 20:25

  Or at least so I thought as I spent a few hours trying to make it work.

What made this issue particularly interesting is that it works/worked on the Windows Phone platform; my open source project shares the same exact source code for the Desktop, Silverlight and Phone environments.   As with the Phone application, my presenter populated the ViewModel with data and all looked well.   To further complicate matters my other control bindings (to the SelectedUserProfile) were working - only the ListBox.ItemsSource was not working...

I had just completed the Phone UI work (having no issues) and started working on the Silverlight version of the UserProfileView.xaml view and for the life of me I could not get the ListBox.ItemsSource to work unless I assigned it programmatically!

Turns out that, unlike the Phone (and perhaps Desktop??? I'll find out when I'm done with the Silverlight UI), the Silverlight ItemsSource binding does not work if you bind to an ObservableCollection<yourtype> list WHEN IT IS NULL at the time of binding!  The following highlighted code fixed my problem and it now works as expected.

PRISM 2.2: can't use StaticResource when resource is in App.xaml

by 22. June 2010 20:09

I lost count of the number of variations of "can't use StaticResource" that I BING'd for over the last couple of days; countless hours banging my head against the desk.

This adventure started when I created a prototype from the DirectoryLookupModule sample from the Prism 2.2 package (ref this prototype link).  As you can see from the link it went through a major transformation and it wasn't until the MVPVM infrastructure was in place (with Business and Data access layers consuming a simple service) that I started to implement a DataTemplate.

The problem was I couldn't access my DataTemplate from the merge dictionary entry for App.xaml UNLESS I made it a DynamicResource.  Where this worked just fine the pit-bull side of me had to know why....

It wasn't until the second day that I noticed that "all" of the resources in this sample application were using DynamicResource, it was this revelation that started the road to discovery.   At the end of the road was the following obsure little declaration in the constructor.   The Prism bootstrapper was being loaded during the constructor versus OnStartup!  This little oversite prevents the StaticResource from being usable in the Shell or any of its Modules.

The happy ending on this story was that while updating the Prism forum with this tidbit (it was where I started my journey to discover the cause of this odd-ball bug) I noticed that Prism 4 had a Drop 2 so  naturally  I downloaded it and at first was somewhat dismayed that Unity was no where in the picture but was shortly taken aback by MEFs angle at the problem; it was very cool to say the least and I am now in the process of moving my MVPVM prototype to Prism 4.


Unit Testing ASP.NET/Client Application Service / Programmatically Starting Web Development Server (WebDev.WebServer.exe)

by 27. March 2010 09:02

What is seemingly a very simple process turned into quite the adventure - a costly one in terms of following dead-ends and beating my head against the wall - I first started with the programmatically started service (failing miserably) and evolved into the attribute driven approach which I finally got to work but it had constraints.....

I will detail how to make both methods work, highlighting areas left out of available blogs and research material that will result in errors that yield no answers on the internet.  

The adventure started with an annoying problem with my EHR unit test - I have a number of test that test the Client Application Service (for security) and if I don't manually start up the ApplicationService web service they will fail - this morning I rolled up my sleeves and decided to automate this process so at any time I can run all test in solution and have the service automatically start for the test that depend on it.

Below shows the syntax for the StartWebApplication() TestContext extension method that does the job of starting up the service during test initialize programmatically. 

Before going into more detail the following source demonstrates how to use the attribute method for starting the ApplicationService:

THE KEY to using attributes is to first ensure you have the namespace available - you'll find many resources that will correctly inform you that you must use the following:

using Microsoft.VisualStudio.TestTools.UnitTesting.Web;

However, what is not easily found is the DLL that this unit test resides in!!!   After a long search and destroy mission (online failed) I started searching the Microsoft.VisualStudio DLLs and found it in the Microsoft.VisualStudio.QualityTools.WebTestFramework 

A second piece of information that can really eat your lunch if it escapes you is that you MUST have a DEFAULT.ASPX file in the service!!!  Since I was using a Client Application Service (which doesn't even have a service, never mind a default.aspx file) I ran into the errors you'll see below that affected both the programmatic method as well as the attribute method.   Ensure you have a Default.aspx file.


I could be missing something but I could not get a breakpoint to work on the unit test that had this attribute - this was unacceptable but at least I got the web development server to start automajically (for the first time) so I was going to make it work.   I decided to have an initialize (empty) service that would start the service so that it was available for the rest of the unit test.

I then ran into a problem - you cannot control the order of your test (outside of an ordered test).  I want to be able to "run all test in solution" and have it work (which it currently does).   I saw blogs that tell you that you can use the Priority attribute but it doesn't work - later this was confirmed on the MSDN site that holds the information for this attribute; it clearly states that this is not used by the test engine and is only for developer use.

My work-around; I found that the same test always is the first test to run so I put the attribute on it :)  Ugly work-around but it works.   You'll find it on my CanGetCloudContainer() unit test which is always the first test to run in the solution.   Later I was able to get the programmatic approach to work consistently (by adding a default.aspx file) so I really don't need this solution but keep it in there as a code reference (for this blog).   I did code the TestContextExtension so that if a WebDev.Server is available it will not attempt to programmatically load it.   This supports both "all unit test in solution" (attribute) and the programmatic approach (if running only that test fixture during development).


ERROR:  The ASP.NET Web application at 'C:\_\_EHR\Layers\Service\GWN.EHR.ApplicationService' is already configured for testing by another test run. Only one test run at a time can run tests in ASP.NET. If there are no other test runs using this Web application, ensure that the Web.config file does not contain an httpModule named HostAdapter.

This error occurs if you are using the attribute method and you crashed out of the unit test.   Behind the scenes when the test starts the Web.Config is modified; the HostAdapter is added to it.  When the test are all completed it is removed.  If you crash out of the test and this is not removed then you will see the above error.   To watch this at work simply load your Web.Config of your service and run the test - you will be notified when the Web.Config file is changed (first to add and the second to remove the HostAdapter statement).

ERROR:  The Web request 'http://localhost:2035/AppService' completed successfully without running the test. This can occur when configuring the Web application for testing fails (an ASP.NET server error occurs when processing the request), or when no ASP.NET page is executed (the URL may point to an HTML page, a Web service, or a directory listing). Running tests in ASP.NET requires the URL to resolve to an ASP.NET page and for the page to execute properly up to the Load event. The response from the request is stored in the file 'WebRequestResponse_CanGetCloudBlobConta.html' with the test results; typically this file can be opened with a Web browser to view its contents.

The above error occurs if the the web application/service does not have a Default.aspx file.   If you debug the test you'll see the ASP.NET Web Development Server load, the test will fail and then the Web Development server will close.

With the Default.aspx file missing you can see the "in progress" test below fails for a "Configuration Error".   At other times I could get the programmatic approach to work without the default.aspx however I will ensure I have one to ensure I don't stumble upon the following error again:


The error for CanGetCloudBlobContainer (attribute load of Web Development Server) above had the following "The web site could not be configured correctly" error also: 

Source code for TestContext extension that loads the WebDev.WebServer.exe follows:

using System.Diagnostics;

using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace GWN.Library.Tests.Extensions


    public static class TestContextExtension


        private static Process _currentProcess;


        public const string WebDevWebServerExe =


        public static string StartWebApplication(this TestContext testContext,

            string appName, string port, string fullAppPath)


            if (_currentProcess != null)

                return null;


            // If other processes, i.e., attribute process, loaded webserver

            // then don't run this process (it is already available).  We only

            // run one service at this point so we'll worry about multiple ones

            // when the need arises..

            if (Process.GetProcesses()

                .Any(process => process.ProcessName.Contains("WebDev.WebServer")))

                    return null;


            var fullWebPath = string

                .Format("/port:{0} /path:\"{1}{2}\" /vpath:\"/{3}\"",






            var startinfo = new ProcessStartInfo(WebDevWebServerExe, fullWebPath)


                    WindowStyle = ProcessWindowStyle.Hidden,



            _currentProcess = Process.Start(startinfo);


            return fullWebPath;



        public static string GetRootPath(this TestContext testContext)


            var offset = testContext.TestDir.IndexOf("TestResults");

            var path = testContext.TestDir.Substring(0, offset);

            return path;




ATTRIBUTE APPROACH (full source since image is cut off)

/// <summary>

/// Determines whether this instance [can get BLOB container].

/// </summary>



   @"C:\_\_EHR\Layers\Service\GWN.EHR.ApplicationService", "/AppService")]


public void CanGetCloudBlobContainer()


    // Get list

    var blobList = client.ReadContainerList();


    // Get first container

    var blobContainer = blobList.FirstOrDefault();




    // Use first container (name) to get container from list

    var cloudBlobContainer = client.ReadContainer(blobContainer.Name);


    // Assert the names match

    Assert.AreEqual(blobContainer.Name, cloudBlobContainer.Name);


Unable to load DLL 'sqlceme35.dll': The specified module could not be found

by 3. October 2009 00:49

If you are running x64 then you'll need to install the following:

Microsoft SQL Server Compact 3.5 Service Pack 1 and Synchronization Services for ADO.NET version 1.0 Service Pack 1 for Windows Desktop

This threw me for a loop because my form would simply load without any data.  As a result I would be stepping through code (stepping over my data layer) and my form would activate with nothing in it.   Drilling down deeper I discovered the view would activate on line 228 below:

  222 public DataBindingList<T> ExecuteList<T>(string sqlCommand, ListDelegate<T> listDelegate)
  223 {
  224     try
  225     {
  226         DataBindingList<T> dataList = new DataBindingList<T>();
  228         using (SqlCeConnection conn = new SqlCeConnection(ConnString))
  229         {

This had me scratching my head wondering if some of the Async processes were messing with my debugger.   Since it worked on the 32-bit development box (which I don't currently have with me) I had no reason to suspect foul play on my x64 development box - this misconception resullted in much head-banging time.   

I should have payed attention to this error earlier, as it would reveal itself, but more towards the end of the debugging session and not on line 228 above; it would reveal itself as a messagebox not attached to any particular line of code.  I wrongly had suspected corrupt dlls as I am dabbling in a multi-targeting application (code shared between mobile and winforms).   It wasn't until I placed the try/catch (shown above) that the error revealed itself within the scope of the process.

Hopefully you'll hit this blog before the others because Head-banging occurred longer than it needed as I ended up chasing rouge blogs on this topic that had me going in circles until I figured out they were dead-ends. In the end the fix was quite simple - simply install SP1 and everything started working. 

Your Silverlight developer components are out of date

by 21. July 2009 10:41

After getting Expression Blend 3 up and running I was ready to run the Zune sample and was greeted with the prompt to upgrade my Silverlight - I ran it and was then stopped by the message "Your Silverlight developer components are out of date".

This message had me banging my head for a while because I had just finished installing everything new on my x64, Windows 7, Visual Studio 2008 sp1 beta box.   Everything is the latest software in addition to Beta and CTP development apps!

The clue came from a situation I ran into with Visual Studio 2010 - it wouldn't convert Silverlight applications from Silverlight 2 to Silverlight 3, to be more specific it would act like it converted it successfully but the project never showed up.   VS2010 has a hardcoded reference to the 2.0 folder references; my work-around was to copy the 3.0 folder to 2.0 (I have a blog on this somewhere as well as an incident reported to Microsoft).

So my assumption was that Expression Blend 3, like Visual Studio 2010 has some hard references to Silverlight tools 2 so I installed it from the following link:

I was happy to see it install without complaints about Silverlight tools 3 being installed and I found I could now successfully run the Expression Blend 3 sample!!

The key to upgrading is to install old stuff!

Where is Microsoft.Expression.Interactions?

by 21. July 2009 10:09

That's the question I was asking after installing Microsoft Expression Blend 3.   It appears that two DLL references are missing - or at least misplaced.

They are located at C:\Program Files\Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries. 

In my case (64bit) it was C:\Program Files(x86)\... as shown in the image that follows.

Add the references and all will be happy. 

Below you can see that after adding references our view will display.   Note Expression Blend 3 offers 140 controls! 


Blog videos and references to CodePlex projects are no longer valid