Trying to use Windows.Devices.SmartCards in a WinUI c# applicaiton throws ComException

Zahur, Abdullah 20 Reputation points
2024-02-09T23:10:06.07+00:00

I am using the following code to create a virtual smartcard and keep getting a ComException. Is await SmartCardProvisioning.RequestVirtualSmartCardCreationAsync() supported in WinUI. This code works fine in UWP application. Is Windows.Devices.SmartCards namespace available in WinUI ? SmartCardPinPolicy pinPolicy = new SmartCardPinPolicy(); pinPolicy.MinLength = 6; IBuffer adminkey = CryptographicBuffer.GenerateRandom(24); SmartCardProvisioning provisioning = await SmartCardProvisioning.RequestVirtualSmartCardCreationAsync( "Card friendly name", adminkey, pinPolicy); throws a ComException (runtime) error

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
745 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,138 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,562 questions
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 16,391 Reputation points Microsoft Vendor
    2024-02-12T11:59:59.77+00:00

    Hi @Zahur, Abdullah ,

    Welcome to Microsoft Q&A!

    I can reproduce the same behavior, but I didn't find out whether this API is still supported in WinUI3. I only found this document Windows Runtime APIs not supported in desktop apps.

    It says that Windows.Devices.SmartCards requires package identity, it doesn't say WinUI3 doesn't support Windows.Devices.SmartCards.SmartCard.

    If you need a solution now, It is recommended that you use win32 api to create virtual smartcard in WinUI3 project.

    Virtual smart cards can also be created and deleted by using APIs. For more information, see the following classes and interfaces:

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful