Xamarin portable class library issue - c#

Hi I have the following issue, I am using xamarin on a Mac and created a cross-platform app solution using native single view app with portable class library.
In the portable class library i added one reference to newtonsoft.json v4.0.3 but when i rebuild my project i get errors like the following:
Reference to type 'System.ComponentModel.ITypedList' claims it is defined assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found.
What should i do?
Thank you very much in advance

Version 4.0.3 of Newtonsoft.Json is only available for .NET (2.0, 3.5, 4.0), Windows Phone 7 (I think) and Silverlight 4. This version does not support portable class libraries.
Use NuGet to download the latest Newtonsoft.Json version, it should provide a number of PCL alternatives, in particular a Profile 328 assembly that can target practically all modern platforms including Xamarin iOS and Android.

Related

Is it possible to add a System.windows.form reference to a Xamarin project?

I am developing a Xamarin.Forms app in Visual Studio and I need to use an external SDK that is dedicated for Windows Form apps. I have been trying to add a reference to System.Windoes.Form but it doesn't appear in the assemblies.
I know it wouldn't make sense using windows forms in a Xamarin project, but I am creating the user interface with Xamarin graphics, I just need to add the reference to Windows.Forms to get rid of the following error:
Can not resolve reference: System.Windows.Forms, referenced by MY DLL. Please add a NuGet package or assembly reference for System.Windows.Forms, or remove the reference to MYDLL.
Is there a way to do so?
Thanks
.NET can be categorized into three and those are, .NET Core, .NET Framework and Xamarin.
The .NET Framework supports Windows and Web applications.
.NET Core is the new open-source and cross-platform framework to build applications for all operating system including Windows, Mac, and Linux.
When you want to build mobile (iOS, Android, and Windows Mobile) apps using C#, Xamarin is your only choice.
You cannot use System.Windows.Forms inside a Xamarin Project and it is incompatible.

Using assembly redirection in UWP C#

Hi!
I'm getting a typeload exception, the assembly being loaded is targeting runtime version v2.0.50727, other assemblies targets v4.0.30319.
I've been reading about Assembly Redirection and I think it could solve this problem but I'm unsure how this would be applied in a UWP app as there is no app.config.
Any advice would be helpful!
System.TypeLoadException: 'Could not load type 'System.Net.Sockets.Socket' from assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.'
In UWP platform, it would be better to create a Universal Windows Class Library then add it as a reference into the UWP project. You can try to create a Universal Windows Class Library and add your code into it as the following image,
From Windows 10 Fall Creators Update(16299), UWP supports .Net Standard 2.0, you can also create a .NET Standard 2.0 Class Library in VS2017.
Last but not least, I think you should learn more about the relationship among .Net Framework, .Net standard and UWP, you can look into the following blogs to get a better understanding:
https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
https://msdn.microsoft.com/en-us/magazine/mt814993.aspx

Portable class library for referred nuget packages dll not generated

I created a .net standard 1.3 PCL and referred newtonsoft.json package in that library using visual studio 2015.
After that i tried referring this dll to a console application of .net framework 4.5.2 , in the console application on execution, i get an error as
Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
I see that in PCL on building project i am not getting the dlls of dependent package , why does that problem exist?
How to fix this?
Note -
build location for console application and PCL library is same.
best way i found on exploration is to create nuget package using dotnet pack and refer it in project

Xamarin.Forms assembly references

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.

Using Async CTP with Portable Class Library

I am trying to rewrite a project into a Portable Class Library. But the problem is that it is using Async CTP, and I can't compile it as a library for WP and Windows Store App. If I don't include reference AsyncCtpLibrary.dll, compiler says that
The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
If i include it, compiler still says the same errors and adds a warning:
The primary reference "AsyncCtpLibrary" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "AsyncCtpLibrary" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
How should I bear with that?
You can only currently use async/await in portable when targeting .NET 4.5 and Window Store apps. Outside of portable, you can use the Async Targeting Pack for .NET 4.0 and Silverlight 5.
In saying that though, we are working on an updated async targeting pack that adds support for async/await in portable when targeting Phone 7.5, Silverlight 5 and .NET 4.0, see: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2691068-support-async-in-portable-class-libraries. You will see this early October.
Update: We just release a beta of this: http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx.
Simple answer - AsyncCTP is not working in Visual Studio 2012 and cannot be used in any project. For .NET 4.0 and Silverlight 5 you can install Async Targeting Pack from NuGet that works in a similar fashion.
Async/await is in Portable Class Library supported only when targeting WinRT, .NET4.5 or Windows Phone 8 and even then the use is pretty limited. I can't go into more details here, because the Windows Phone 8 SDK is still under NDA.
For WP7.5 and VS2012 there is currently no way how to use async/await, but updated Async Targeting Pack for this platform should be available sometime.
Note also that AsyncCTP and Async Targeting Pack can't be used in Portable Class Libraries and it's unlikely it will change in the future. The result is in VS2010 you cannot use async/await in Portable Class Libraries.
You can try to use the AsyncBridge project instead of the AsyncCTP. I don't know if it will help. You'll have to compile in VS2012 to get this to work though (you can still target .NET4.0):
http://omermor.github.com/AsyncBridge/
http://www.simple-talk.com/blogs/2012/04/08/asyncbridge-async-on-net-4-0-using-vs11/

Categories

Resources