Problem: error CS2012

Hello everyone I am new to mono game and am trying to create a 2d platformer. Everytim I try and run the debugger on my PC I get this error.

error CS2012: Cannot open ‘C:\Users\sean\documents\visual studio 2015\Projects\Game3\Game3\obj\x86\Debug\Game3.exe’ for writing – ‘Access to the path ‘C:\Users\sean\documents\visual studio 2015\Projects\Game3\Game3\obj\x86\Debug\Game3.exe’ is denied.’

Can anyone tell me how to fix it?

I think I’ve had this problem…
Kind of hard to remember, but try this:

Go to ‘project’ drop down menu, and select ‘Game3 properties’, at the bottom.
A lot of things will pop up…

Look for the button that says ‘Assembly Information’
and press it…

A window will open. Uncheck ‘make assembly com visible’.

I think access is denied, because windows has it marked as “in use”… Its not just that you cant overwrite your exe file from within VS, you also cannot manually delete it in its folder!

I think before I found a solution, the work around was to sign back into widows, which would clear the “in use” flags…

As is obvious, I dont know why all of this is the case, but worked it for me, and other people can run my games and stuff, so its probably fine.

Maybe the last debug run wasn’t terminated correctly and the task is still running. That’s why the OS doesn’t let you compile (=write) the file.
You have to open Task manager and kill the old process. Or reboot.

Why is it trying to run the executable from the obj folder? I think you might have the output directory set to obj instead of the default bin. Obj is the default directory for the intermediate files, so it is trying to copy or write a file to itself when trying to move it to the output directory.

I had the same issue.

Go to the drop-down (solution configuration) where it says debug, release and configuration manager.

On the “Configuration Manager” specify the platform of your project (x86 and x64).

In my case it was ANY CPU. I changed it to x64 (my processor is 64 bits) and all done!

I hope that helps someone.

1 Like