locked
DEVENV Command line build fails with: "This operation may only take place in the UI thread" RRS feed

  • Question

  • Hello,

    we virtualized our build server and having issues building some c++ projects.

    It is a win7 (we have some vb6 projects) with visual studio 2017.

    When I build a project it just errors out with "This operation may only take place in the UI thread".

    I have no idea why and what I could try to fix it. I have also a Win10 build machine where the problem does not happen. We want to stick with the Win7 build machine though, because on the Win10 one we got issues with some vb6 projects.

    If I use msbuild it works fine, I would rather not replace all devenv calls for now though.

    Anyone an idea what the issue could be or how to debug it?
    Wednesday, April 25, 2018 7:21 AM

All replies

  • Just noticed that it is sometimes even random, one time it compiles, one time it errors out with: "This operation may only take place in the UI thread", with the 100% same code.
    Wednesday, April 25, 2018 7:34 AM
  • Hi JannyD,

    Other members also met this kind of issue before, please check that whether it is related to the .vcxproj.filters in your side.

    https://stackoverflow.com/questions/29384333/building-x64-c-project-from-command-line-says-this-operation-should-only-take

    If the same app has no issue in different machines, maybe you could compare the solution folders/files in your side. Please also check the project files. Maybe you could find much more information.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 26, 2018 10:04 AM
  • This happens here very often too. It's a regular C++ project with no MFC or other dependencies. Using the latest version 15.7.1 of VS 2017. Building from IDE produces no errors or warnings. Building the same project from a command line by calling devenv result in the error "This operation should only take place on the UI thread." with no indication of what might be wrong. The error happens randomly: sometimes the Win32 configuration builds, but x64 one fails. Sometimes it stops at Win32. All .filters and other project files are valid (did I mention that the IDE processes them without any error?).

    If someone from the VS team could at least give us a hint what to look for to avoid this problem that would be much appreciated!

    Saturday, May 26, 2018 6:46 PM
  • We too see this error intermittently.

    We have an NSIS script that attempts to build a vcxproj file.

    It gets run from a Visual Build Pro script to further complicate things.

    1>------ Rebuild All started: Project: NSISGAC, Configuration: Release Win32 ------
    1>This operation should only take place on the UI thread.
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

    This is a very small native c++ dll project.

    Tuesday, June 5, 2018 1:48 AM
  • This happens to me very often too. I have changed to use msbuild finally.

    But msbuild don't stop when build error!!

    Thursday, June 7, 2018 12:49 AM
  • It seems that bug was localized and will be fixed in VS 2017 15.8.x. (it fixed in 15.8 preview 4)

    https://developercommunity.visualstudio.com/content/problem/240541/devenv-command-line-build-fails-with-this-operatio.html

    Added a solution by Lifeng Lu [MSFT] · 03/07 22:54

    Our automation tests also reported this problem. We added more diagnostic in this area, so the future error message should contain a more detailed stack information. With this change, and some other threading related fixes, we can no longer hit this problem in 15.8 preview 4 bits, and consider this to be fixed in that update preview. You can try it, once the preview is released. By any chance you see that happens again, please notify us with hopefully new detailed messages, and we will address the problem based on that. Until that happens, we consider this issue as fixed in the 15.8 preview 4.

    Friday, July 20, 2018 7:23 AM
  • there is another problem, when build using batch file who's content listed as below

    @devenv %~dp0\build\libsample.sln /Build "Debug|Win32" > %~dp0\build.log
    @devenv %~dp0\build\libsample.sln /Build "Release|Win32" >> %~dp0\build.log
    @devenv %~dp0\build\libsample.sln /Build "Debug|x64" >> %~dp0\build.log
    @devenv %~dp0\build\libsample.sln /Build "Release|x64" >> %~dp0\build.log

    after first building completed, the second or third (randomly) will give build error:
    Another program is using this file, and the process cannot be accessed.

    if make some delay after build, all building will be successful
    @devenv %~dp0\build\libsample.sln /Build "Debug|Win32" > %~dp0\build.log
    @ping 127.1 -n 5 >nul
    @devenv %~dp0\build\libsample.sln /Build "Release|Win32" >> %~dp0\build.log
    @ping 127.1 -n 5 >nul
    @devenv %~dp0\build\libsample.sln /Build "Debug|x64" >> %~dp0\build.log
    @ping 127.1 -n 5 >nul
    @devenv %~dp0\build\libsample.sln /Build "Release|x64" >> %~dp0\build.log


    • Edited by dong.zeng Thursday, August 2, 2018 7:57 AM change content
    Thursday, August 2, 2018 7:56 AM