HttpClient missing from .Net portable subset while creating PCL in Xamarin - c#

I have created a Portable class library in Xamarin and want to use it for an android app. I want to use the HttpClient within this PCL. I have added the Microsoft Http Client libraries from the NuGet Package manager. I can now see the .Net portable subset added to my references. But somehow I still cannot use the HttpClient and it does not show in the .Net portable subset as well.
Also, my Current profile of the PCL is 4.0-Profile 158. If I change the profile to 4.5, Xamarin crashes and does not open the solution
Can anyone help me with this?
Thanks

The simple solution is to target .NET 4.5, Windows Store apps (Windows 8.1), Xamarin.iOS, and Xamarin.Android (4.5-Profile7). Then you won't need the HttpClient NuGet package to get those APIs.
If Xamarin is crashing when you try to select a 4.5 profile, please make sure you're using the latest version and then report the bug with details about how to repro it and what happens.
Also the HttpClient NuGet package should allow you to use HttpClient from PCL profile 158. Make sure you're using the latest version of NuGet. ".NET Portable Subset" should always appear in your references for a PCL, that's not related to the NuGet package. When you install the HttpClient NuGet package, you should also see references to System.Net.Http and other assemblies in your references.

Related

How to install Microsoft.Azure.Devices NuGet package for Unity?

I was working with Unity and Hololens and tried to establish connection to Azure Iot Hub via MQTT protocol. Microsoft provides a tutorial for getting started with Azure IoT Hub in C#, but unfortunately, I encountered a problem with the tutorial:
In the picture above, I have selected Microsoft.Azure.Device NuGet package for installation. I have tried version 1.0.0 and also the latest one available, 1.2.4. The projects were automatically generated by Unity and that is probably the reason, why I do encounter this problem. Which problem? After I try to install the selected NuGet, I encounter the following error:
Could not install package 'Microsoft.Azure.Devices 1.2.4'. You are
trying to install this package into a project that targets
'.NETFramework,Version=v3.5,Profile=Unity Full v3.5', but the package
does not contain any assembly references or content files that are
compatible with that framework. For more information, contact the
package author.
I was like, "Hmm, I must have wrong .NET framework version. I wonder if I can change that..." I tried to go to project properties like this
Microsoft advises changing .NET framework from Properties context menu item:
https://technet.microsoft.com/fi-fi/library/bb772098(v=vs.90).aspx (4.24.2017)
https://msdn.microsoft.com/en-us/library/bb398202(v=vs.100).aspx (4.24.2017)
However, this feature must be blocked by something, because the view that is supposed to open flashes white and disappears immediately. I suppose Unity doesn't like people tinkering with project properties, but what else can I do? Incompatible .NET framework issue needs to be resolved, so that the NuGet package can be installed, but how do I do that?
In short, how to install Microsoft.Azure.Devices NuGet package for Unity?
Sorry, this isn't possible due Unity's restriction to .net 3.5.
To be exactly, they use a custom version of mono-2.
You could try the new (experimental) .net 4.6 settings in Unity 5.6.
https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-on-5-5-0b4.433541/

RabbitMQ in Xamarin

I'd would like to use RabbitMQ .I find nugget .NET but i get error :
You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
How Can I implement connection with RabbitMQ . Manual copy source ?
The issue is that the RabbitMQ nuget package needs the full .NET Framework. Since PCLs and Xamarin Android projects don't provide the full framework, it won't work. One option is to take the source code and build it in a PCL like you suggested (eg see https://forums.xamarin.com/discussion/49858/using-rabbitmq-amqp-with-xamarin-forms). Depending on what you want to do, I think using the HTTP API might be worth considering too.
Rabbit MQ is now also built as a .net standard 1.5 libraries. https://www.nuget.org/packages/RabbitMQ.Client
You should be able to pull it into the latest Xamarin without any problems (taking into account that your xamarin build is set up to support version .net standard 1.5 or version 2.0).
Xamarin forms added support for standard libraries from version 2.3.5-pre
https://devblogs.microsoft.com/xamarin/building-xamarin-forms-apps-net-standard/
UWP is easily supported with .net standard 2.0 and is compatible with the 1.5 libraries.

Error when installing NetMQ via nuget to xamarin projects

I tried to install NetMQ to my xamarin application.
Because NetMQ depends on AsyncIO, this package could not be installed and show me the following error:
Could not install package 'AsyncIO 0.1.18'. You are trying to install this
package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111',
but the package does not contain any assembly references or content files
that are compatible with that framework. For more information, contact the package author.
How can I reesolve this issue?
The AsyncIO 0.1.18 NuGet package and the NetMQ 3.3.3.1 NuGet package only contain assemblies for .NET 4.0 and .NET 3.5 so you cannot install it into a portable class library project nor a Xamarin project.
Your options include:
Port those libraries to the Xamarin frameworks.
Only use these libraries on the server side. Your Xamarin project then connects to your server using a supported way, such sending json messages over http.
Find another library that does support the Xamarin frameworks.
NetMQ now target Xamarin IOS and Android, you can download here:
https://www.nuget.org/packages/NetMQ/4.0.0.3-rc3

Azure Mobile Services in a PCL project that includes WP8

Is it possible to inlcude AzureMobileServices client in a PCL that includes WP8?
I used to have a PCL project that had it up until I upgraded it to VisualStudio 2013.
The required PCL is profile78: .NET4.5, Windows Store apps (Win8), WP8, and the Xamarin twins.
I tried following this recommendation from Xamarin to reference the component's DLL directly, however the DLL was compiled for profile7 (that does not include WP8).
Yes. Make sure you are using at least version 1.1.5 of the Mobile Services NuGet package or Xamarin Component and you will be able to successfully use it from a PCL that includes WP8. For a tutorial on how to do this, see here.
It looks like their nuget package only includes directories for Store, .Net 4.5, Wp8, and Portable-Store+.Net 4.5. However if I ildasm the dll in the portable folder I see it was built for Profile78, which does support phone.
This looks like a bug with the WindowsAzure.MobileServices.nupkg nuspec authoring.

Why can't I use await keyword in my Windows Phone 7.1 MvvmCross project while using the Microsoft.Bcl - cannot await 'System.Threading.Tasks.Task?

I am unable to use the await keyword in my MvvmCross Windows Phone 7.1 project while using the Microsoft.Bcl "Microsoft BCL Portability Pack".
I have posted the code for the sample project that I describe below on GitHub and the await error occurs on this line.
When I try to build the third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get the errors of:
Type System.Threading.Tasks.Task<string> not awaitable under VS red squiggles, and
Cannot await 'System.Threading.Tasks.Task<string>' when building.
There are four projects in the solution:
A Windows Portable Class Library (PCL) with an interface in it that
references that "Task" object provided by the BCL.
A Windows Phone Class Library targeting OS 7.1 that implements the
interface above and also uses "Task" from the BCL.
Another Windows Portable Class Library (PCL) that provides the
"Core" functionality of the app, including the ViewModel.
The Windows Phone 7.1/"7.5" application that tries to reference and
consume the DLL's above.
The first two projects containing the interface and the implementation of the interface compile without any errors. But the 3rd "Core" PCL fails to build with the errors shown above.
More Details If You Want Them:
I tried this App.config "fix" as described here in the "known BCL issues":
http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx .But that did not resolve the error when I added App.config to just the "Core" project, nor when I tried to add the same App.config to every project. It is possible that I am not using the right version in the element or I just did the App.config stuff incorrectly.
Every project in the solution that is set to target a PCL are set to "Profile104" in Visual Studio.
Those DLL's are located in:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\
This PCL profile is shown as targeting these platforms in the Visual Studio project properties:
.NET for Windows Store apps, .NET 4.5, Silverlight 4+, and Windows 7.5+
Every project in the solution also has reference to the Microsoft.Bcl "Microsoft BCL Portability Pack" via NuGet.
All four projects are using MvvmCross (Mvx).
None of the projects in this sample are trying to target anything related to the Xamarin Droid/iOS stack yet. It is all Windows and is still failing on the await keyword.
The PCL with the interface in it and the Windows Phone Class Library both use the Mvx CrossCore NuGet Package and are setup to be consumed as "Mvx Plugins".
The "Core" PCL is using the full MvvmCross NuGet package and contains the FirstViewModel where the await error is occurring.
The Windows Phone App project references the full MvvmCross as well, with the Windows Phone-specific Mvx files pulled in to it.
as mentioned, see the failing sample code on GitHub.
You need to add the Microsoft.Bcl.Async NuGet package.
These packages were previously unavailable on non-Microsoft platforms, but as part of the Xamarin collaboration Microsoft relicensed them to be usable under all platforms.

Categories