In Xamarin, Is it possible link to a .NET 4.0 assembly? - c#

I don't have Xamarin yet, and i want to build some application both for android and windows, each will use same shared library.
Is there a possibility to link .NET 4.0 assembly to Xamarin ios/android project, without recompile?
This assembly reference to System only, uses SQLite-NET by praeclarum, which requires native Windows library sqlite3.dll.
As i heard, on Mono/Xamarin? Mono.Data.Sqlite is required instead sqlite3.dll, but i am not sure, can i keep my library "cross-platform" with it? Or i will have to change something?
Unfortunately, i cannot check this currently.
Thank you..

.net assemblies can't be linked to Xamarin Android/iOS but you can link PCLs or you can create a Xamarin Android/iOS project, link files from your .net assemblies there and resolve possible problems with conditional directives (#if...).

Related

Monogame UWP - Including a DLL library causes error

I'm creating a Monogame UWP Project and whenever I make a call to an included very basic compiled DLL .NET Core library within the project it throws the Error: Could not load file or assembly System.Runtime 4.1.0.0
Here is the project Sample:
http://www.filedropper.com/game1_2
Is everyone else getting the same Error? How do I go about fixing this issue?
Kind regards, Josh L.
As #iinspectable said in the comments:
You cannot reference a full .NET assembly from a UWP project.
UWP is a thing on it's own, and is basically incompatible with .NET as it needs to run on all Win10 platforms (where .NET is meant to be run on Windows PC). Now i don't know monogame, but if it's a .NET Library, it's incompatible with UWP.

Do i have to recompile a .dll in order to use it on a Mono Android Project?

I have recently acquired the student licence of Mono Android from Xamarin.
After making a simple project, i decided to start using some DLL's i am familiar with such as Json.Net and H.A.P on my Android Application (mono project), and that's when the problems started.
After trying to pull those references from NuGet, they failed since the "Android Application" project is not known leading to no .dll installed (NuGet tries to match the project type with the correct .dll to be downloaded be it WindowsPhone, .NET4, .NET 3.5 and so on).
So i moved on to mannually referencing the libraries, since i have them downloaded on my PC. Referencing Works, but as soon as i try to access the HtmlAgilityPack it raises an exception.
Error CS0012:
The type 'System.Xml.XPath.IXPathNavigable' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Xml, Version=x.x.x.x, Culture=neutral
The exception is raised on the first execution of the code because of J.I.T compilation of .NET, i know this.
Question:
How can i use my "so loved" .dlls on my Mono Android Project?
Do i need the source code of those libraries in order to use them on my projects?
Thanks in Advance
In order to recompile an assembly you will need the source.
To see what assemblies are provided by Xamarin.Android and Xamarin.iOS you can visit these two pages:
http://docs.xamarin.com/guides/android/advanced_topics/assemblies
http://docs.xamarin.com/guides/ios/advanced_topics/assemblies
One way to recompile it would be to make a Android Class Library or iPhone Class Library and add a link to all the files in the original source and then compile it. Or when Xamarin have their PCL support done, do something similar just in a PCL so that you have one DLL targeting multiple platforms.
You may also find this post useful, which briefly describes how to compile HtmlAgilityPack against Xamarin.Android: http://forums.xamarin.com/discussion/comment/2139/#Comment_2139 You might need to alter some things as this is from December 2012, since then things might have changed.

Visual Studio 2012 How to debug "Unable to add reference to project x" error?

In Visual Studio 2012 in a blank new Class Library I am trying to add reference to an existing project in the solution, also a Class Library, MonoGame.Framework.Windows8 (https://github.com/mono/MonoGame), but get the error:
Unable to add reference to Project MonoGame.Framework.Windows8
I have built the existing library, MonoGame, successfully and made it a dependency of the new one. What could be the problem?
(It's extremely annoying the error message does not give a reason!)
Trying to add the built dll has a reference gave a more explicit error message which has solved the problem for me, it said:
“A reference to ‘x’ could not be added. The project targets ‘.NetFramework’ while the file reference targets ‘.NetCore’. This is not a supported scenario”
The MonoGame Class Library is a Class Library (Windows Store apps) type! (The bit in parenthesis is important! Presumably the difference is the Windows Store apps type use .Net Core which is not the same as .Net Framework).
So to get it working your project must be a Class Library (Windows Store apps) which is available under the Windows Store option in Add New Project.
I suspect the problem is to do with the 'Target Framework' in project options.
I don't know how MonoGame works for Windows 8 but when you're developing for Android the target framework options are the different versions of Android [e.g. Android 2.2 (Froyo)]. When you create a regular class library you have choices between the different versions of the .NET framework or Mono [e.g. Mono / .NET 4.0].
Unfortunately, these frameworks are not compatible with each other. You can't add a project reference for Android to a .NET framework class library and visa-versa.
The solution is to use a Portable Class Library. They are specifically designed to deal with this issue. The downside is that you will only have access to the subset of assemblies provided in the lowest denominator you choose to target.
You might also want to consider code sharing between projects using linked files. It can make maintenance a little trickier but gives you a little more control over code that should compile in both target frameworks but doesn't fit into the portable class library. Here's a related question:
Project reference vs. file links in Mono multi-target projects
The key to all of this once you understand what's going on here is how you structure your solution. With a little care you can have nearly all your code shared across different platforms.
I might be because of both projects are using different Framework versions and change the Framework versions in both Projects of properties section then your problem might solve.
Same question I guess here:
Visual Studio 11 metro apps unable to add reference?
The answer was:
What are you adding a reference to? Metro style apps can only add references to other Metro style class libraries or portable class libraries

Google APIs Client Library for .NET on Windows Phone 7 Project

Is it possible to use Google APIs Client Library for .NET in a WP7 project?
I've tried to add a new reference to DotNetOpenAuth.dll and I'm getting the folowing error.
Reference cannot be added to DotNetOpenAuth.dll because it was not built using the Windows Phone runtime. Windows Phone projects will work only with Windows Phone assemblies.
Is it possible to solve?
Try Portable Library Tools from MSDN. Read about them here. Now reference Google .Net library in the portable library, also reference this portable library project in WP7 project. Now, write a small wrapper over the Google apis in the portable library project and use them from your WP7 project. Referencing works but I did not use it, you can give it a try once.
I would think it would be possible to use the Google APIs from WP7. I've not used them myself, but it looks like you use them by making HTTP requests which, if memory serves me right, is possible on WP7.
With regards to the DotNetAuth.dll it is more then likely built against the Full or Client Profile version of the .NET Framework and therefore can't be used by WP7. In order to do this, then a WP7 specific version of the assembly will be have to be compiled.

How to compile a .NET assembly against Silverlight?

I am trying to compile AvalonEdit for Silverlight, but I am not sure how to do it as I never worked with Silverlight, only WPF.
I tried to add this control to my Silverlight application but Visual Studio complained that the assembly wasn't compiled against Silverlight.
I thought it was gonna be a matter of picking Silverlight under the target platform in the project settings.
Any ideas?
Silverlight and WPF assemblies are not compatible. So any assembly you reference from your Silverlight assembly must also have been compiled as a Silverlight assembly. I'm assuming your reference to "project settings" is your assembly, not the third party assembly.
But, compiling WPF code as Silverlight may be challenging. Silverlight is a functional subset of WPF so the code may use features not available in Silverlight.
You need to create new project which targets silverlight (File - New Project - Silverlight) and then add all the source code from the AvalonEdit source code into that library.
Edit:
Also note that the control might use classes that are not available in Silverlight. From the codeplex discussion related to this control (from year 2009):
Silverlight does not have the System.Windows.Media.TextFormatting namespace, so you'd have to rewrite a large part of the ICSharpCode.AvalonEdit.Rendering namespace if you want to port AvalonEdit to Silverlight.
In silverlight projects you can't reference non-silverlight dll's or projects. So in this project if there is an essential non-silverlight dll for building this project. You cant do this build.
If there are just some usages wfp supports but silverlight doesnt support find out this differs.
Then exclude these codes or use pragma
#if !WPF
//Todo
#endif

Categories