1

I'm trying to create a program in C# that can manipulate the mouse cursor. I am getting a System.IO exception when I call the method in main and run the program.

I'm doing this in Visual Studio 2019. To run the method below, I am using System.Windows.Forms and System.Drawing. I have both referenced.

 public static void AutomateMouse()
 {
       int x = 500;
       int y = 500;
       Cursor.Position = new System.Drawing.Point(x, y);
       Console.WriteLine(Cursor.Position.ToString());
 }

The expected result of this method was printing of the cursor to the coordinates specified in the method. I get this exception, on the fifth line when I run the program:

System.IO.FileNotFoundException: 'Could not load file or assembly
 'System.Security.Permissions, 
Version=0.0.0.0, 
Culture=neutral, 
PublicKeyToken=cc7b13ffcd2ddd51'. 
The system cannot find the file specified.'
Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • 3
    I suggest cleaning and rebuilding your application, and also clear the bin and obj directions from the solution. Something is out of line here. – TheGeneral Aug 05 '19 at 05:36
  • 3
    `Version=0.0.0.0` is definitely wrong - https://www.nuget.org/packages/System.Security.Permissions/. If rebuild doesn't help, then it is either some [assembly binding redirection](https://stackoverflow.com/questions/43365736/assembly-binding-redirect-how-and-why) issue. Or it is a case of mishmashed dependencies (.net framework, .net standard...) Can you show us contents of your csproj file (not all, only the framework and referenced libraries section for System.Drawing and Permissions)? – Eugene Podskal Aug 05 '19 at 05:46
  • 1
    I have fixed the problem. I was using core instead of framework and there was some compatibility problem with System.Drawing. I switched to framework and now the program runs fine. Thanks. – erikmerrill Aug 07 '19 at 02:26

0 Answers0