How to include Windows.Security.Credentials.UI namespace into C# project - c#

My goal is to work with Windows.Security.Credentials.UI namespace to create a program that authenticates users through their Windows pin, similar to Opera Password Manager:
The only problem is that I cannot figure out how to include the namespace into my program.
I've tried including it as so:
using Windows.Security.Credentials.UI;
However, that returned an error:
The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
I have also tried to include the namespace as a reference but I cannot locate it inside the References menu.
What is the correct method to install the Windows.Security.Credentials.UI namespace in C# .NET 4.7.2 Console Application?

When using the .NET Framework, you must include the Microsoft.Windows.SDK.Contracts nuget package and then you will have access to (some) WinRT APIs.
Here is a sample C# Console Application:
class Program
{
static async Task Main()
{
await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync("hello world").AsTask();
}
}
It works because this API is marked as DualApiPartition.
Also make sure you're using PackagesReference format for nuget packages and not the packages.config configuration.

Related

SHDocVw for .NET Core projects

I need to move my projects from .Net Framework 4.7.2 to .Net Core platform, and I have difficulties to resolve the problem with code in part of using SHDocVw library.
I have such string of code:
using SHDocVw;
...
var list = new ShellWindows().Cast<InternetExplorer>().ToList();
and compiler fails on "ShellWindows()" and "InternetExplorer" with next message:
The type or namespace name 'ShellWindows' could not be found (are you missing a using directive or an assembly reference?)
What Nuget package is required to resolve this problem, either what class and methods can be used instead of current?

Adding CsWinRT nuget breaks using Windows.System namespace

I've created a .NET 5.0 project, one of the dependencies I have is on this API:
AnalyticsInfo.VersionInfo.DeviceFamily
After installing Microsoft.Windows.SDK.Contracts, I'm able to use this API. Then, I needed to install the Microsoft.Windows.CsWinRT package to resolve this error:
Error NETSDK1130 Referencing a Windows Metadata component directly when targeting
.NETCoreApp,Version=v5.0 is not supported.
Use the C#/WinRT projection tool (https://aka.ms/cswinrt) or a provided projection for this target.
After installing this, I no longer have access to the Windows.System.Profile namespace to call the AnalyticsInfo API:
Error CS0234 The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
With .NET 5, built-in support for WinRT APIs in .NET is removed (because it's Windows specific) , so we can't use Microsoft.Windows.SDK.Contracts any more.
The solution as explained here Built-in support for WinRT is removed from .NET is to
Remove references to the Microsoft.Windows.SDK.Contracts package.
Instead, specify the version of the Windows APIs that you want to
access via the TargetFramework property of the project. For example:
<TargetFramework>net5.0-windows10.0.19041</TargetFramework>
Note with that in place, there's no need to manually add a reference to C#/WinRT (Microsoft.Windows.CsWinRT) it should be done automatically and shown as "Microsoft.Windows.SDK.NET.Ref" in the list of Frameworks Dependencies.

Can't add popular namespaces references to C# .DLL Class Library

My question in simple few lines:
I'm trying to build a compiled .dll C# Class Library that contains functions I want to easily call from other non-C# applications.
My functions depend on popular namespaces' Assemblies references like System.Windows.Forms and Microsoft.Office.Interop.OneNote.
When I try to add any of them to my class library, I get does not exist in the namespace error.
Also, they don't exist in Reference Manager (Screenshot 2).
Continued description:
Within normal C# application (that's compiled to .exe), I can easily include those Assemblies references using code lines like below:
using System.Windows.Forms; // works good in normal application
using Microsoft.Office.Interop.OneNote;
Also I am able to add References with References Manager (by right clicking the References node on Solution Explorer → then Select Add Reference → then search for the references I want to add) — in Visual Studio 2019 (Screenshot 1). I can find and add assemblies like System.Windows.Forms and Microsoft.Office.Interop.OneNote easily.
But within a C# Class Library (that's compiled to .dll), when I try to include System.Windows.Forms and Microsoft.Office.Interop.OneNote using the below lines:
using System.Windows.Forms; // gives errors in C# Class Library
using Microsoft.Office.Interop.OneNote;
I get errors:
CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) MyLibrary C:\Path\to\MyLibrary\Class1.cs
CS0234The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) OneNoteLibrary C:\Path\to\MyLibrary\Class1.cs 15 Active
Also, these assemblies aren't shown at all when I try to add using References Manager (Screenshot 2).
Screenshot 1:
Screenshot 2:
Screenshot 3:

Can't find namespace in Global

I have the job of getting a legacy project working again. This project was done many years ago using Silverlight and C# Class Library's.
The error I am getting is to do with a namespace inside the project file called Silverlight.Business:
Code
using Tcx = global::MapTools.Xml;
Error:
The type or namespace name "MapTools" could not be found in the global namespace (are you missing an assembly reference?)
MapTools is a C# Class Library and Silverlight.Business is a Silverlight Library. Due to this I can't add a reference to MapTools inside the Silverlight project file.
The silverlight project does have a WCF RIA Service's Link but that does not connect to anything.
I am now wondering how the person that wrote the code has managed to call that namespace? I have tried researching how to add the MapTools.dll to the Global namespace but have not found anything.
Anyone have any ideas?
To do that there should be an some tool been used .
We had used in our projects a Portable library which allowed us to communicate through cross type of projects , below is the link :
https://msdn.microsoft.com/library/gg597391(v=vs.100).aspx

The type or namespace name 'Http' does not exist?

I have this portable class library, its settings it Windows Phone 8, Windows Store and .NET 4.5.
I'm trying to add the HttpClient, but after I add it by NuGet its runtime version is v4.0.30319, and when i try to using System.Net.Http it states:
The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
The following is added as a reference, and was added by NuGet upon install:
System.Net.Http
System.Net.Http.Extensions
System.Net.Http.Primitives
The class I'm trying to use is HttpClient in my portable class library :-/
This MSDN blog post makes it clear that you need to use this special release of HttpClient.
To use the HttpClient package, right click on your solution, go to the
Manage Nuget Packages dialog, search for Id Microsoft.Net.Http, and
make sure “Include Prerelease” is turned on.
This was released last February, but I haven't seen any updates to indicate that it is now obsolete.
EDIT
Here's the page for the latest version of this package

Categories

Resources