I've been playing about with the monodroid (preview 8980) and I'm trying to create an application that will run on Android, WP7 and silverlight.
My plan is to create a single core class library and then a seperate project for each of the platforms that will contain the UI stuff - so one monodroid project, one for WP7 and a SL one, all of which will reference the core class library.
The main problem with this is that it will be possible to implement some functionality in the core library that will work fine on silverlight, but not on WP7 for instance. I believe the best way to make sure this doesn't happen is by making the core library a silverlight 3 project, as this will be the lowest common denominator.
The problem I am facing now is that I can't reference a SL3 library from the monodroid project. I get this warning - 'Warning 2 The project 'TMCore' cannot be referenced. The referenced project is targeted to a different framework family (Silverlight)'
Any ideas?
Bah I seam to always end up answering my own questions - http://www.gregshackles.com/2010/12/shared-libraries-for-windows-phone-7-monodroid-and-beyond/
according to
http://monodroid.net/Documentation/Assemblies
you must compile your core-stuffe into a seperate assembly you cannot share a core-dll.
> Note: MonoDroid is not ABI compatible with existing assemblies compiled for
> a different profile. You must recompile your source code to generate
> assemblies targeting the MonoDroid profile (just as you need to recompile
> source code to target Silverlight and .NET 3.5 separately).
Related
How do your write Xamarin platform specific code in a .net standard library?
I want to use namespaces like Xamarin.Forms.Platform.iOS in a .Net Standard Library..
Use case: I want to develop a .net library for my apps which includes a video player for the various platforms. This video player also has to interact with other code in the .net library.
Or is the answer I need to use a shared project or portable library?
You should not include platform specific code or use namespaces like the one you mentioned in your .NET Standard Library, the reason is that .NET is just a runtime environment.
It’s not the the main runtime environment that you would use on iOS or Android. These platforms use Mono - not .NET. Check this or this to see more details for how its structured.
If you need to execute something from your .NET Standard project which is related to platform-specific behavior, use Dependency Injection or Custom Renderers.
I have small problem - I'm trying to implement class that needs to contain a lot of events. Due to memory concerns I planned to implement EventHandlerList which is available for me in my Android Library project target also in my iOS Library project target but is not available for me inside PCL Project. Tried to change PCL Target project to most commonly used but none of them contained what i needed.
Type missing for my case :
System.ComponentModel.EventHandlerList
Is there any possibility to write such class once or I'm forced to write it two times because of missing PCL Target.
You will need Inversion Of Control (IoC) to use platform specific features or non-portable methods
Please take a look at this IoC example
Another option if you want to avoid IoC is to use Shared Project in Xamarin
I have been developing an app for Android, Ios and UWP.
Since I need a socket connection, I used DependenyService to access the "platform specific" code and started to implement my interface in all 3 projects.
The problem is that the implementation is exact the same in all 3 projects, because they all use System.Net.Sockets.Socket.
However I can't simply put the implementation code in my PCL and use it for all 3, because I can't reference System.Net.Sockets.Socket in my PCL. (doesn't exit there)
This picture shows the targeting section of my PCL
I think the problem is that my PCL targets ASP.NET Core 1.0, which doesn't contain an API for System.Net.Sockets.Socket.
However, I can't tell my PCL to stop target ASP.NET Core 1.0, because it gets targeted automatically.
So has anyone an idea how I can share code only between Android, Ios and UWP, or make my PCL only target them?
If the app should only support iOS, Android and UWP, you can switch to the PCL of the year 2016 and the future called .NET standard (>= 1.3).
In the properties of your PCL click Target .NET Platform Standard and select 1.3 or higher. If you don't have this option, you have to install/update some stuff. Requirements are listed here: https://learn.microsoft.com/en-us/dotnet/articles/core/tutorials/libraries
After you have done that, you are ready to use Sockets without using patterns like factory or dependency injection (which are the alternatives).
Or you use the Sockets plugin: https://www.nuget.org/packages/rda.SocketsForPCL
I'm building some code with these portable class libraries at present.
I'm looking to target full .Net, WinRT Metro, Windows Phone, ... and then MonoTouch and MonoDroid. My experiments today show this can work - http://slodge.blogspot.co.uk/2012/04/experiments-with-portable-class.html
However, I have hit a fairly significant problem - MonoTouch and MonoDroid currently support these libraries in that you can consume PCLs as binary assemblies, but they don't allow linking between project files
e.g. I can reference MyLib.dll from a MonoDroid project, but I can't reference MyLib.csproj.
This is a problem as it means automated (resharper) refactoring doesn't work - and I seem to rely on this for most of my work!
I've seen that Microsoft publish targetting packs that allow you to extend class libraries, but I've not worked out where these install to or what they modify.
Here's the current Microsoft list: http://msdn.microsoft.com/en-us/hh487282.aspx
Does anyone have any knowledge about what these packs contain or how someone might make their own pack? If they're not too overly complex, then I would like to have a go at producing one for MonoTouch and/or MonoDroid.
This has come up a few times recently, so I wrote a blog post that should do what you want:
http://jpobst.blogspot.com/2012/04/mono-for-android-portable-libraries-in.html
Please let me know if have any issues!
I have a project written in C++/CLI. Some of the types there are in managed code, and some are in completely native code. Let's say I have the produced DLL on a machine that dosen't have any version of the .Net framework installed, is there a way that another, native application will link with my "mixed-mode" Dll and use only the native types? I've noticed that the minute I add the "/clr" switch, my Dll automatically depends on several .Net Framework Dlls (mscorjit, mscoree etc.), and when I actually try to use the 100% native types defined in it, the application still tries to load those .Net Framework Dlls (even though I don't use the framework in that part of the code).
So, is it possible to avoid loading those Dlls in such case? (as I see it, the other option is to create another, native project, that will contain all of the native types, without the managed ones).
Thanks
No. When you load a mixed mode assembly (/clr), right after DllMain runs, the .cctor runs and initializes the framework, if it hasn't already been setup for the application.
Without this, there would be a big hit as soon as you called a function that required a managed API. For details, see "Initialization of Mixed Assemblies" on MSDN.
The best option would be to make your native API a separate DLL, and have the mixed mode assembly a separate project, so you can load it separately if required.