How do I use JSON.Net on a new Mono class library? - json

I wish to use JSON.Net on a brand spankin new Mono class library (say .. Mono / .NET 4). Of course, this class library will be used by a MonoTouch iPhone/iPad project (also in the same solution).
I'm not sure of the steps I need to do, to use JSON.Net in a Mono Class Library.
The closest I got to this was this SO question .. but it said nothing about how the DLL was made, where it exists, etc.
BTW: I'm also using MonoDevelop for the IDE. This is on a Mac OSX.

If your mono is new enough, you can in fact use NuGet downloaded from here. You also need some trusted certificates to get it working well - they can be imported using:
mozroots --import --ask-remove
And then you can download the package using NuGet
You can also download the library any other way - no need to recompile the sources as Mono and .NET are binary compatible.
Btw, binaries can be directly downloaded from nuget in a way like that:
Json.Net.

Related

Entity Framework with IoT Background Application

Visual Studio provides a "Background Application (IoT)" template which i want to use to create a headless webservice. To persist some data i want to use Entity Framework with SQLite as DB-Engine .
After upgrading UWP to 5.2.2 and installing Sqlite and EFCore.Tools and adding a DbContext i wanted to migrate the first version. It fails:
PM> Add-Migration MyFirstMigration
Project 'BackgroundApplication4' is a Windows Runtime component. The Entity Framework Core Package Manager Console Tools don't support this type of project.
I thinks it's not a problem with EF itself, because it worked for me with a simple "Blank App". Now there are some questions coming up: Is a "Background Application" really a WinRT-Component and has a different (unsupported) handling by EF?
I thought UWP is an extension of WinRT so basically each UWP-App must be a WinRT-Component?
EF in a Windows Runtime component is a no-go; but that is not so bad since WinRT component can depend on class libraries. So move all your EF classes to a own class libary and consume that library from your background task in your Windows Runtime component.
By doing this you can also use the same class library also in the foreground app when needed.
P.s. Check the github page of EFCore and UWP. There are lot of issues especially in combination with .net native. so using EF.core in UWP will cause you lot of headache; but it is possible.

Using cocos2d-x as a static library results in linker errors on mac os

I am trying to use cocos2d-x as a game engine, and I have already tried using RubyMotion and MonoTouch to check if it is possible to use cocos2d-x binaries.
But both, RubyMotion and MonoTouch, are suffering from the same linker error:
duplicate symbol _SHA1 in:
libcocos2dx.a(sha-1.o)
libcocos2dx.a(sha1_one.o)
I did a research and figured out following:
_SHA1 symbols are defined in libcurl.a which packed as precompiled static library inside of cocos2d-x externals. During building cocos2d-x XCode calls libtool to create a universal binary libcocos2dx.a And according to this article libtool itself creates duplicated symbols (in some cases related to category bug).
Though author states how he has solved similar problem in his case, I am not sure how to apply his solution to my case (if at all it can be applied).
I am not sure where to go from here, since I hoped to use either Ruby or C# to develop my game. Is it possible to solve this libtool/linker problem and get static library without duplicated symbols?
P.S. Please note that if I use same cocos2d-x binaries as a xcode project inside my XCode project, then everything is good. But I want to code in ruby/c#.
As an option you could use project template for MacOS which comes with cocos2d-x samples. We've made several projects (two of them are already at the store) this way.

Xamarin + JSON.Net

I'm having trouble understanding why the Newtonsoft JSON parser has to be device specific under Xamarin. I cannot seem to find any way to have the parser exist in a common, shared library. I'm using the Tasky Pro sample app. I can get the JSON.Net DLLs from the Xamarin store to work in the Android and iOS projects, however that makes no architecural sense. E.g., the SQLite stuff is all in a shared lib, as you'd expect - as one set of c# source files.
Ideally I'd like to just add some kind of reference to "Tasky.Core" and be able to serialize/deserialize JSON.
Is there any way to get JSON.Net to work in a shared library (across droid/ios/wp8)? The source is pretty huge to try to manage as linked files, if that's even possible...
If not, is there some alternative way of managing JSON that will work in this way?
You should be able to use the JSon.NET NuGet Package for this. The implementation is actually platform-specific [1], but NuGet will transparently take care of that for you and pick the correct one for you.
Note that you need Mono 3.2.6 and Xamarin.iOS 7.0.6 for this, which just hit the alpha channel this week, I have just fixed some critical bugs in this area. You should also upgrade the NuGet Add-In in Xamarin Studio to the latest version (0.8), which contains several PCL-related bug fixes.
Simply add the NuGet Add-In to Xamarin Studio if you have not done so already, then search for "JSon.NET", the add-in will automatically install the package and add the required library references for you.
[1] The NuGet package contains different .dll's for different target frameworks and then picks and references the best one for your project - so your application will only contain a single implementation, but an iOS app may use a different one than a desktop application.
Update 01/14/14:
NuGet packages usually contain different implementations - unfortunately, not all of them will work with Xamarin.iOS due to APIs such as Reflection.Emit or Full DLR that are not available on iOS.
If you look into the packages/Newtonsoft.Json.5.0.8/lib/ directory, you'll see different sub-directories - each of these contain a different implementation and NuGet will use the one that best fits the current target framework. Unfortunately, NuGet does not always pick the right one :-(
For Newtonsoft.Json.5.0.8, the "portable-net45+wp80+win8" implementation uses DLR features that are not available on iOS, the "portable-net40+sl4+wp7+win8" one is ok. So if you add the NuGet package to a PCL that's targeting for instance Profile136, you'll get the correct implementation.
There is no GUI to choose another implementation, but you can edit the .csproj file. Replace
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\portable-net45+wp80+win8\Newtonsoft.Json.dll</HintPath>
</Reference>
with
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll</HintPath>
</Reference>
and it should work.
In general, when you're getting an error message about missing types after adding a new NuGet package, go to the corresponding package directory and grep -r for that symbol - chances are that there's a different implementation which does not use this type.
Hopefully, a more elegant solution will be available in the future, but that needs coordination with the NuGet team and package authors, so it'll take some time.
Just add it to Shared Library via NuGet. Actually, all your request/response tasks should be done in library. You should use JSON.Net to parse response.

How targeting .NET 4.0 with Mvvmcross?

I want to use Mvvmcross to make application for several platforms.
I use Profile 104 for PCL library like Mvvmcross, but this profile target .NET 4.5.
I want to target .NET 4.0 to use my application on Windows XP.
To do that, I add the xml files
MonoAndroid, Version = v1.6 +. Xml
and
VSMonoTouch, Version = v1.0 +. Xml
in the profile 143 which allows me to target. NET framework 4.0.3.
However, I have a compilation error because it can not find the ICommand interface.
This interface is not in the same library between version 4.0 and 4.5, is it why it doesn't work ?
Or should I recompile all Mvvmcross libraries with profile 143?
thanks,
This is a Portable Class Library limitation.
See the table on: http://msdn.microsoft.com/en-us/library/gg597391.aspx
Model-View-View Model (MVVM)
Only 4.5
This means that if anyone wants to use MvvmCross on earlier .Net platforms then someone has to build and maintain a non-PCL version.
Since the maintainer of Mvx (me!) has decided to only maintain PCL versions of MvvmCross, then any non-PCL support will have to be created by the community.
For WPF this shouldn't be too large or difficult a job - but it might be...
Alternatively, somebody might be able to do something funky to get the ICommand working... I've retagged this question with portable-class-library to try to lure in some of the MS experts.

Does mvvmcross support windows phone 8?

I'm working my way through the MMVMCross Tip Calculator tutorial.
Got an Android instance up and running and have now turned my attention to Windows Phone 8.
So far, I can't find the Cirrious.MvvmCross.Plugins.Json assembly in the WindowsPhone bin folder, and I'm also having issues with the CreateApp() method not being able to resolve the Core.App class (there are a bunch of suggestions for chasing down the Core namespace but none of them have an App class inside that I can see).
When I comb through the docs it seems WP7 is supported explicitly, but no mention of 8. Anybody have any luck getting this scenario going? Is there a hack I'm missing?
After installing the Nuget package (The HotTuna Startup) in an Andriod project, I was unable to build and was getting the same problem in the CreateApp() where Core is not resolved. I had missed adding the package MVVMCross.Core and MvvmCross - Hot Tuna Libraries (which added the app.cs) to my core PCL library. Those Nuget packages are a great way to get started!
It's obvious now, but maybe this will help someone else.
Yes, Windows Phone 8 is supported, but there's no specific extensions for WP8 yet (e.g. we still use the Community C# SQLite code)
The Core.App class should be in your Core/application project. e.g. in the tutorial it's in https://github.com/slodge/MvvmCross/tree/vnext/Sample%20-%20Tutorial/Tutorial/Tutorial.Core