Sharing assets between the .NET Compact Framework and the .NET Framework

22
Sharing assets between the .NET Compact Framework and the .NET Framework Chris Tacke OpenNETCF Consulting www.OpenNETCF.com [email protected]

description

Sharing assets between the .NET Compact Framework and the .NET Framework. Chris Tacke OpenNETCF Consulting www.OpenNETCF.com [email protected]. FAQ. “I want to run the .net compact framework on the desktop. How to?” - PowerPoint PPT Presentation

Transcript of Sharing assets between the .NET Compact Framework and the .NET Framework

Sharing assets between the .NET Compact Framework and the

.NET Framework

Chris TackeOpenNETCF Consultingwww.OpenNETCF.com [email protected]

FAQ

• “I want to run the .net compact framework on the desktop. How to?”

• “I tried to use my own desktop dll on my PocketPC and it didn’t work. Help!”

Why do I care?

• Enlarge your market

• Kick-start projects by leveraging existing biz logic

• Get an edge over competitors

• Impress your manager!

• Same principles for cross-device code

• Use PC tools against your code to improve netcf development

Agenda

• Set the scene• Why?• Differences

● .NET• Visual Studio, Language, Framework, CLR

● Platform• Windows Mobile vs Windows XP

• Share code● 1 failure and 2 successes

• Gotchas, tips and tricks● Code it, stub it, catch it, test it

Visual Studio for Devices

• Visual Studio 2005 Standard● Nothing additional in “Higher” versions

• Resx format• Form factors• Emulator• Debugging• Remote tools• Change Target Platform• Targets both v1 and v2

C#, VB – no other languages

• Everything from a language perspective is there. No limitations● With CF v1.0, volatile keyword was not supported

• …but everything is volatile anyway on CF

• VB’s language includes support libraries● No Microsoft.VisualBasic.Compatibility● Compactness on main VB lib as with other Fx ones● No late binding

• IL statements not supported● calli, localloc

“Framework Compactness”

• No ngen• No ASP.NET server• No Remoting• No runtime hosting• No code access security• No binary serialization, no Reflection.Emit• No codedom, no configuration• Trimmed namespaces (XSLT), classes

(Button.Image), method overloads etc

CF-specific classes v1.0

• Microsoft.WindowsCE.Forms● InputPanel, MessageWindow/Message

• System.Net.IrDA● IrDAXXX

• EndPoint, Client, DeviceInfo, Listener

• System.Data.SqlServerCE● SqlCeXXXX

• Command, CommandBuilder, Connection, DataAdapter, DataReader, Engine, Error, ErrorCollection, Exception, Parameter, RemoteDataAccess, Replication, Transaction

CF-specific classes v2.0

• Microsoft.WindowsCE.Forms● HardwareButton● MobileDevice.Hibernate● SystemSettings.ScreenOrientation● DocumentList● Notification● LogFont

• Microsoft.WindowsMobile.DirectX● .Direct3D

• SqlCeResultSet

Windows Mobile 5.0

• Has its own additional classes● Part of the platform● Not part of NETCF● Can be used by both CF v1.0 and CF v2.0

• Microsoft.WindowsMobile● .PocketOutlook● .Configuration● .Status● .Telephony● .Forms

CF CLR

• Garbage Collector● Mark and sweep (not generational)● 3 phases: Simple, Compact, Full● Triggered by

• Allocation failure• App goes to background• 750KB allocation in v1.0 (1MB in v2.0)

• JIT (iJIT & sJIT)● No ngen, Pitching, 64KB limit

PPC vs desktop

• Input Methods• Form/Dialog size• Navigation Between applications• App/Form Closing• Take Over the Device – don’t!• File System• Memory Constraint (resource constraint)• Deployment

Is common UI a good idea?

• Is non-UI code affected by these?● Input Methods● Form/Dialog size● Navigation Between applications● App/Form Closing● Take Over the Device – don’t!

• Even if you can do it, should you?● Different UI guidelines on each platform● Least common denominator

“Thank you for the background…

…now tell me how to do it!”

Full Fx assemblies on device

• TypeLoadException• MissingMethodException• Different PKT

● 969DB8053D3322AC (device)● B77A5C561934E089 (desktop)

• “I insist that there are no desktop assemblies in my CF package/solution”● Use the loader log● Use VS2005 output window (build)

CF assemblies on PC

• Retargetable● CF binaries can be executed on PC

• Not the other way round, as we saw

• Runtime conditional paths● System.Environment.OSVersion.Platform

• CF-specific assemblies will bomb● TypeLoadException● FileLoadException

Share the code, not the binary

• Compilation Constant● Two projects, two outputs, one set of code

files● Build platform-specific binaries from same

source

Gotchas, tips and tricks

• Solution/project setup• Stub it

● E.g. InputPanel, Serializable

• Partial Classes● WinForms, Other code

• Runtime differences• PInvoke• Class Designer• Code it

● SDF from OpenNETCF is a great example

OpenNETCF:SDF v2.0 Full Fx classes

• .ComponentModel.● BackgroundWorker● Licens*

• .Win32.SafeHandles.*• .Configuration.*• .Net.

● Ftp.*● NetworkInformation.*

• .Diagnostics.● Stopwatch● FileVersionInfo● EventLog

• .IO.● DriveInfo● FileSystemWatcher

• .Runtime.InteropServices● SafeHandle

• .Threading.● EventWaitHandle● Semaphore

• .Drawing.ColorTranslator• .Windows.Forms.

● GroupBox● IMessageFilter● NotifyIcon● SendKeys● PowerStatus

• .Media.SoundPlayer

How VS2005 & CF v2.0 improved the Everett story

• Common Resx file format• Predefined constants• Docking and anchoring• Fx compatibility• Partial types• Data access code simpler• Deploy to MyComputer

● Enable TODO

Conclusion

• Create desktop versions of your assemblies● Use conditional compilation

• If commercial, change the UI to be platform-specific● Architect your product to that effect

Questions?

• Thank You!