Rode
Rode

Reputation: 51

Reference to the right "System" in c# project

I am new to c# and visual studio and have run into some trouble.

I have created a project with references to "Windows" and ".Net" in visual studio because I want to test a little with smart cards. The code:

using System;
using Windows.Devices.Enumeration;
using Windows.Devices.SmartCards;

class HandleSmartCard 
{
    public async void checkNumberOfSmartCards()
    {
        string selector = SmartCardReader.GetDeviceSelector();
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
        //  return "2";
    }
}

So far it looks fine. However I also want the project to be able to use System.Windows.Forms; which I have used in a previos test. I add reference to System.Windows.Forms; and try to create a form. However in that form when I try this:

Form prompt = new Form();
System.Windows.Forms.Button confirmation = new System.Windows.Forms.Button() { Dock = DockStyle.Bottom };
confirmation.Click += (sender, e) => { prompt.Close(); };

I get a red line under "Close" with the message:

Reference to type component claims it is defined in system but could not be found.

System is referenced at top of file, but I am guessing it is the wrong type of system right? Can I somehow use "both Systems" in one project so to speak? I hope someone understands what I mean and can help me understand this.

Upvotes: 0

Views: 336

Answers (1)

user1228
user1228

Reputation:

You're most likely working on a UWP app. The API for UWP apps is a very small subset of the full .NET framework. You can find more information here

https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx

You're attempting to reference System.Windows.Forms which is not allowed in UWP applications.

Looks like you're trying to create a popup to ask the user something. For this, use the MessageDialog class.

https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx

Upvotes: 1

Related Questions