I'm trying to build iOS app using Microsoft EWS managed API. I've downloaded the msi from http://www.microsoft.com/download/en/details.aspx?id=13480 and copied the DLL under the solution folder. When building for the simulator, it builds and runs fine, but when trying to target the physical device, mtouch fails with:
Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -v --nomanifest --nosign -dev "/Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Users/Projects/HelloMonoTouch/MyEWSApp/ThirdParty/Microsoft.Exchange.WebServices.dll" -linksdkonly -sdk "5.0" "/Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe"
Framework is: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
Copied /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/MyEWSApp.exe
Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/mscorlib.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/monotouch.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/Mono.Security.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.Core.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.Xml.dll
Copied /Users/Projects/HelloMonoTouch/MyEWSApp/ThirdParty/Microsoft.Exchange.WebServices.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/Microsoft.Exchange.WebServices.dll
Linking SDK only for assembly /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe into /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app
Could not link assemblies: System.IO.FileNotFoundException: Could not resolve: System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
at Mono.Linker.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
at Mono.Linker.LinkContext.Resolve (IMetadataScope scope) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at MonoTouch.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
mtouch exited with code 1
I diligently added:
System.DirectoryServices.dll
System.Configuration.dll
System.Security.dll
System.DirectoryServices.Protocols.dll
System.EnterpriseServices.dll
with a growing feeling of not being on the right track, but when mtouch complained about native System.EnterpriseServices.Wrapper.dll, I gave up.
I've tried to play with Project Options/iPhone build SDK and Linker options.
I've also tried both 32-bit and 64-bit versions of Microsoft.Exchange.WebServices.dll
P.S. I know that I could consume EWS without Managed EWS API, but writing and parsing all these XML requests and responses is such a pain.
Both the MonoTouch's linker and the AOT compiler needs all dependencies to be present when doing their work. That, and missing symbols (types, methods...), makes it hard (but not totally impossible) to re-use pre-built binaries from another version of the framework.
It also explains why this can sometime (no missing symbols) work on the simulator. By default the simulator builds are set to "Don't link" (no linker) and the JIT (no AOT) is used. This allows missing references/symbols to go unnoticed... until they are (potentially never) needed.
You can turn off the linker for device builds - but that won't help the AOT compiler. OTOH you can try to satisfy the linker and it could be able to remove enough of the code to let the AOT compiler do its work properly. Sadly when things go down to native code, like System.EnterpriseServices.Wrapper.dll, your options becomes much more limited.