Has anyone ever seen any MS documentation on implementing a CF ADO.NET 2.0 provider and supporting the VS design-time environment?
Me neither.
You wouldn't believe what I had to do to track this down. When a typed dataset exists in your VS project, VS will compile it in the background when it thinks it needs it. For example, when you open a form with a DataGrid on it.
To compile it, VS will copy over the SQLite library to a temp folder and run the compile against it. In this case, the SQLite library it copies is the CF library which of course will not run on the desktop. As a matter of fact, trying to load any DLL/exe marked as retargetable on the desktop will result in a TypeLoadException.
However, you CAN place retargetable assemblies in the GAC and if a better match for the platform exists in the GAC, the binding will redirect to the closer match.
You also can't turn off the retargetable flag in the CF assembly -- if you do then typed datasets break completely in CF projects.
So what was the answer? You'll love this ...
For the redistributable mixed CF DLL, I had to turn off the Retargetable flag in the assembly. Then I had to build another pure MSIL assembly without the interop library and WITH the Retargetable flag to place that DLL in the GAC as a placeholder.
So what happens is this:
- VS Copies the redist CF DLL to the temp folder. It's not marked Retargetable, so the metadata can be loaded.
- During the assembly loading phase, the GAC is consulted and an entry is found for this assembly, so binding is redirected from the disk DLL to the GAC entry.
- The GAC entry is marked as retargetable, so assembly binding is redirected yet again to the x86 GAC entry which is the desktop DLL.
- The typed dataset is now compiled using the desktop DLL.
You know, if it gets any hairier, I'm going to need a sturdier pair of shears.