2

I have been learning GoLang for some time and recently started facing this strange issue while running exe built using go build command.

I am using VS Code 1.55 on Windows 10 (Enterprise edition) computer.

I created few sample programs in GoLang and was able to run them from VS Code without any issues.

Following is one such simple program for performing bubble sort.

package main

import "fmt"

func main() {

    arr := []int{6, 2, 1, 3, 7, 5, 4, 8}
    n := len(arr)
    input := make([]int, n)

    _ = copy(input, arr)

    fmt.Println(input)

    performBubbleSort(input, true)

    fmt.Println(input)
}

func performBubbleSort(arr []int, popTop bool) {
    // Removed the soring logic just to rule it out.
    // This is literally an empty function with no code in it...
}

I normally run following commands to build and run a GoLang program.

go build
.\sampleapp.exe

This was running all fine with above commands. Recently I have been seeing following error while running .\sampleapp.exe from VS Code terminal.

AccessDenied Error

I tried to create fresh new GoLang programs and they also have the same issue. Sometimes just using fmt causes this behavior or sometimes fmt works fine but other modules such as os causes the Access Denied error.

Searched on Google about this and found that people are suspecting the Antivirus to block the exe from running and also suggested to run with Administrator privileges.

I am already running VS Code with Administrator privileges. Also I doubt that it is antivirus because I have other program created which is a web API developed in GoLang and I am able to run it without any issue.

I am scratching my head around this and searching in Google to find the cause and solution to this. I am not able to create any new GoLang program to experiment with other learnings due to this issue.

Any help would be appreciated on this. Feel free to ask if any other information is required on this.

EDIT 1:

Created a new fresh program as following.

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello world")
}

This programs has the same issue and shows the following output.

enter image description here

EDIT 2:

As per the suggestion from @MrFuppes I tried running command go run .\main.go but that did not help.

When I tried to run go run .\main.go for the above EDIT 1 code, it failed with Access denied error.

enter image description here

If I remove used of fmt package, it works fine.

Also tried the same command for the program with performBubbleSort above, and it ended up with the same error.

Chetan
  • 6,711
  • 3
  • 22
  • 32
  • It looks like calling the executable is denied access, not `go build` – FObersteiner Apr 03 '21 at 16:44
  • Yes @MrFuppes.... it is not the `go build`... but I need to know why executable is denied the access even when the code does not use any of the native resources such as disk, network or memory... – Chetan Apr 03 '21 at 16:52
  • Hm, does any of these suggestions help, [1](https://stackoverflow.com/q/43019581/10197418), [2](https://stackoverflow.com/q/58909806/10197418), [3](https://stackoverflow.com/q/14511495/10197418)? I actually never encountered this issue on Windows, but I noticed very slow compilation speed compared to when I compile go code on Linux - which also seemed to be related to anti-virus software on Windows. – FObersteiner Apr 03 '21 at 17:48
  • @MrFuppes.. Thank your for the suggestions... 1. My machine has Windows Defender Firewall installed and I can not add a path as an exception for executables to run. Also I am already running command prompt and VS Code with Administrator access. 2. Tried using `go run .\main.go` but that didn't solve the issue... (Question updated). 3. Could not find `Application Experience` windows service on my machine (Windows 10). – Chetan Apr 04 '21 at 13:58
  • 1
    Finally I was able to get rid of the error and run the exes successfully... I can not say if that's the solution but I tried two things... 1. Followed old and very popular Microsoft hack and restarted my computer. 2. Upgraded GoLang to latest version (from 1.15 to 1.16.3). After that I am able to run the exes created by `go build` command without any issues... and running `go run .\main.go` also works find. – Chetan Apr 04 '21 at 14:25
  • *old and very popular Microsoft hack* ^^ Windows keeps surprising me... glad you can run your go builds now. – FObersteiner Apr 04 '21 at 15:20

0 Answers0