More than one export was found that matches the constraint

Don’t deploy the same assemblies twice …MEF DeploymentCatalog and Reference¬†assemblies

Making WCF RIA Services work in a DMZ/Multitier architecture using Application Request Routing

If your web services are running on a server that is not in the DMZ and you are not able to open port 80 to these services either then you will encounter a common scenario. Your Silverlight application will not be able to connect to these services because it can’t get to the clientaccesspolicy.xml file that is required to access services on a different server to the one that served your Silverlight application.

If you hosting your Silverlight application on a machine running IIS 7.5 (Windows Server 2008) then help is at hand – click here for more details.

Telerik Silverlight RadGridView Styles etc.

To save me repeating myself ūüôā …

Styles, StyleSelectors and BasedOn – a working solution

Silverlight/WPF Design Time data

Like all good things, its simple and straight forward. For more details take a look at this post

INotifyDataErrorInfo & Silverlight 4

Mike’s post provided me with a very useful solution.

Silverlight events and the CallMethodAction

I have been using the CallMethodAction behavior to call specific methods when an event is raised. The CallMethodAction can call either:

  1. A public method that takes no arguments and returns no value
  2. A public method whose signature matches that of the event handler

I had used the first option a couple of times quite successfully but had difficulty getting the second option to work using the DisplayDateChanged event for a DatePicker control. That was until I came across this post which provided me with the necessary pointers to get my DisplayDateChanged event to work. I just needed to ensure:

  • The signature of my method matched that for the DisplayDateChanged event handler (of course)
  • The method needed to be listed in the ViewModel I was using for the DataContext of the DatePicker control

So my markup code for the DatePicker looks like this:

<telerik:RadDatePicker .... >
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="DisplayDateChanged">
      <ei:CallMethodAction MethodName="SetRadioButtons" 
        TargetObject="{Binding}" />                                           
    </i:EventTrigger>
  </i:Interaction.Triggers>
</telerik:RadDatePicker>

And the ViewModel code for my SetRadioButtons method is declared as:

public void SetRadioButtons(object sender, CalendarDateChangedEventArgs e)

Solution – XamlParseException [Line : 0, Position 0] in Expression Blend Design Mode

Sometimes it just really helps to read the manual. This is a link to my post in the Expression Blend forum.

Silverlight StringFormat bug

If your StringFormat is not working as you would expect take a look at this solution.

Silverlight and Session variables

I have seen numerous postings about how to access Session data from the current HttpContext using WCF. A simple example can be found here. Whilst looking for a solution to another Silverlight problem I came across this post about passing large text to SL using initParams and it got me thinking. Could I use the same concept to read my Session variables?

The short answer is Yes, with a few small changes. My initial problem was that my session variable contained a class of complex types. In order to serialize this I just need to mark the class as [Serializable]. I then set my initParams value:

<param name="InitParams" value="<%=InitParams%>" />

In the code behind for the page hosting the SL control I added:

protected string InitParams { get; private set; }

Then I just needed to convert my Session variable to a Base64 string during the Page_Load event.

MemoryStream stream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
serializer.Serialize(stream, <my session variable> );       // Of type MyClass
stream.Position = 0;
string data = Convert.ToBase64String(stream.ToArray());
InitParams = "SessionDetails=" + data;

In my Silverlight Page, I just had to do the reverse to get my class back from the Base64 string.

if (App.Current.Host.InitParams.ContainsKey("SessionDetails"))
{
    MemoryStream ms = new MemoryStream(Convert.FromBase64String(App.Current.Host.InitParams["SessionDetails"]));
    StreamReader sr = new StreamReader(ms);
    string s = sr.ReadToEnd();

    sr.Close();
    sr.Dispose();

    ms.Close();
    ms.Dispose();

    // Parse the string so we can determine the contents of the Session variable
    XElement xElement = XElement.Parse(s);
}

And that is about it. The only other thing that is required is a bit a LINQ to get to the necessary values within the Session variable. Obviously this only works if you need to read in the Session variables one time when the SL control loads, but for me this was perfectly suitable.

Silverlight, Firefox and initParams

My ASPX page hosting my Silverlight 4 control was working perfectly well within IE8 but when I load the same page in FF (3.6…) I just kept getting the nice MS logo asking me to download and install Silverlight. I knew the SL add-on worked in FF because I had tried other applications.

As it turned out the problem was my initParams value which was initially blank and was to be configured in the code behind. The solution came from this post in the MS SL forum. For some reason, in all other browsers except IE, the initParams value must contain a value. I followed Eric’s solution and my problem was solved.