Basically the title. When the serial monitor is open, the output errors, saying:
avrdude: ser_open(): can't open device "\\.\COM7": Access is denied. Failed uploading: uploading error: exit status 1
If I wait for the upload to finish erroring, and then shut the serial monitor, the upload works. If I shut the serial monitor while it's trying to upload. I can't upload my sketch without closing and re-opening the IDE.
I'm on a windows 11 machine and an Arduino uno on version 2.3.6 of the IDE
Not so. When using most boards, Arduino IDE automatically closes the port in Serial Monitor before starting the upload process, only reopening the port in Serial Monitor after the completion of the upload. So Serial Monitor is specifically designed in order to avoid it interfering with uploads.
As @van_der_decken pointed out, unfortunately there is a bug in that port juggling system which can cause the Serial Monitor to interfere with uploads. However, as far as I know, that bug is specific to the boards that have an FTDI FT232R USB chip. It is not known to occur with boards that have any other USB chip.
In @bakedpotatolord2's comment on GitHub, they said they are using an "Arduino uno". The official UNO series of boards use an ATmega16U2 instead of an FT232R FTDI chip, so the bug does not affect them. The common clone/derivative boards either use the ATmega16U2 or WCH CH340, so also are not affected. So I am doubtful the upload error they are experiencing is caused by that bug. However, it is possible.
However, we have received some reports of uploads failing with this error with cheap derivative boards that have strange unlabeled USB chips which are definitely not genuine FTDI chips, but identify as FT232R:
@bakedpotatolord2 Please tell us which USB to serial bridge chip your Arduino board has. This is a black chip near the USB socket.
The chip will usually be identified by writing on the top. This might say something like "Atmel MEGA16U2" or "WCH CH340G" or "SILABS CP2102".
There are some boards on the market that have a USB chip with the same IC package as the WCH CH340, and which are identified by the computer as a CH340. However, these chips don't have the "WCH CH340C ..." labeling like you see on the chip in the picture above:
These mysterious unlabeled chips have different characteristics than the labeled CH340 chips, so please let us know if yours is labeled or not.
If it isn't clear, alternatively you can provide the link to where you bought the board from and we'll see if we can determine the chip from the product listing.
Sorry, I don't have details, but I've had failures to u/l and then I had to say "oh durn it" and click SerMon off. But, anyway, I click it off and put it back up after - when I do use it.
OK, great. Then it looks like the failure is likely caused by the bug @van_der_decken mentioned. The bug was reproduced with boards that have the FTDI FT232 chip, and I have not been able to reproduce it with chips from other manufacturers. However, I don't have an FTDI 231X chip so I can't check whether it is affected. It seems likely the bug also affects this related chip though.
Unfortunately the only workaround I am aware of other than closing Serial Monitor/Serial Plotter before uploading is using the obsolete Arduino IDE 1.8.19 instead of the modern Arduino IDE 2.x. It will be a matter of personal preference which of the two workarounds is the least inconvenient.
I was actually surprised to learn that the RedBoard used the FT231X. I try to be aware of the common USB chips and I hadn't seen mention of this chip before, even though the RedBoard is quite a prominent piece of hardware. I can see that the design change was made all the way back in 2014:
However, that doesn't necessarily mean the change went into production at that time. I see the first tag after that time was V_21, made in 2017. However that was the first tag in the repository, so the change might have been in previous production versions for which no tag was created.