Porting a C# library to windows phone 8? - c#

I was using the Math.NET Neodym library for a project on Visual C# for a winforms application.
Here's the project's link: Math.NET Neodym
Now, I want to port it over to Windows Phone 8, When adding a reference to the library in the WP8 SDK, I get an error along the lines of:
a reference to a higher version or incompatible assembly cannot be
added
Now, I've asked this question before, and Ive been told that I can port the library to WP8 by recompiling it. And I have no idea how to? Do I just copy paste each file from the Library into a new WP8 library project and compile?

The easiest way would be to convert the project to a Portable Class Library. This would allow it to be used by Windows Phone as well as desktop apps.
You should be able to just open the solution, and change the appropriate project properties to do this. However, if any types are not supported by the target framework(s), you'll need to rework or remove those portions of the library.

Please see the answer to this question at a previous post. This might not be an issue with "higher version", just VS2012 having an irrelevant error message.

Related

Xamarin - Android - SQLite - Which C++ Library?

A bit of background...
SQLite is an open source C++ library compiled for multiple platforms. There are several commonly used C# wrappers for this library on several different platforms. Some of the common ones are:
https://github.com/praeclarum/sqlite-net.git
https://github.com/mattleibow/Mono.Data.Sqlite.git
https://github.com/oysteinkrog/SQLite.Net-PCL.git
Here is my one which is a stripped back fork from SQLite.Net-PCL.
https://github.com/MelbourneDeveloper/SQLite.Net.Standard.git
There are multiple versioning issues around SQLite on the different platforms, but recently, a big version issue came in to play on the Android platform. You can read about it here:
http://ericsink.com/entries/sqlite_android_n.html
According to Xamarin:
Note: Due to a change by Google, Android N will now only permit linking to NDK-provided native libraries. libsqlite.so is not an NDK-provided native library. Consequently, existing apps using e.g. Mono.Data.Sqlite.dll will crash when running on Android N. This may include other SQLite-using assemblies, not distributed with Xamarin.Android.
Xamarin.Android 7.0, which is part of Cycle 8, updates Mono.Data.Sqlite.dll to include a custom built version of libsqlite.so, named libsqlite3_xamarin.so.
https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/
So, my questions are: which Android C++ library should we be using for Android? Does the version depend on the version of the Android OS installed? Where do we get the C++ library from?
It sounds as though Google will only allow a customized version of the library. I guess this means that they will only accept signed libraries and the one compiled from Xamarin will be accepted. If this is the case, how do we get this library and package it up in a .NET Standard DLL, or include it in an Android app package?
I ask this question because this issue has been pointed out in my library here:
https://github.com/MelbourneDeveloper/SQLite.Net.Standard/issues/5
I feel like this is connected to the versioning issue. Anything that can shed some light on this would help. In my repo mentioned above, I have created a branches called Issues/5 which uses a different C++ library called libsqlite3_xamarin which seems to be bundled with Mono.Data.Sqlite but I still get the above issue when my phone goes to sleep.

Use OxyPlot in Windows Universal app c++/xaml project

I am new to windows app development. I want to use OxyPlot in UWAP C++/Xaml project. I am able to use it in C# based project but not in C++/Xaml project. First I tried to add it using Nuget package manager but it didn't install. Then I followed this (https://social.msdn.microsoft.com/Forums/en-US/8b77c775-21e0-4b43-b9f3-fb3777c43212/adding-libraries-and-use-them?forum=winappswithnativecode). In this Windows runtime component (with OxyPlot) is created in C# and used in C++ project. Here I am able to build the project but app crashes saying OxyPlot (added in C# project) not found.
Can someone please guide me. Regards
This may not 100% apply but it should. I was not trying to do this: "Use OxyPlot in Windows Universal app c++/xaml project". But I was tyring to use OxyPlot in a C++ .Net class so that it could do somethings fast, and eventually pass things back to a C# Class or WPF form. The idea I needed to know was could I create an OxyPlot.DataPoint array in C++ then put it into a C# Double array or an List in C# fast. And I can do that now fast! I hope this approach might help someone here doing this. I don't know how easy it is to use this technique to be able to use the opti chart in a C++ app or not. But if the GUI is done in C# this approach works.
I was getting the error: "You are trying to install this package into a project that targets 'native,Version=v0.0', but the package does not contain
any assembly references or content files that are compatible with that framework." when I tried to install OptiPlot.WPF or the NuGet.Commandline.
This may not be a complete solution for everyone's needs, but it worked for me. I found a "cheatin" way of getting OptiPlot.WPF into a sample C++.Net project. I had a C# main program project in my solution - I installed the package there:
Install-Package OxyPlot.Wpf -Version 2.0.0
Then I copied the packages.config file and the packages folder from there to my C++ .Net Class Library Project. Then I edited the packages.config file and took something out that didn't apply, and I probably took out a package in packages that wasn't needed. Then I added my references in the C++ .Net Class Library Project to packages/OxyPlot.Wpf.2.0.0 folder.
Now I could use the OxyPlot inside of C++! Cool!

How to add System.ServiceModel.Syndication.dll in Windows Phone 8 project?

I am trying to build an rss feed app. and i want to add System.Servicemodel.Syndication. But when i am trying to add, it is saying a reference to a higher version or incompatible assembly cannot be added to the project. After reading some post on how to solve it, i try to unblock the assembly but i found no unblock button. That means the project is already unblocked.
So how can i solve the issue?? Is there any alternative way to read rss?
Judging from the documentation here Adding a Reference to the Syndication DLL you need to install the Silverlight 4 SDK and then reference the v4 version of the dll located at Microsoft SDKs/Silverlight/v4.0/Libraries/Client/.
Windows Phone is based on Siverlight v4.
this assembly is designed for silverlight 5 so you cannot add to the project due to compatibility issues regarding .Net 3.5 +
See the article at
http://www.wintellect.com/blogs/jprosise/silverlight-for-windows-phone-programming-tip-2
on how to use LINQ to XML instead
(btw that article says the alternative is to use the respective dll from the Silverlight 3 SDK)
another way is to use a Web Service and parse the RSS on the server instead, see example at:
http://www.codeproject.com/Articles/83859/A-Simple-Silverlight-RSS-Reader

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.

Categories