Strange behaviour with Microsoft.WindowsCE.Forms

Go To StackoverFlow.com

6

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?

2009-06-16 07:42
by mrtaikandi
What happens if you remove the static-keyword - Thorsten Dittmar 2009-06-16 08:40
The designer shows the error message - mrtaikandi 2009-06-16 09:58
Are you referencing that specific version (3.5.0.0) in your application? It could be a mismatch in version numbers from what version you assigned in the references and what version the designer actually can find - Tom van Enckevort 2009-06-16 14:09
The reference added automatically when I used the Input control. But I also tried referencing it directly to the "Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE - mrtaikandi 2009-06-17 10:20


4

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

2010-02-02 15:35
by Robin


2

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;
    }
}
2009-06-16 15:08
by ctacke


1

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"
2010-06-07 23:30
by Miros