Skip to content

Long git directory name causes error C1083 when building coreclr tests (cl.exe) #110407

Open

Description

@steveharter

Having a long directory name causes issues when building the coreclr tests. I verified that long paths are enabled in both git and the registry.

Repro (Windows x64)

  • Create a long directory name such as C:\git\ThisIsSomewhatOfaLongName
  • Clone runtime repo into that
  • build -s clr+libs (this works)
  • src\tests\build.cmd /p:LibrariesConfiguration=Debug (this fails with the error below)

Error:

[219/384] Building CXX object baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ForeignThreadRevPInvokeUnhandledNative.cpp.obj
FAILED: baseservices/exceptions/UnhandledExceptionHandler/ForeignThreadRevPInvokeUnhandled/CMakeFiles/ForeignThreadRevPInvokeUnhandledNative.dir/ForeignThreadRevPInvokeUnhandledNative.cpp.obj
C:\PROGRA~1\MIB055~1\2022\Preview\VC\Tools\MSVC\1443~1.346\bin\Hostx64\x64\cl.exe  /nologo /TP -DForeignThreadRevPInvokeUnhandledNative_EXPORTS -DHOST_64BIT -DHOST_AMD64 -DHOST_WINDOWS -DNDEBUG -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_WINDOWS -DURTBLDENV_FRIENDLY=Retail -DWINDOWS -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -IC:\git\ThisIsSomewhatOfaLongName\src\native -IC:\git\ThisIsSomewhatOfaLongName\src\tests\Common\Platform /DWIN32 /D_WINDOWS  /GR- /O2 /Ob2 /DNDEBUG -MT /GL /Ox /EHa /nologo /W4 /WX /Oi /Oy- /Gm- /Zp8 /Gy /GS /fp:precise /FC /MP /Zm200 /Zc:strictStrings /Zc:wchar_t /Zc:inline /Zc:forScope /wd4065 /wd4100 /wd4127 /wd4131 /wd4189 /wd4200 /wd4201 /wd4206 /wd4239 /wd4245 /wd4291 /wd4310 /wd4324 /wd4366 /wd4456 /wd4457 /wd4458 /wd4459 /wd4463 /wd4505 /wd4702 /wd4706 /wd4733 /wd4815 /wd4838 /wd4918 /wd4960 /wd4961 /wd5105 /wd5205 /we4007 /we4013 /we4102 /we4551 /we4640 /we4806 /we4055 /we4146 /we4242 /we4244 /we4267 /we4302 /we4308 /we4509 /we4510 /we4532 /we4533 /we4610 /we4611 /we4700 /we4701 /we4703 /we4789 /we4995 /we4996 /w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038 /w44177 /Zi /ZH:SHA_256 /source-charset:utf-8 /guard:cf /guard:ehcont -wd4100 -wd4242 -wd4244 -wd4514 -wd4625 -wd4626 -wd4668 -wd4710 -wd4711 -wd4774 -wd4820 -wd5025 -wd5026 -wd5027 -wd5039 /showIncludes /Fobaseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ForeignThreadRevPInvokeUnhandledNative.cpp.obj /Fdbaseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ /FS -c C:\git\ThisIsSomewhatOfaLongName\src\tests\baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\ForeignThreadRevPInvokeUnhandledNative.cpp
C:\git\ThisIsSomewhatOfaLongName\src\tests\baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\ForeignThreadRevPInvokeUnhandledNative.cpp : fatal error C1083: Cannot open compiler generated file: '': Invalid argument
[240/384] Building CXX object profiler\native\CMakeFiles\Profiler.dir\rejitprofiler\rejitprofiler.cpp.obj
ninja: build stopped: subcommand failed.
BUILDTEST: Error: native test build failed.

I did not attempt to diagnose the root cause but note that the path C:\git\ThisIsSomewhatOfaLongName\src\tests\baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\ForeignThreadRevPInvokeUnhandledNative.cpp is 169 characters, short of MAX_PATH (260).

Activity

  1. ghost added
    needs-area-label
    on Dec 4, 2024
  2. added
    area-Infrastructure-coreclr
    and removed
    needs-area-label
    on Dec 4, 2024
  3. added
    untriaged
    on Dec 4, 2024
  4. dotnet-policy-service commented on Dec 4, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @hoyosjs
    See info in area-owners.md if you want to be subscribed.

  5. changed the title [-]Long git directory name causes build error C1083 when building coreclr tests (cl.exe)[/-] [+]Long git directory name causes error C1083 when building coreclr tests (cl.exe)[/+] on Dec 4, 2024
  6. huoyaoyuan commented on Dec 5, 2024

    @huoyaoyuan
    Member

    Enabling long path support is listed under Windows requirements. Do you still encounter this error with long path enabled? It can be easily enabled with Dev Home.

  7. steveharter commented on Dec 5, 2024

    @steveharter
    ContributorAuthor

    I do have long paths enabled:

    PS C:\git\ThisIsSomewhatOfaLongPath> git config --system core.longpaths
    true
    
    PS C:\git\ThisIsSomewhatOfaLongPath> Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled
    LongPathsEnabled : 1
    
  8. steveharter commented on Dec 5, 2024

    @steveharter
    ContributorAuthor

    I believe cl.exe has issues with MAX_PATH even when long paths are enabled in Windows registry:
    https://developercommunity.visualstudio.com/t/compiler-cant-find-source-file-in-path-/10221576
    https://developercommunity.visualstudio.com/t/clexe-command-line-error-d8022-cannot-open-path-re/1478916

    However, I didn't see where I was very close to MAX_PATH. Perhaps there was some artifacts\bin folders that have a longer path but not shown in the error message.

  9. mdh1418 commented on Dec 10, 2024

    @mdh1418
    Member

    I'm starting to see this too when building runtime tests locally after rebasing on main. It seems to be related to the new test added in #109806. I'm also not sure why that test needs to be compiled if I want to just build a separate particular runtime test .\src\tests\build.cmd test <path_to_specific_runtime_test_csproj>

  10. mdh1418 commented on Dec 11, 2024

    @mdh1418
    Member

    I ended up using subst to associate my local repo's path to a drive letter (Thanks @tommcdon for the suggestion), and was able to shorten the generated ForeignThreadRevPInvokeUnhandledNative object path to under 250 chars. (I also have long paths enabled, similar to Steve)

  11. tommcdon commented on Dec 11, 2024

    @tommcdon
    Member

    Another thing to try is to enable long paths in windows per
    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
    "LongPathsEnabled"=dword:00000001
    
  12. steveharter commented on Dec 18, 2024

    @steveharter
    ContributorAuthor

    Another thing to try is to enable long paths in windows per
    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later:

    Long paths are enabled locally for me and for @mdh1418.

    Those instructions also say to update the app's manifest, however the app here is cl.exe and FWIW the links I added above for known issues with cl.exe mention other users who tried to update the cl.exe manifest but then got other errors.

    So the root problem appears to be with cl.exe needing a proper manifest and\or it doesn't use the \\?\ prefix necessary for paths > MAX_PATH.

  13. kkukshtel-unity commented on Feb 5, 2025

    @kkukshtel-unity

    I'm also seeing this on windows fwiw:

    [221/387] Building CXX object baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ForeignThreadRevPInvokeUnhandledNative.cpp.obj
    FAILED: baseservices/exceptions/UnhandledExceptionHandler/ForeignThreadRevPInvokeUnhandled/CMakeFiles/ForeignThreadRevPInvokeUnhandledNative.dir/ForeignThreadRevPInvokeUnhandledNative.cpp.obj
    C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1441~1.341\bin\Hostx64\x64\cl.exe  /nologo /TP -DBUILDENV_DEBUG=1 -DDEBUG -DForeignThreadRevPInvokeUnhandledNative_EXPORTS -DHOST_64BIT -DHOST_AMD64 -DHOST_WINDOWS -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_WINDOWS -DURTBLDENV_FRIENDLY=Debug -DWINDOWS -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -ID:\UnitySrc\Workspace\runtime\src\native -ID:\UnitySrc\Workspace\runtime\src\tests\Common\Platform /DWIN32 /D_WINDOWS  /GR- /Zi /Ob0 /Od /RTC1 -MTd /Od /EHa /nologo /W4 /WX /Oi /Oy- /Gm- /Zp8 /Gy /GS /fp:precise /FC /MP /Zm200 /Zc:strictStrings /Zc:wchar_t /Zc:inline /Zc:forScope /wd4065 /wd4100 /wd4127 /wd4131 /wd4189 /wd4200 /wd4201 /wd4206 /wd4239 /wd4245 /wd4291 /wd4310 /wd4324 /wd4366 /wd4456 /wd4457 /wd4458 /wd4459 /wd4463 /wd4505 /wd4702 /wd4706 /wd4733 /wd4815 /wd4838 /wd4918 /wd4960 /wd4961 /wd5105 /wd5205 /we4007 /we4013 /we4102 /we4551 /we4640 /we4806 /we4055 /we4146 /we4242 /we4244 /we4267 /we4302 /we4308 /we4509 /we4510 /we4532 /we4533 /we4610 /we4611 /we4700 /we4701 /we4703 /we4789 /we4995 /we4996 /w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038 /w44177 /Zi /ZH:SHA_256 /source-charset:utf-8 /homeparams /guard:cf /guard:ehcont -wd4100 -wd4242 -wd4244 -wd4514 -wd4625 -wd4626 -wd4668 -wd4710 -wd4711 -wd4774 -wd4820 -wd5025 -wd5026 -wd5027 -wd5039 /showIncludes /Fobaseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ForeignThreadRevPInvokeUnhandledNative.cpp.obj /Fdbaseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\CMakeFiles\ForeignThreadRevPInvokeUnhandledNative.dir\ /FS -c D:\UnitySrc\Workspace\runtime\src\tests\baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\ForeignThreadRevPInvokeUnhandledNative.cpp
    D:\UnitySrc\Workspace\runtime\src\tests\baseservices\exceptions\UnhandledExceptionHandler\ForeignThreadRevPInvokeUnhandled\ForeignThreadRevPInvokeUnhandledNative.cpp : fatal error C1083: Cannot open compiler generated file: '': Invalid argument
    [258/387] Building CXX object profiler\native\CMakeFiles\Profiler.dir\classfactory.cpp.obj
    ninja: build stopped: subcommand failed.
    

    Setting a reg key isn't working either. I had to also use subst to shorten the path

  14. 1 remaining item

  15. kg commented on Apr 9, 2025

    @kg
    Contributor

    CMake is also generating a warning about this for me:

    CMake Warning in baseservices/exceptions/UnhandledExceptionHandler/ForeignThreadRevPInvokeUnhandled/CMakeLists.txt:
      The object file directory
    
        Z:/runtime/artifacts/tests/coreclr/obj/windows.x64.Checked/Native/baseservices/exceptions/UnhandledExceptionHandler/ForeignThreadRevPInvokeUnhandled/CMakeFiles/ForeignThreadRevPInvokeUnhandledNative.dir/./
    
      has 205 characters.  The maximum full path to an object file is 250
      characters (see CMAKE_OBJECT_PATH_MAX).  Object file
    
        ForeignThreadRevPInvokeUnhandledNative.cpp.obj
    
      cannot be safely placed under this directory.  The build may not work
      correctly.
    
  16. MichalStrehovsky commented on Jun 10, 2025

    @MichalStrehovsky
    Member

    Cc @VSadov who added the test with the long name

  17. mdh1418 commented on Jun 19, 2025

    @mdh1418
    Member

    Originally, using subst to map a virtual drive to my runtime repo worked, but now VS Code Version: 1.101.0 (user setup) is not showing any of the files/folders in the Explorer view for that virtual drive. (Previously it did show files/folders, but I think upgrading VS Code versions changed behavior)

    Image

    Not sure if this is a temporary thing in VS Code, but regardless, it feels like we should address the underlying issue.
    Is it really mandatory for building a specific native test like .\src\tests\build.cmd -test tracing/eventpipe/bigevent/bigevent.csproj /p:RuntimeConfiguration=Debug /p:LibrariesConfiguration=Debug should trigger building baseservices/exceptions/UnhandledExceptionHandler/ForeignThreadRevPInvokeUnhandled/CMakeLists.txt?

    Is it clear whether or not we can only build what's necessary when specifying the -test arg, instead of trying to build every subdir's CMakeLists.txt?

  18. AaronRobinsonMSFT commented on Jun 19, 2025

    @AaronRobinsonMSFT
    Member

    causes error C1083 when building coreclr tests (cl.exe)

    Has anyone reached out to the MSVC team about this issue?

  19. AaronRobinsonMSFT commented on Jun 20, 2025

    @AaronRobinsonMSFT
    Member

    This was mostly from the internal perspective. The issue already references older issues on Developer Community - #110407 (comment).

  20. added this to the Future milestone on Jul 21, 2025
  21. removed
    untriaged
    on Jul 21, 2025
  22. added and removed
    area-Infrastructure-coreclr
    on Apr 13, 2026
  23. dotnet-policy-service commented on Apr 13, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/runtime-infrastructure
    See info in area-owners.md if you want to be subscribed.

  24. krwq commented on Nov 10, 2026

    @krwq
    Member

    I seem to be hitting this quite frequently with the Copilot app, which creates worktrees at paths like:

    C:\Users\kwicher\.copilot\repos\copilot-worktrees\runtime\krwq-effective-tribble
    C:\Users\kwicher\.copilot\repos\copilot-worktrees\runtime\krwq-laughing-meme
    

    Some generated object paths then get long enough to hit this issue.

    I'm exploring a workaround using Windows 8.3 path aliases. It looks promising so far, and I'll see if I can turn it into a reasonable build-script workaround that covers most of these cases where aliases are available. I'll follow up with a PR once it's ready.

  25. krwq commented on Nov 10, 2026

    @krwq
    Member

    Proper fix requires cl.exe update so I can't claim PR fixes it but it will definitely make it much less likely to hit. @steveisok the only ways I can see as permanent solution on Windows is either changing compiler to i.e. clang or asking team owning cl.exe to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions