Unable to use System.XML.Linq - xamarin.android

I am working on a project using Mono for Android. After reading a cross-platform document with Xamarin. I had my data layer in a separate project and was going to move it to my Mono for Android project and then link those files to my Mono Touch project, and one day perhaps a Windows Phone 8 project.
When I moved the code, I am now unable to compile because of the System.Xml.Linq reference. The reference shows in the Mono for Android project, but I am unable to use it. I thought aiming for Froyo may be the problem, but upgrading the project to Gingerbread or Ice Cream Sandwich didn't help.
Does anybody know what I am doing wrong? I am a seasoned .NET developer and am well aware of how references work in project, but this one has me stumped.
The project the original code was working on was targeting the Mono/.NET 4 framework

Is your reference to System.Xml.Linq pointing to the .Net version or the Mono version? The one for Mono will have Version 2.0.5.0.
Also, is the reference to System.Xml.Linq in a Android Class Library/Application or in a regular .Net Class library. If it is a .Net Class library, I would try referencing the library in your Android application as a compiled (dll) reference and not a project reference. It is not a perfect solution, but I have found that this works when I needed to reference libraries that I use across multiple solutions. The reference will generally work out fine, but if there is anything that is not supported in the Mono version, then it can cause issues.
Assuming you have your code in a class library, your best bet may be to create a Mono specific version of your library project. You can import and use the same class files, but just add some Conditional compilation symbols to have it compile properly for Mono. If you are not familiar with this, take a look at how Json.Net or ServiceStack manages code for multiple platforms.

Related

how to use protobuf-net in the xamarin ios pcl

I am trying to use protobuf-net with the new xamarin ios pcl, and it's nuget packet doesn't appear to support the framework. Is there a way to import protobuf-net into the pcl?
Update:
I just found recompiling the PCL with the new Xamarin PCL definitions allowed the resulting library to be references. Nice work! Let me know when a new version is posted to Nuget.
The NuGet package includes PCL drops, but it is unclear to me what change you would have me make to the NuGet package here, as there is no specific "Xamarin" target that I know of; the example targets are described here; protobuf-net currently includes a broad target of portable-sl4+net40+wp7+windows8. If you know of a target (or indeed a PCL build combination) that works for Xamarin for iOS, please let me know.
I should also note that the NuGet drop is the "Full" implementation, where meta-programming is performed at runtime. Because of the limitations in iOS, you may find you get better performance by using the "CoreOnly" implementation combined with the "precompile" tool, available from the google-code drop. This is described here.
I was able to use NuGet version of protobuf-net by manually editing the .csproj file for my portable library and setting the target framework profile to match protobuf-net:
<TargetFrameworkProfile>Profile136</TargetFrameworkProfile>
The resulting portable library worked well with Xamarin.Android. According to this list, it should work with Xamarin.iOS as well.

Json.NET under Unity3d for iOS

has anyone succeeded to adapt/port Json.NET to a version able to run under Unity3d deployed to iOS (and the webplayer, and android, too, but these seem less problematic), somehow overcoming the AOT issues there?
Or are there plans to release a compatible version of Json.NET?
Many thanks,
Max
You can use netstandard version of Newtonsoft.Json in Unity and it works fine. It seams that this library has changed some inner implementations to not use System.Reflection.Emit for deserialization anymore.
Just be sure that after downloading nuget package you get Newtonsoft.Json.dll from netstandard2.0 folder, not from net45. And also don't forget to specify in link.xml that System.Linq.Expressions.Interpreter.LightLambda class shouldn't be stripped (it's used for deserialization) along with libraries/classes that you use for deserialization (to preserve constructors). Your link.xml should look smth like this:
<linker>
<assembly fullname="Your.Dto.Package.Name" preserve="all" />
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
</assembly>
</linker>
We use this library in all our projects for Android and iOS with IL2CPP and Mono runtimes.
Moreover, unlike Unity's JsonUtility, Newtonsoft.Json fully supports any type of objects, including Dictionary.
Microsoft Example
Newtonsoft Json fails AOT in iOS and also fails at deserializing anything inheriting from KeyedCollection in the webplayer. Here's a version that has been fixed:
JSON .NET For Unity (Supports iOS)
We use MiniJson and so far it serves our json needs well :)
I have been facing the same issue for a while and searched on every nook and cranny of the internet to look for a solution. Here's what worked for me.
I replaced NewtonSoft.Json with NewtonSoft.Json for Unity
Uninstalled NewtonSoft.Json from Unity's Nuget package manager.
Install NewtonSoft.Json for Unity with Unity's package manager. Follow this installation steps
What's the difference?
NewtonSoft.Json for Unity is different from standard NewtonSoft.Json
NewtonSoft.Json does not support AOT targets for IL2CPP builds in Unity
NewtonSoft.Json for Unity supports AOT targets such as all IL2CPP builds (WebGL, iOS, Android, Windows, Mac OS X) and portable .NET (UWP, WP8).
Hope this helps. Cheers!
Nope AFAIK.
LitJson and JsonFX would be alternate choice for Unity3D.
http://wiki.unity3d.com/index.php?title=UnityLitJSON
Have a look at the modified version of LitJson: UnityLitJson
Actually LitJson has some issues and is not always working as expected, so I created a simple JSON-Lib that can handle all Unity3D Types, Enums and arbitrary classes. Find it at GitHub: Tiny-JSON
You can use it very simple:
// encode
Animal a = new Animal(4);
string json = Json.Encode(a);
// decode
IList<Animal> a = Json.Decode<IList<Animal>>("[{\"legs\":4}, {\"legs\":2}]");
Yes, we share code on client and server and use an older version when it was called NewtonSoft.Json. Works in IOS, Android, everything.
Search for NewtonSoft.Json, and you could probably find an archive.

How to use sharpziplib in Monotouch?

Hi I need to unzip a file in Monotouch for an iOS (and Andriod later) App and sharpziplib looks like a good choice (is it?). But how do I go about adding it in MonoDevelop (I have the latest version)?
I have downloaded ICSharpCode.SharpZipLib.dll, but how/where is it added to my project (solution)? Can anyone give me step-by-step instructions?
Also which .net version of the DLL should I be using? There are three: net-11, net-20, netcf-20 (i think it's the last one but would be good to have that confirmed).
You must create a MonoTouch class library project for ICSharpCode.SharpZipLib and add the corresponding source files to that project.
Then you can either reference the resulting assembly or the project itself in your solution.

Use existing DLL in iOS app through mono framework

For one of my current iOS project, some business logic has been provided to me through a DLL and Native C++ binding code that i have to recompile in a dynamic library (dylib) and then use the DLL through this dynamic library.
Finally the DLL is used like this example:
int main(int argc, char** argv){
RTEnvironnement::CreateRTEnvironnement("../dll/RT.dll");
RT::RT_Facade * mFacade = new RT::RT_Facade();
RT::RT_Data_Projet * mProjet = new RT::RT_Data_Projet();
mProjet->Load_From_XMLFile(argv[1]);
...
Objects RTEnvironnement, RT_Facade, RT_Data_Projet are provided by the binding C++ dynamic lib. I cannot get the code of the base DLL and i have to use the DLL as it is on IOS.
I'm currently studying if mono touch can able my IOS app (basic iOS Objective C based on Xcode ), to launch the DLL that as been build with the standard mono framework. Before purchasing a license, I have to be sure that MonoTouch is able to do this.
Is someone do something similar ? Is there a simplest way to this ?
If i choose to use MonoTouch, can i keep my project in Xcode and just build the dylib in MonoDevelop and then import the lib the Xcode project ?
Thanks for your help.
the DLL that as been build with the standard mono framework.
MonoTouch (like Mono for Android) provide a base class library (BCL) profile that is similar (a superset) to Silverlight. However it's a subset of the whole Mono framework.
As such it's very common that assemblies compiled against the full framework won't work on MonoTouch unless they are re-compiled (against the MonoTouch BCL).
If i choose to use MonoTouch, can i keep my project in Xcode and just build the dylib in MonoDevelop and then import the lib the Xcode project ?
It's more complicated than that (e.g. MonoDevelop won't give you a .dylib). You might be able to google some instructions to do this, however be aware that this scenario is unsupported.
An supported alternative is to make MonoTouch drive the application, load any assemblies you need, expose those and then transfer control to your Objective-C code.

Is the AWS.net library compatible with MonoTouch?

I'm working on a new app using MonoTouch and I'd like to store data in AWS.
I saw there is an AWS.net library available from Amazon, but I don't know if I can use it with my MonoTouch app. Can I?
standard .NET binaries won't work, per FAQ: http://monotouch.net/FAQ (Can I use standard desktop Mono assemblies or .NET assemblies with MonoTouch?).
Edited: All you need to do is rebuild the source code with Mono's C# compiler
I think the better option is to use the AWS SDK for iOS and write bindings to the Obj-c library. There are examples out there of how to write bindings if you just do a search for it. It probably isn't the quick solution you were hoping for but you probably don't want to use the SDK for .NET anyway as it probably wasn't intended to be used on the iPhone.
If you do end up writing bindings for it, please post it on github for everyone else to use. Solve once for many, right? :)
For standard upload of files from monotouch to S3 I used this Library ,
recompiled in MonoDevelop using MonoTouch Library Template and done ( use System.Web.Services instead of System.Web ).
Recompile AWS for monotouch has to be really difficult because of the heavy use of System.Web and IOrderedDictionary ( ThirdParty Libraries ).
I just built the AWS SDK for Monotouch/Mono for Android. I had to modify some files and add some classes from the current Mono release.
GitHub repo is located here:
https://github.com/fr500/aws_sdk_monotouch_monodroid
It's my first attempt at this, and it's working but I don't know if my approach is correct. Any help will be appreciated

Resources