views:

723

answers:

3

I have a Windows Mobile application in which I want to check the device orientation. Therefore I wrote the following property in one of my forms:

internal static Microsoft.WindowsCE.Forms.ScreenOrientation DeviceOriginalOrientation { get; private set; }

The strange thing is that after that whenever I open a UserControl, the designer shows this warning even if that UserControl doesn't use the property:

Could not load file or assembly 'Microsoft.WindowsCE.Forms, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Commenting the above property will dismiss the warning and shows the user control again. The application is built successfully and runs without any problems in both cases.

Does anybody know why this happens and how can I fix it?

+1  A: 

Yes, this is pretty much expected. Since it's a static property (which I'd disagree with in the first place) the designer has to initialize it, which means loading up Microsoft.WindowsCE.Forms, which means loading device-specific entry points. Admittedly, the error message sucks, but then the designer support for device stuff has lots of fun issues that are hard to divine the causes for.

I'd try moving it to another class or wrapping it with a check to see if you're in the designer. Something like this works for us:

protected bool IsDesignTime
{
    get
    {
        // Determine if this instance is running against .NET Framework 
        // by using the MSCoreLib PublicKeyToken
        System.Reflection.Assembly mscorlibAssembly = typeof(int).Assembly;
        if ((mscorlibAssembly != null))
        {
            if (mscorlibAssembly.FullName.ToUpper().EndsWith("B77A5C561934E089"))
            {
                return true;
            }
        }
        return false;
    }
}
ctacke
+1  A: 

This problem cost me a couple of hours. I solved it by adding the Microsoft.WindowsCE.Forms.dll to the GAC using gacutil. Hope it helps. Robin

Robin
+1  A: 

If you copy the Microsoft.WindowsCE.Forms.dll to a subfolder in your project for example, and then add the following to the pre-build events of your project, it will also work just fine if you eg. reinstall your PC:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /i "$(ProjectDir)SubFolder\Microsoft.WindowsCE.Forms.dll"
Miros