Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Microsoft Visual Studio 2022 problem: I made a simple program that converts text to an URI and after it gets generated, the program will ask the user if they want to copy the URI to use it somewhere else. I need to use the System.Windows.Forms one because the System one doesn't work. So I created a separate library in .NET Framework 4.7.2 and I referenced "System.Windows.Forms".

What I have tried:

But now let's get into the problem: System.Windows.Forms also has the "Clipboard" class, I type the name, no problem: Visual Studio recognizes the class but when I put the first dot, it's where the problem begins: Visual Studio says the class "Clipboard" doesn't exist in the current context and it's still recognized: summary but there is nothing inside the object. I tried restarting Visual Studio and my computer but it didn't help. I also tried to reload everything but it didn't fix.
Any ideas? It is all I found.
Thank you for your attention and your help!
Posted
Updated 5-Jun-23 6:04am
v2
Comments
Dave Kreskowiak 5-Jun-23 0:30am    
Show the code and the list of References you have set in your project.

I had something similar recently with VS2017. I can't remember what I did to fix it but most likely I would have done a super clean on the project. I do recall that there was nothing wrong with the source code.

Super Clean
1) Delete obj subdirectory tree
2) Delete bin subdirectory tree
3) Delete .vs subdirectory tree
4) pray

[Edit] I forgot this one
3b) Delete any .csproj.user files
 
Share this answer
 
v2
Comments
Le lance Flamer 5-Jun-23 11:55am    
It didn't fix. What makes it even weirder is that the System.Clipboard doesn't exist but the System.Windows.Forms one exists, with other classes from System.Windows.Forms it does work but not for the Clipboard one.
Le lance Flamer 5-Jun-23 11:56am    
Or it is maybe because I use implicit usings so it messes it up but the System Clipboard doesn't exist so I don't know why it could be the System.Clipboard class that could break the Visual Studio editor and throw an error like this one.
Put the text cursor in the word "Clipboard" and hover the mouse over it - a symbol will appear at the beginning of the line. Click it with the mouse and it'll make suggestions as to what you need to do, which is almost certainly to add a using statement to include the containing class.

Almost certainly System.Windows is currently missing.
 
Share this answer
 
Comments
Le lance Flamer 4-Jun-23 16:47pm    
This is what I tried but it didn't change anything. It does show the namespace but it says the class does not exist.
OriginalGriff 5-Jun-23 2:35am    
Without being able to see your screen or access your system, this is really difficult and will probably take some time - what framework did you select?
Le lance Flamer 5-Jun-23 11:50am    
I selected .NET Framework 4.7.2. This always what I used and I never had a problem
OriginalGriff 5-Jun-23 12:07pm    
Hmmm ... I use the same: VS2022, 4.72

Can you post a solution ZIP to dropbox or something? I'll try it here and that should tell us something if you can.
Literally, "it is working here" ...
        private void MyButton_Click(object sender, EventArgs e)
            {
            string s = Clipboard.GetText(); 
            }>
Le lance Flamer 5-Jun-23 12:10pm    
I fixed this by deleting the file then creating a new one and put my code in. Why did Visual Studio did this? I don't know why. Thanks for your help :)
Well, I fixed it myself. The file of the class was the problem: Now I can access all everything as they should. But I still don't understand why it didn't want to work at the first place.
Here's the solution:
Delete the file then recreate it. It was only this.
 
Share this answer
 
Comments
Richard MacCutchan 5-Jun-23 12:32pm    
All you have done is hidden the problem rather than fix it. So next time it happens you will have the same issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900