Using Assembly.LoadFrom(Filename) to load the same DLL on CF & FF

J

Jon Brunson

Is it possible to load the same DLL on the Full & Compact frameworks
using Assembly.LoadFrom(Filename)?

I've written a plugin-based application, which works brilliantly atm.
However I want to expand it so that the stuff that is currently
PDA-based can be done on a PC, and I don't particularly want to have two
seperate DLLs (Plugins) that do exactly the same thing, one for each
framework.

I've tried loading the PDA Plugins in a test PC application, and they
load ok - so long as they don't use any PDA-specific stuff (mainly
caused by using the OpenNETCF, as those DLLs wont load on the desktop).

So the next thing I tried was creating a PC DLL which references the
OpenNETCF, and wrote different code like so:

[VB.NET]
Friend WithEvents btnShowCalender As Control

Public Sub New()
MyBase.New()
InitializeComponent()

If Environment.OSVersion.Platform = PlatformID.WinCE Then
Dim btn As New OpenNETCF.Windows.Forms.ButtonEx
btn.Image = Me.imgButton.Images(0)
btn.TextAlign = OpenNETCF.Drawing.ContentAlignment.MiddleCenter
btn.TransparentImage = False
Me.btnShowCalender = btn

Else
Dim btn As New Button
btn.Image = Me.imgButton.Images(0)
btn.TextAlign = ContentAlignment.MiddleCenter
Me.btnShowCalender = btn

End If

Me.btnShowCalender.Location = New System.Drawing.Point(176, 0)
Me.btnShowCalender.Size = New System.Drawing.Size(24, 21)

Me.Controls.Add(Me.btnShowCalender)

End Sub
[/VB.NET]

And this works perfectly on the PC, but when I attempt to load it on the
PDA, I get a TypeLoadException - presumably because the DLL references
the full framework System dlls.



So, after all that, how do, or indeed /can/, I create a single DLL that
loads & works on both frameworks?
 
P

Peter Foot [MVP]

The only way for a single dll to run on both platforms is if it is compiled
as a Smart Device (.NETCF) application. But here you are limited to lowest
common denominator functionality only. There are two options:-

Set the properties in the desktop version using reflection (incurring an
overhead) so your code won't refer to any unsupported properties on the
device side
Take the OpenNETCF source that you require and build and sign your own
version of the dll. Create another project with exactly the same naming,
versioning and signature as a desktop dll and remove the implementation from
the classes and simply have them inherit from the desktop controls e.g.

public class ButtonEx : Button
{
}

This approach will work so long as all the properties are a direct match for
the desktop equivalents, for any other properties you can either provide a
stub with no implementation or do a bit of massaging to call the required
properties/methods on the desktop control - for example when the
OpenNETCF.Drawing.ContentAlignment enumerator is used your wrapper would
have to set the equivalent System.Drawing.ContentAlignment on the base
Button class.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

Jon Brunson said:
Is it possible to load the same DLL on the Full & Compact frameworks using
Assembly.LoadFrom(Filename)?

I've written a plugin-based application, which works brilliantly atm.
However I want to expand it so that the stuff that is currently PDA-based
can be done on a PC, and I don't particularly want to have two seperate
DLLs (Plugins) that do exactly the same thing, one for each framework.

I've tried loading the PDA Plugins in a test PC application, and they load
ok - so long as they don't use any PDA-specific stuff (mainly caused by
using the OpenNETCF, as those DLLs wont load on the desktop).

So the next thing I tried was creating a PC DLL which references the
OpenNETCF, and wrote different code like so:

[VB.NET]
Friend WithEvents btnShowCalender As Control

Public Sub New()
MyBase.New()
InitializeComponent()

If Environment.OSVersion.Platform = PlatformID.WinCE Then
Dim btn As New OpenNETCF.Windows.Forms.ButtonEx
btn.Image = Me.imgButton.Images(0)
btn.TextAlign = OpenNETCF.Drawing.ContentAlignment.MiddleCenter
btn.TransparentImage = False
Me.btnShowCalender = btn

Else
Dim btn As New Button
btn.Image = Me.imgButton.Images(0)
btn.TextAlign = ContentAlignment.MiddleCenter
Me.btnShowCalender = btn

End If

Me.btnShowCalender.Location = New System.Drawing.Point(176, 0)
Me.btnShowCalender.Size = New System.Drawing.Size(24, 21)

Me.Controls.Add(Me.btnShowCalender)

End Sub
[/VB.NET]

And this works perfectly on the PC, but when I attempt to load it on the
PDA, I get a TypeLoadException - presumably because the DLL references the
full framework System dlls.



So, after all that, how do, or indeed /can/, I create a single DLL that
loads & works on both frameworks?
 
Top