Monthly Archives: October 2010

Combining OPF3 with Windows Communication Foundation

I've been experimenting lately with Windows Communication Foundation (WCF) and OPF3. I created two classes, one for OPF3 and one for my WCF service. It became increasingly tiresome to maintain both classes whenever the table was updated. I really wanted to clean up my code by removing any "convert-from-opf3-object-to-wcf-object" functions, so I decided to combine both of them!

This solution worked better than I thought it would. Now I have an object that can be loaded straight from an SQL query and returned from my WCF contract to the client Silverlight application. Really all it involved was adding a couple more attributes and viola! Here's an example of what the final class looked like.

[Persistent( Rights = PersistentRights.Load )]
[DataContract( Name = "DiveSite", Namespace = Information.DiveService.DataObjects )]
public class DiveSite : BaseServiceContract, ISelfContainingObject, IContainsFaultDetail
{
    [DataMember]
    [Field( "DIVESITEID" )]
    public int DiveSiteId { get; set; }

    [DataMember]
    [Field( "DIVESITENAME" )]
    public string DiveSiteName { get; set; }

    [DataMember]
    [Field( "PRIMARYDIVESITETYPEID" )]
    public int? PrimaryDiveSiteTypeId { get; set; }

    [DataMember]
    [Field( "MARKERTYPEID" )]
    public int MarkerTypeId { get; set; }

    [DataMember]
    [Field( "ISBOOKMARKED" )]
    public bool IsBookmarked { get; set; }

    [DataMember]
    [Field( "LATITUDE" )]
    public decimal Latitude { get; set; }

    [DataMember]
    [Field( "LONGITUDE" )]
    public decimal Longitude { get; set; }

    [DataMember]
    public DiveSiteDetail DiveSiteDetail { get; set; }

    public FaultDetail FaultDetail { get; set; }

    public ObjectInfo ObjectInfo { get; set; }

    public static List<DiveSite> GetDiveSites( Location northWest, Location southWest )
    {
        return ObjectContextFactory.ObjectContext.GetObjectSet<DiveSite>( new SqlQuery( "EXEC spGetPublicDiveSites " ) ).ToList();
    }
}


With the addition of the DataContact and DataMember attributes I now could have one class that could be loaded with OPF3 and then sent to the client. Really helped with cleaning up any "conversion" functions.

Visual Studio 2010 Designer Exception: UnresolvedAssemblyException

Recently I've run into an issue with while coding in XAML. Here at Pure Logic we have a custom library that handles our user input validation. Simply, the library has static methods such as IsEmail and IsPhoneNumber.

I wanted to leverage the power of XAML Validators and our custom library to create a regular expression ValidationRule. The goal was to create a ValidationRule that could be added to the Binding.ValidationRules element. Seemed easy enough to do. All that was left to be done was make a call to the validation library on the Validate method. The app compiled and worked like a dream. However, there was one issue that annoyed me greatly.

Any XAML that included one of my validators would throw a dreaded System.Reflection.Adds.UnresolvedAssemblyException within the designer. I has assumed that Visual Studio would just pull my custom library from the bin folder of my application, or even look up where the reference was from the project. But that's not the case. I took a screen shot so you can see what I was dealing with.

Designer Exception

The frustration of not being able to see what I was working with in the designer was driving me mad. After some digging around I found a solution to my problem. Microsoft has bundled a tool with the .Net framework called fuslogvw.exe. This little tool allows you to view the binding failure log.

I cleared out the log file, and started up fuslogvw.exe (VS command prompt). Then I opened up Visual Studio and waited for the designer to throw an exception. The exception was logged and showed up with fuslogvw.exe.

After reading through the log I found a number of locations as to where Visual Studio 2010 was looking for my custom library. I picked one of the locations, dropped my custom library in, and presto everything worked! I ended up dropping my in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies but you can pick any of the locations listed in your log.

Hope this helps!