Common Library .NET and CF.NET

  • Thread starter Thread starter Neelima Godugu
  • Start date Start date
N

Neelima Godugu

Hi,
I am looking for "how to" on building a common library project that can be
used both in a .NET and CF.NET projects.
I have looked in the groups but was not able to figure out if this was
really possible.
Appreciate your help.
Thanks
Neelima Godugu
 
If you target .NET CF with your DLL, it will run on the desktop, too, as
long as you didn't use any CE-specific stuff. The reverse is *not* true;
DLLs targeted at the desktop will not run on Windows CE devices.

Paul T.
 
It is possible as long as:-

* Your dll is compiled to target the Compact Framework (it will be
retargetable to the desktop framework)
* You don't use any Compact Framework specific functionality:-
System.Net.IrDa
System.Data.SqlServerCe
Microsoft.WindowsCE.Forms

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Hi,

I made exactly that - several times. Here are my experiences and
suggestions.

1) Of course you have to limit your usage of the .NET Framework to the
common subset of both.

2) In my components I avoid to have _any_ GUI stuff in the components that I
share among .NET and .NETCF. I guess you should avoid having any GUI stuff
in your libraries, too. The GUI is what makes the platforms so different. So
leave that to the platform specific application and outside of commonly used
libraries.

3) You must test thoroughly on both frameworks because there are some subtle
differences (Some that I found and remember: String.Replace(string,string)
with newValue=null works on big .NET as documented but leads to exception on
..NETCF; HttpWebResponse is IDisposable and must be disposed in big .NET but
does not even implement IDisposable in .NETCF; etc...). Expect to find quite
a few of such small compatibility glitches.

4) If you encounter a serious incompatibility, or even have to do some
P/Invoke stuff (which is almost always different), it is probably best to
use some conditional compilation (in C#: #if / #else / #endif). I don't know
whether there is any officially suggested symbol for .NETCF, I just define
and use WINCE and bracket platform dependend code with #if WINCE / #else
/#endif. IMHO: Visual Studio should define some platform symbol in all Smart
Device Projects by default.

5) The resulting binary .dll of a build is not fully portable across .NET
and .NETCF. It is in some cases (.NETCF builds should work on full .NET 1.1)
but not in the general case.

6) Therefore, you must make two completely separate builds. One as a Smart
Device Application project (although it will only be a library), and another
as a Class Library project (always assuming you will use Visual Studio).
Both builds can be made from the same source code though.

7) To organise these builds, perhaps the best solution is to use
VisualSourceSafe. There you can create two separate project branches and
share all common source code between these branches. Thus you can be sure
that both builds are always made from the same source code. Do not share the
project files .csdproj and .csproj as these are different. Also I do not
share the AssemblyInfo.cs as I use that to mark my builds differently. To do
so, you will have to use VisualSourceSafe through its own GUI and disable
the VSS integration in Visual Studio which always messes things up if you
have shares. (Interestingly the old pre-.NET Visual Studio was able to
handle this. The new VisualStudio.NET VSS integration got much worse and is
better switched off completely)

Final advice: The complete .NET reference documentation is obviously made
from the full .NET framework (and development team) and there is no _real_
documentation of the .NETCF. Therefore it often contains information that is
plain wrong for the .NETCF. So take care and test a lot.

Good luck!
 
Another example of wierdness related to IDisposable is the fact that the
SolidBrush implements Dispose but does not seem to implement IDisposable. If
you try to use a SolidBrush in a 'using' statement like:
using (SolidBrush b = new SolidBrush(Color.Black))

You get a compiler error stating that: Cannot implicitly convert type
'System.Drawing.SolidBrush' to 'System.IDisposable'
It must be that SolidBrush does not implement IDisposable, but since
SolidBrush inherits from Brush which is documented to implement IDisposable,
I don't understand why this error occurs.
 
Hi,

although Brush is documented to implement IDisposable, it does not do so in
the .NETCF. However the Brush also does implement Dispose(). Which makes me
wonder whether the SolidBrush is nothing but a holder for a Color value and
whether Dispose() is needed to be called at all.

The Pen class, which is very similar in concept, does implement IDisposable
and Dispose().

Would be nice if someone could clear up things about IDisposable and Dispose
with Pen and Brush classes in .NETCF

Andreas Selle
 
Another object that doesn't correctly implemnt IDisposable as documented is
SqlCeDataAdapter. It should implemnt IDisposable because of inheriting from
Component, but it doesn't. It does, however, implement Dispose()
 
Back
Top