Desktop C# - Referencing Windows.Devices - c#

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.

Related

Added reference not detected in visual studio

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

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

MvvmCross-SecureStorage in PCL

I'm trying to add MvvmCross-SecureStorage plugin of MvvmCross to PCL wich contains classes shared between Universal Widows app iOs apps and Android apps, but I'm getting this kind of error.
Could not install package 'Beezy.MvvmCross.Plugins.SecureStorage 1.0.0'. You are trying to install this package into a project that targets 'portable-net45+win+wpa81+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.
Anybody successfully added this plugin to PCL?
Looking at https://github.com/ChristianRuiz/MvvmCross-SecureStorage it looks like this project doesn't yet support the new unified xamarinios10 target which is included in your list.
One route forwards would be to add unified support to that open source project and to send them a Pull Request.

Xamarin.Forms could not install package

When creating a new solution within Xamarian studio I get this error
Could not install package 'Xamarin.Forms 1.0.6186'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5,Profile=Profile78', 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.
Is there a certain version of .Net that Xamarian Forms requires for it to be included in the solution? I've tried searching in their documentation but I'm only seeing marketing and not real in depth documentation.
I had a similar issue using Visual Studio and I've found that the following combination in the PCL works:
.NET Framework 4.5
Windows Phone Silverlight 8
Xamarin.Android
Xamarin.iOS
You have created the wrong project type, you created a normal Windows app, and I assume you are targeting iOS/Android or Mac.
Create the project with the correct type and it should work correctly.
If you are using Xamarin Studio for Windows (without also having Visual Studio installed) you need to download the Portable Library Tools. See the Xamarin doc Introduction to Portable Class Libraries.
I had the same problem with my Xamarin project. The problem was, that in the portable Xamarin project Windows Phone Silverlight was set as target. The PCL project from which I created the nuget, didn't reference Silverlight as target. I don't need Silverlight, so uninstalling all nuget packages from my portable Xamarin project, removing silverlight as target and reinstalling the NuGet packages solved it.
I had similar issue using VS and I found solution here - http://forums.xamarin.com/discussion/29674/xamarin-forms-dll-cannot-be-installed
"It looks like your NuGet Package Manager needs to be upgraded. The Xamarin PCL Profiles are installed but NuGet is not recognising Xamarin.iOS as a target framework. You can update NuGet by selecting Tools - Extensions and Updates, then select the Updates tab, then select Visual Studio Gallery. Then update NuGet from there."
I have invested a lot of time trying all the solutions posted here, but none of them helped me... Here is the solution that worked for me (on Windows 10):
1.) Open your .csproj file
2.) Find the TargetFrameworkProfile entry
3.) This entry contains Profile78 for me, therefore I open the folder below
c:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/.NETPortable/v4.5/Profile/Profile78/SupportedFrameworks
4.a) If the folder does not exist, then use one of the solutions posted here to install the PLC right on your PC
4.b) Unfortunately, ASP.NET and Xamarin don't like each other, therefore delete all ASP profiles from this folder. For me it was ASP.NET Core 5.0.xml. Obviously this will break your ASP.NET support in VS
5.) Restart Xamarin and have fun!
interesting reading about all that:
https://forums.xamarin.com/discussion/52846/cannot-create-new-xamarin-forms-project-pcl-in-xamarin-studio-win10-vs2015

Installing Twilio C# api with VS2008

I have successfully installed and tested twilio api with C# .Net framework 4.0 using VS2010. I referred to the link https://www.twilio.com/docs/csharp/install which has instructions to install with VS2010/12
Now I have another computer where I have to install twilio C# api with .net framework 3.5 and VS2008. How can I do that ?
I tried to copy the dlls and take reference but it didn't work.
Kindly let me know how can I install twilio api for C# with .net framework 3.5 and VS2008 ?
Twilio evangelist here.
You will likely need to manually download the NuGet package since there is no built in way in VS2008 to do it. There are a bunch of ways to do this:
NuGet Package Explorer
NuTake Chrome extension
NuGet support for Visual Studio 2008
Once you get the nupack file change its file extension to .zip, extract the contents and locate the folder that contains the .NET 3.5 version of the assemblies. Then add to your project.
Or you can always pull the source from Github.
Hope that helps.
Had to add SMS support to a legacy VS2008 app, and here's an easy way to do it.
Use VS2010 or later, create some dummy project, and then use Nuget Package to download Twilio. It will create a 'packages' folder inside your solution directory.
Use VS2008 to open your actual project.
Right click on references, select 'Browse' tab, and browse to the packages folder inside your dummy project you obtained in step one.
You need to add two references (one for Twilio, and one for RestSharp, which Twilio depends on). They are located in these two folders:
...\packages\Twilio.4.4.1\lib\3.5\Twilio.Api.dll
...\packages\RestSharp.105.2.2\lib\net35\RestSharp.dll
The versions I specify above are targetting .NET 3.5

Categories

Resources