Skip to content

[.NET 8 Regression] error CS1504: Source file "<Path to XAML>" could not be opened --- Could not find file #34438

Open

Description

@WardenGnaw

Describe the bug

A .NET project fails to build with the .NET 8 SDK but succeeds with the .NET 7 SDK. It seems to be an issue with the WPF generated source files not being able to find the original XAML file.

To Reproduce

  1. Have .NET 8 SDK 8.0.100-preview.6.23330.14
  2. Checkout https://github.com/microsoft/MIEngine/tree/main
  3. Run dotnet build src\MIDebugEngine.sln
  4. See error logs
Errors Logs
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(49,18): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(57,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(65,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(73,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(81,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(89,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(97,19): error CS1504: Source file 'UI\Containe
rPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2gao
z2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(105,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(113,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(121,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(129,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(137,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(145,19): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(166,21): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]
C:\src\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs(246,23): error CS1504: Source file 'UI\Contain
erPickerDialogWindow.xaml' could not be opened -- Could not find file. [C:\src\MIEngine\src\SSHDebugPS\SSHDebugPS_zh2ga
oz2_wpftmp.csproj]

Note: The build works if you use a .NET 7 SDK like
dotnet "C:\Program Files\dotnet\sdk\7.0.109\dotnet.dll" build src\MIDebugEngine

Exceptions (if any)

None. This is just dotnet build

Further technical details

  • Include the output of dotnet --info
dotnet --info output
.NET SDK:
 Version:   8.0.100-preview.6.23330.14
 Commit:    ba97796b8f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-preview.6.23330.14\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-preview.6.23329.7
  Architecture: x64
  Commit:       5340be2ccc

.NET SDKs installed:
  7.0.200 [C:\Program Files\dotnet\sdk]
  7.0.306 [C:\Program Files\dotnet\sdk]
  8.0.100-preview.3.23178.7 [C:\Program Files\dotnet\sdk]
  8.0.100-preview.6.23330.14 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.3.23177.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.6.23329.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.3.23174.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.6.23329.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.3.23178.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.6.23329.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
    VS Version does not matter as this repros with just the dotnet commandline but it reproduces with Visual Studio 17 Preview 7.

Activity

  1. ghost added
    untriaged
    on Aug 4, 2023
  2. WardenGnaw commented on Aug 4, 2023

    @WardenGnaw
    Author

    @chuckries Helped point out that this may be an issue caused with the project overriding the <IntermediateOutputPath>

    <IntermediateOutputPath>$(MIEngineRoot)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>

    https://github.com/microsoft/MIEngine/blob/3986396d9c31c6ac729c6b52fa79f34d7a253e95/build/all_projects.settings.targets#L22

  3. KirillOsenkov commented on Sep 1, 2023

    @KirillOsenkov
    Member

    Just ran into this as well, ping me on Teams if you need a repro.

  4. miloush commented on Sep 4, 2023

    @miloush

    Works in 8.0.100-preview.3.23178.7

  5. abpiskunov commented on Sep 22, 2023

    @abpiskunov
    Contributor

    Still repros with 8.0.100-rc.1.23463.5. We do override IntermediateOutputPath however not doing anything crazy, just group all projects obj folder under common obj folder in the root. Each project stil has its own subfolder under common obj.

  6. added
    needs team triage
    and removed
    untriaged
    on Sep 22, 2023
  7. dsplaisted commented on Sep 24, 2023

    @dsplaisted
    Member

    I've investigated this and found a workaround, which is to set the EmbedUntrackedSources property to false.

    @tmat This is a regression in .NET 8 that looks like it's related to Source Link embedding untracked files, can you take a look?

    I compared a build of the project between the .NET 7 and the .NET 8 SDK. In the .NET 8 SDK where it fails, there are EmbeddedFiles items passed to the compiler in the inner XAML markup compilation pass 2 build, that are not present in the .NET 7 SDK:

    EmbeddedFiles
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs
            Link = ContainerPickerDialogWindow.g.cs
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\GeneratedInternalTypeHelper.g.cs
            Link = GeneratedInternalTypeHelper.g.cs
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\GeneratedAssemblyInfo
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
    

    These appear to be causing, or te be related to, the error that is being generated.

  8. tmat commented on Sep 25, 2023

    @tmat
    Member

    This is an old bug in nuget/wpf interaction: dotnet/wpf#1718
    IncludePackageReferencesDuringMarkupCompilation = true is required for the fix to kick in. MIEngine repo sets this property to false in src\SSHDebugPS\SSHDebugPS.csproj which causes the build failure.

  9. tmat commented on Sep 25, 2023

    @tmat
    Member

    @KirillOsenkov Is property IncludePackageReferencesDuringMarkupCompilation set to false in your repro project?

  10. KirillOsenkov commented on Sep 25, 2023

    @KirillOsenkov
    Member

    It doesn't appear to be set or mentioned at all.

    @dsplaisted I don't have the broken SDK on this machine anymore, so if you could try setting IncludePackageReferencesDuringMarkupCompilation = true and see if it builds successfully?

  11. nagilson commented on Sep 25, 2023

    @nagilson
    Member

    I've investigated this and found a workaround, which is to set the EmbedUntrackedSources property to false.

    @tmat This is a regression in .NET 8 that looks like it's related to Source Link embedding untracked files, can you take a look?

    I compared a build of the project between the .NET 7 and the .NET 8 SDK. In the .NET 8 SDK where it fails, there are EmbeddedFiles items passed to the compiler in the inner XAML markup compilation pass 2 build, that are not present in the .NET 7 SDK:

    EmbeddedFiles
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\UI\ContainerPickerDialogWindow.g.cs
            Link = ContainerPickerDialogWindow.g.cs
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\GeneratedInternalTypeHelper.g.cs
            Link = GeneratedInternalTypeHelper.g.cs
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\GeneratedAssemblyInfo
        c:\Users\noahgilson\MIEngine\obj\Debug\SSHDebugPS\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
    

    These appear to be causing, or te be related to, the error that is being generated.

    Thank you @dsplaisted for investigating. I could not figure out what was wrong from the binlog.

    @abpiskunov Does setting IncludePackageReferencesDuringMarkupCompilation=true solve the problem for your 3 repos? NVM. I saw the email thread, looks like its working for you.

    And @tmat thanks for following up, is there a reason this may not have surfaced for customers in .NET 7 but would begin to surface in .NET 8? If so, we should create a breaking change doc.

  12. 20 remaining items

  13. KirillOsenkov commented on Nov 15, 2023

    @KirillOsenkov
    Member
  14. bouchraRekhadda commented on Nov 23, 2023

    @bouchraRekhadda

    Offline we figured out that there are two ways to get into this situation:

    1.Setting <IncludePackageReferencesDuringMarkupCompilation>false</IncludePackageReferencesDuringMarkupCompilation> 2. Having a .NET Framework-targeting project

    • Using .NET SDK 8
    • Without UseWPF and with manual XAML assembly references
    • With a customized obj/IntermediateOutputPath

    dotnet/wpf#8378 fixes the former.

    sdk344838.zip is a repro of the latter.

    We are in second use case, targeting .NET Framework 4.7.1 while using .NET SDK 8 and redirecting to a costume IntermediateOutputPath.
    For now we are obliged to rollback to .NET 6, but it seems like there is no workaround for our use case.

  15. singhashish-wpf commented on Nov 23, 2023

    @singhashish-wpf
    Contributor

    Starting to see these in the wild as folks update to .NET 8.

    Did we end up having a doc page or an aka.ms links that I can point people to?

    aka.ms/net8wpfsl
    This points to the known issues page.

  16. bouchraRekhadda commented on Nov 23, 2023

    @bouchraRekhadda

    aka.ms/net8wpfsl
    This points to the known issues page.

    @singhashish-wpf the workarounds suggested, i.e. setting IncludePackageReferencesDuringMarkupCompilation to true it submerges the famous error dotnet/wpf#5700

    Error MC3074 The tag 'X' does not exist in XML namespace 'clr-namespace:Y'

    Am I looping something ?

  17. singhashish-wpf commented on Nov 23, 2023

    @singhashish-wpf
    Contributor

    @bouchraRekhadda EmbedUntrackedSources set as False. Does this workaround not work for you>?

  18. bouchraRekhadda commented on Nov 23, 2023

    @bouchraRekhadda

    @bouchraRekhadda EmbedUntrackedSources set as False. Does this workaround not work for you>?

    Unfortunately no. I still have the same error MC3074.

  19. singhashish-wpf commented on Nov 23, 2023

    @singhashish-wpf
    Contributor

    @bouchraRekhadda EmbedUntrackedSources set as False. Does this workaround not work for you>?

    Unfortunately no. I still have the same error MC3074.

    Can you share a minimal repro? And the versions of SDKs you are using?

  20. singhashish-wpf commented on Nov 23, 2023

    @singhashish-wpf
    Contributor

    The 2nd case reproduces for me on .NET6, .NET7, .NET8 as well, Most probably I am missing something here. I heard that this is a regression in .NET8.
    cc:// @KirillOsenkov @rainersigwald

    1. Having a .NET Framework-targeting project
    • Using .NET SDK 8
    • Without UseWPF and with manual XAML assembly references
    • With a customized obj/IntermediateOutputPath

    Attaching
    binlogs.zip
    binlogs.

  21. KirillOsenkov commented on Nov 26, 2023

    @KirillOsenkov
    Member

    Hi Ashish, make sure to comment out the line 21 in MainWindow.xaml.cs:
    C:\Users\singhashish\Downloads\sdk344838\FxWpf\MainWindow.xaml.cs(21,10)

    If you see in Rainer's repro, it is commented out:
    #34438 (comment)
    https://github.com/dotnet/sdk/files/13219712/sdk344838.zip

  22. KirillOsenkov commented on Nov 26, 2023

    @KirillOsenkov
    Member

    Oh, and after you unzip the repro, make sure to run git init in the folder and add the source files and make a commit. This way the SourceLink logic kicks in which breaks:

    image

  23. singhashish-wpf commented on Nov 27, 2023

    @singhashish-wpf
    Contributor

    Thanks @KirillOsenkov for the repro steps. I was able to repro.
    While checking I see that the MarkupCompilePass1 and MarkupCompilePass2 targets are executing successfully. The problem happens in the CoreCompile part later for the main project(Not the temporary target assembly).
    Also this change would be in NETFX as i understand, While the change shouldn't be in GenerateTemporaryTargetAssembly in my understanding, but there is a lot of code diff in NETFX and NetCore versions of the file.

    From what I understand, this is happening as the EmbedUntrackedSources is set as True for the main project by default and we need some mechanism to make it false for such kind of projects(IntermediateOutputPath + Reference Desktop WPF libs). Not quite sure on where that change would be, @rainersigwald Any thoughts?

  24. otac0n commented on Dec 1, 2023

    @otac0n

    I feel like this is a security issue. This will potentially disclose comments customers did not intend to disclose.

  25. vikukush commented on Dec 2, 2023

    @vikukush

    This is what I'm using to workaround:

      <!-- Another XAML hack for .NET Core SDK version 8 -->
      <Target Name="NETCoreSDKHack" BeforeTargets="MarkupCompilePass1" Condition="'@(Page)'!=''">
        <Message Text="Copying @(Page) to output to workaround NET SDK bug https://github.com/dotnet/sdk/issues/34438" Importance="high" />
        <Copy SourceFiles="@(Page)" DestinationFolder="$(IntermediateOutputPath)" />
      </Target>
    
  26. added a commit that references this issue on Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions