I've got a PCL which includes System.Data.Linq(.Mappings) via the dll itself. This works with iOS, Windows and MacOS, but it does not with Android.
Temp: I will post the error message as soon as I am back at work, but I remember it was something like "Could not load file or assembly System.Data.Linq". It was not found
I know this namespace is not supported inside a PCL, but it is strange that it works (and yes, I made multiple projects with this) in every project type except Xamarin:Android.
Is there anything I could try like implementing the code myself, embed assemblies in native code, or something else?
Thanks for your help
Is there anything I could try like implementing the code myself, embed assemblies in native code, or something else?
I think no. As you already known, System.Data.Linq is unavailable in PCLs, and there is no lambda expressions in Android (or Java) yet. Also we need to respect the design of PCL, it is used to write and build managed assemblies that work on more than one .NET Framework platform. So if the method/dll or something else is not supported in the projects which uses this PCL, then this method/dll should not be placed in PCL.
Also, Xamarin.Forms is designed as a cross-platform UI toolkit that allows developers to easily create native user interface layouts that can be shared across Android, iOS, and Windows Phone. It is mainly target sharing UI. Of course you can also specify the platform when calling method/dll in its PCL, for example like this:
#if __MOBILE__
// Xamarin iOS or Android-specific code
#endif
For more info about specifying platform, you can refer to Dealing with Multiple Platforms.
Related
I am developing a Xamarin.Forms application for Android and iOS. The pcl project grew quite a lot and has many nuget packages installed like FluentValidation, SQlite and Newtonsoft.Json. The platform specific projects only have a few lines of code like custom renderer and stuff. The only references they have, is SQlite.
Now this works just fine when compiling for Android. However, when trying to build for iOS, I get an error -> Can not resolve reference (System.EnterpriseServices.Wrapper.dll).
My question is not specific to this dll, furthermore I'd like to know how it really works. I was assuming, I can install whatever package I want into the pcl project. Is there a limitation? Do the packages have to be compatible with Xamarin.iOS / Xamarin.Android? How am I able to track, where the dll actually comes from?
Why does it work in Android but not in iOS?
Yes, there are limitations between the platforms. The different assemblies and/or nuget-packages you use in the PCL-project, need to be comaptible for the platforms you are targeting.
The reason is quite simple: When you build your iOS-project, the PCL project is also building for the iOS target, and therefore the assemblies need to be compatible. The assemblies are just a subset.
Xamarin.iOS, Xamarin.Android, and Xamarin.Mac all ship with over a
dozen assemblies. Just as Silverlight is an extended subset of the
desktop .NET assemblies, Xamarin platforms is also an extended subset
of several Silverlight and desktop .NET assemblies.
When you want to use an assembly, which is only compatible for android, then add it in the android-project and not in the PCL project.
You can find a list with supported assemblies over the platforms on the Xamarin Developer page.
On this list you can see, that System.EnterpriseServices.dll is only available for android and not for iOS. Additionaly you cand find some limitations using SQLite/System.Data on the iOS platforms on this page.
I try to create a really simple app containing
Windows Version
Mac Version
Portable Class Library
I would like to put the code (as much as possible) into the Portable Class Library.
Now i simply want to check if a file exists using System.IO.File.Exists() but the File object is not available. I tryed to target different plattforms but i cant get it to work.
What #hvaughan3 said is correct in that the System.IO.File is not available from your PCL and it needs to be implemented within each platform and injected into your PCL. That said the good news is that like many of these common requirements there already is a plugin to do that so you don't need to do it yourself.
Have a look at the following blog post that describes how to use the PCLStorage plugin within your PCL project.
System.IO.File is not available in the PCL code. You will need to implement in platform specific code. You will also need to verify that it exists for each platform. I know it does for Android and iOS, have never tried using it on Mac and Windows. Although from Xamarin's docs it looks like at least Mac does have System.IO.File.
Once you have methods in each platform project, you can reference the platform specific method from your PCL code using Xamarin's Dependency Service.
I have a lot of business logic coded in C#. I donĀ“t know a lot about Xamarin, but as far as I know, you have to use the full framework. What I would like to do is just use Xamarin to compile the business logic into an android DLL and then code the Android app using them. Is it possible?
Thanks.
Depends on what code you actually have in your business objects.
Xamarin uses Mono which is open source port of .NET. It then takes the Mono code and compiles that to Android. Any 3rd party libraries you have referenced or use probably will not work. You would need to find a Mono library (still may be incompatible on Android) or an Android library that has the functionality you need and re-code those parts.
Xamarin does have the ability (with paid version) that let you to reference Java Jars and work with them in your C# Android project. This is most beneficial when the .NET/Mono library you were using does not work in Android, but an equivalent Android or Java library does.
Again, it is really up to whether or not any of the classes you use outside of your own have been implemented in Mono and then implemented in the Android versions of it.
I wanted to tryout C# for general purpose programming (not web development). I program in Windows environment, but I would like to avoid coding specifically for Windows (.NET), because I want to keep the option open for a future migration to Linux.
Are there any specific libraries in C# .NET that wouldn't work in C# Mono for general purpose programming work (not interested in Windows Forms, Silverlight and stuff like that) ?
Is there any internet link of things/features that provides a list that works on C# .NET wouldn't work on C# Mono or vice versa? I didn't readily find anything in google per se.
Note: I would be interested in specific answers, not opinions of which is better or worse (thanks!)
It is possible for a CLR assembly (even in the form of a DLL, as mentioned in the comments) to be read by Mono, as long as it does not have dependencies that do not exist in Mono, because...
...not every piece of code that compiles for .NET will compile for Mono, since there are lots of Windows-specific things in .NET (not strictly part of C#) that aren't implemented (WPF, ASP.NET async stack) or don't make sense at all in Linux (COM is one such example, I think).
Fortunately, there is a list of what .NET features are implemented in Mono. Even more fortunately, it seems they have an app that tells you a priori whether your code makes use of anything not implemented in Mono (but I have never tried it).
if you install xamarin (you need Pro or bigger so you have VS integration) you can create Portable Class Library that targets xamarin (which is based on mono) and visual studio will allow you to only use classes that are compatible with mono.
http://docs.xamarin.com/guides/cross-platform/application_fundamentals/pcl/introduction_to_portable_class_libraries/
apparently you can also use xamarin studio to create a PCL and there is a free version of that.
I am using C# to create a game using MonoGame which I wish to use on multiple platforms (which I know MonoGame can do).
Is there a way to create a .dll in C# and load it from other operating systems (preferably iOS, Android and MacOS) without recompiling the library? I am prepared to write a "loader" application for each platform, but would not like to rewrite the entire project.
I'm hoping there is a way to load functions from a .net dll (i.e. load the game) on these platforms without using paid products such as MonoTouch.
Basically the .NET/Mono Assemblies all get compiled to CIL Code which is an ECMA Standard.
However, you still have to program your game in a way that it do not depend on OS specifics.
Don't refer to certain .NET Assemblies (i.e. No WCF, cause it has only limited WCF support, no WPF at all, no WWF)
Don't refer to OS specific DLLs (i.e. no P/Invokes to kernel32.dll etc.
Don't use OS specific pathes or use preprocessor directives to make OS Specific code (yes, this will require recompile and you probably won't get around this easily)
Threading on Mono has some catches, so you will probably have to make platform specific code using preprocessor directives.
Honestly, I don't see a problem with having to recompile your code, if it's clearly written it's just a matter of adding a new project to your solution file and setting the preprocessor flags. Then all you have to do is compile the solution and have multiple DLLs in your bin folder. No one ever said you have to rewrite the complete project (unless the project is already finished and has any of the dependency mentioned up there), which in this case... it's your own fault for not having to think about it before starting development.
You'll just have to deploy your Apps (on iOS etc.) with the required Mono Runtime. And for this you will probably need something like Xamarin or wire up your own Mono runtime
Reference links:
http://www.mono-project.com/Compatibility
http://www.mono-project.com/MoMA
You can look at the Xamarin-Framework. But you always have to recompile your project.
Xamarin
on these platforms without using paid products such as MonoTouch.
This will be difficult.