Added reference not detected in visual studio - c#

When trying to install the netmq vis nuget, I get 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.
The problem is that netmq depends on AsyncIO. when installing it, nuget find that the assembly is not compatible with .Net 4.5.
so nuget fail in installing AsyncIO, and then failed in installing netmq.
So I downloaded the AsyncIO Source from Github and build it locally with .Net 4.5.
After that and added the dll of AsyncIO built locally as a reference for my project.
Theoretically, NetMQ should be successfully installed with nuget. because I added the needed reference to AsyncIO.
But when trying to reinstall NetMQ, I get the same 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.
and nuget did not detect that I added 'AsyncIO 0.1.18' in my project.
How to let nuget detect that I added this reference in my project?

Have a look here:
.NET Portable profiles
Profile111 is a combination of:
.NET Framework 4.5
Windows 8.0
Windows Phone 8.1
or in other words:
portable-net45+netcore45+wpa81
So your project into which you are trying to append the NuGet targets Windows Phone 8.1 and other 2 platforms, I mention this one as the most restrictive.
Now let's have a look at the named NuGet package's source:
<ProjectGuid>{3830B7A3-0225-4FDA-B155-E085E183650C}</ProjectGuid>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
What do we have here? We can see that the project is not a PCL. It is targeting full .NET 4.0 framework which is not available on Windows Phone 8.1. And your library does target Windows Phone 8.1. See the problem?
You say that if you compile the AsyncIO targeting .NET 4.5 than you can successfully append it into your project as a reference? That's not altogether true. I mean you can append a reference to it but you cannot use it. You will see that when you try to call something from that reference.
In order to use AsyncIO from you PCL will have to build AsyncIO as a PCL targeting the same or more restrictive set of platforms. Try creating a PCL project targeting Profile111 and try compiling the AsyncIO code with it (just link the original AsyncIO source files (*.cs) into this new AsyncIO_PCL project). If you are lucky enough and the code of AsyncIO is really compatible you will be able to use that library.
Here are your steps:
Create a new project (named AsyncIO_PCL) of type PCL class library.
Pick the Profile111 platform set i.e.
.NET Framework 4.5
Windows 8.0
Windows Phone 8.1
Link all the .cs files from the original AsyncIO project save one (AssemblyInfo.cs) into the new AsyncIO_PCL project.
Set the output assembly name to the same as in original AsyncIO project.
Try building the project.
Your ability to build the AsyncIO as a PCL with the required set of supported platforms depends on AsyncIO code i.e. which API is used inside and if that API is supported by all the three platforms you are targeting.

Try clicking right-button on the project -> Properties. In the "Application" menu check the "Target Framework". It should be set to .NET Framework 4.5

Related

Which PCL profile should I use in my Xamarin.Forms app?

I'm new in Xamarin, Xamarin.Forms and C# platform.
I'm starting the development of an app that should support Android and iOS devices. I'm using a PCL project for code sharing. Currently this project is using the profile111 because Visual Studio has selected it by default for me. But when I try to install some NuGet packages I'm getting a message saying the package is not compatible. Something like:
Could not install package 'DocsBrStandard 2.0.1'. 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.
I believe this message is related with the profile I'm using, right?
So which profile should I use for my app that should support only iOS and Android devices? Is profile111 the more appropriate for this scenario?
At least, how can I identify if a package is compatible or not with my Xamarin.Forms app?
Thanks.
You need to target .NET Standard to be able to use the DocsBrStandard package. So you can't work with profile based PCL if you want to use that package.
Check out this article about targeting .NET Standard with Xamarin.Forms:
https://blog.xamarin.com/building-xamarin-forms-apps-net-standard/

Creating Xamarin.Forms .Net Standard app with Azure IOT Library?

I'm making an iOS/Android app that will work with Azure IoT Hub. The latest Microsoft.Azure.Devices version from what I understand is only compatible with .Net Standard projects. I've been trying to follow these twho tutorials (1, 2) to convert PCL project to .Net Standard project to no avail, and I'm lost on what I'm doing wrong.
These are the steps that I'm taking.
Create new Cross Platform App called TestProject. Xamarin.Forms -> Blank App -> Portable Class Library (PCL)
Right click solution -> Add New Project -> .Net Standard -> Create .Net Standard Library called TestProject.Core
Delete the auto generated class Class1.cs and move App.xaml and MainPage.xaml to TestProject.Core.
Delete Portable Library TestProject.
Rename TestProject.Core to TestProject.
Add TestProject reference to iOS and Android.
Click on TestProject and select Edit TestProject.csproj. Change PropertyGroup to following:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8
</PropertyGroup>
Right click on solution and select Manage Nuget Packages For Solution.
Check Include Prerelease and install 2.3.5.256-pre6 Xamarin.Forms on TestProject, TestProject.Droid and TestProject.iOS.
Clean and Rebuild solution.
Right click on TestProject and select Manage Nuget Packages. Install Microsft.Azure.Devices
Clean and Rebuild.
Add code to TestProject that uses Microsoft.Azure.Devices.
Rebuild and get error:
Project File Line Suppression State Error Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'Microsoft.Azure.Devices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Perhaps it doesn't exist in the Mono for Android profile? File name: 'Microsoft.Azure.Devices.dll'
From what I can understand I am missing Microsoft.Azure.Devices Nuget package on
TestProject.Droid, however, when I attempt to install it, I get the following error:
Could not install package 'System.Threading.Overlapped 4.3.0'.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or
content files that are compatible with that framework.
When I try to install *Microsoft.Azure.Devices** on iOS:
Could not install package 'System.Threading.Overlapped 4.3.0'. You are trying to install
this package into a project that targets 'Xamarin.iOS,Version=v1.0', but the package does not
contain any assembly references or content files that are compatible with that framework.
I'm making an iOS/Android app that will work with Azure IoT Hub. The latest Microsoft.Azure.Devices version from what I understand is only compatible with .Net Standard projects.
Per my understanding, you could leverage the Azure IoT Hub client SDK portable library Microsoft.Azure.Devices.Client.PCL which supports Android, iOS, Windows 10 (UWP) and Windows Phone (WinRT). Also, here is a sample uses Microsoft.Azure.Devices.Client.PCL, you could follow here.

Installing Win2D.win81 as NuGet package. Target Framework not compatible

So I am currently trying to install Win2D.win81 as a NuGet package via VS2015s package manager. My goal is to rewrite a simple graphing library I made to now work with a WPF control instead of winforms and benefit from the performance of Win2D vs GDI+.
To do that I made a new ClassLibrary project and added a userControl (WPF). Now I am trying to add Win2D via the package manger to the project but it keeps rejecting telling me the package doesn't target my target framework. Which wasn't that big of a deal if I haven't tried setting my project to target .Net 3.5 to 4.6.2 and any version in between and it always kept rejecting to install.
Excat error from PM:
Could not install package 'Win2D.win81 1.20.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework.
Win2D.win81 targets Windows 8.1 Store and Windows Phone 8.1 apps, which is a separate .net framework from the full .net 4.6 framework that you are trying to use.

Desktop C# - Referencing Windows.Devices

I am trying to create a classic desktop application for Windows 10 in C# that will be able to talk to BLE devices.
I followed the instructions (Bluetooth 4.0 (low energy) API for windows desktop C# application) and added the tag to the project file
<TargetPlatformVersion>10.0.10156</TargetPlatformVersion>
and reloaded the project. I am given access to the Windows namespace only: references dialog
I don't know what I did in one of my testings, but once that list got populated with a whole lot of other namespaces, giving me the ability to check Windows.Devices namespace, which is essential for my project.
I can now add the Windows.Devices via Recent option, but can not add any other namespace...
Do you guys have any idea what should I do to access the list of all Windows.x.y namespaces?
To access Windows.Devices and other WinRT API's from .NET Framework code,
Add the NuGet package Microsoft.Windows.SDK.Contracts to the project
Configure the project to support Package References (right-click packages.config, select Migrate packages.config to PackageReference...)
From the OP's author comment:
Update - I created a new project and adding C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd and C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll allowed me to include Windows.Devices namespace without selecting Windows.Device in the References dialog.
This worked for various of us.
There is now a Windows.SDK.Contracts NuGet package which helps with this issue. I wasn't able to add the above DLLs, but the nuget package worked.
The Windows 10 WinRT API Pack enables you to add the latest Windows
Runtime APIs support to your .NET Framework 4.5+ and .NET Core 3.0+
libraries and apps.
This package includes all the supported Windows Runtime APIs up to Windows 10 version 1903.

Cannot add the Signalr Client library as a portable library to a Xamarin project

I have tried adding the Signalr Client library and the WebApi client package to my Xamarin Solution (on Visual Studio with Xamarin Support and also on Xamarin Studio) but I always get this error although I am able to install other PCLs (for example Microsoft.Net.Http):
Could not install package 'Microsoft.AspNet.WebApi.Client 5.2.3'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10', 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.
and the following error when adding Signalr:
Adding Microsoft.AspNet.SignalR.Client...
Adding 'Microsoft.AspNet.SignalR.Client 2.2.0' to Corda.Client.
Could not install package 'Microsoft.AspNet.SignalR.Client 2.2.0'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10', 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 have also tried changing the the target framework with not success.
This is the build setting for my project:
and this is my C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile259\SupportedFrameworks folder:
I get the same errors on both Mac OSX and Windows 10. Any ideas?
Using Profile78 solved my problem. Full explaination here.
A simple workaround that worked with my Xamarin with VS:
Download the dll-files manually here: https://components.xamarin.com/gettingstarted/signalr/true
Import the following into your solution.
Microsoft.AspNet.SignalR.Client.dll
Newtonsoft.Json.dll
System.Net.Http.Extensions.dll
System.Net.Http.Primitives.dll
Done!
The problem is not with the dll-files, but with the (nuget) installer.
The problem is with the nuget package manager,specifically with the Windows Phone 8.1 project. I think it expects it to be a windows phone silverlight 8.1 project. There is a bug on installing signalr client on an universal 8.1 phone project in a xamarin project. It should be sorted out in the next xamarin release. Unselecting windows phone 8.1 in the portable config solves the issue,meaning you will have to take the windows phone 8.1 project out of the xamarin project and your need to create a universal windows 10 project.
Yes, As suggested by others this is the problem from nuget package manager, As per this link it should be fixed with the realease of Microsoft.signalr.client 2.2.1 version but for now if you still want to go with nuget, Add the below nuget source
https://www.myget.org/F/aspnetwebstacknightly/
to visual studio and install pre release version 2.2.1 pre-160523-b816 of the signalr client dll as suggested in below link
https://github.com/SignalR/SignalR/issues/3393

Categories

Resources