Strange behavior with Microsoft.WindowsCE.Forms

I have a Windows Mobile application in which I want to check the orientation of a device. 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 this, when I open the UserControl, the designer shows this warning, even if this UserControl does not use the property:

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

Commenting on the above property will disable the warning and display the user control again. The application was successfully created and works without problems in both cases.

Does anyone know why this is happening and how I can fix it?

+6
c # visual-studio-2008 compact-framework
source share
3 answers

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

+4
source share

Yes, this is pretty much expected. Since this is a static property (which I would not agree with in the first place), the designer must initialize it, which means loading Microsoft.WindowsCE.Forms, which means loading entry points for a specific device. Admittedly, the error message sucks in, but then the designer support for the device has many interesting problems that are difficult to explain for reasons.

I would try moving it to another class or wrapping it with a check to find out if you have a designer. For us it works:

 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; } } 
+2
source share

If you copy the Microsoft.WindowsCE.Forms.dll file to a subfolder in your project, and then add the following to the pre-build events of your project, this will also work very well if you, for example. reinstall the computer:

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

All Articles