Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unable to find type" XAMLIL error message after deleting window from project #4968

Closed
joneuhauser opened this issue Oct 29, 2020 · 9 comments · Fixed by #6569
Closed

"Unable to find type" XAMLIL error message after deleting window from project #4968

joneuhauser opened this issue Oct 29, 2020 · 9 comments · Fixed by #6569

Comments

@joneuhauser
Copy link

This is a weird one. Versions: AvaloniaUI 0.10.0-pre6, Avalonia for Visual Studio 0.9.11.0

Steps:

  1. Create a new Avalonia Project (doesn't matter if MVVM or not)
  2. Right click project -> add a new Window
  3. Don't change the name of the window, will be named Window1.axaml
  4. Delete the Window by deleting the file Window1.axaml. This deletes both Window1.axaml and Window1.axaml.cs.

Try to compile the solution. An error message occurs: Unable to find type AvaloniaApplication1.Window1 Line 1, Position 2.

Grep the entire solution for Window1. No result.

Clean and rebuild the solution. The error persists.

Workaround I found:

  • Add a window with the same name again.
  • Rename the window. Only now will the window name show up in the csproj file
  • Delete the renamed window.

Now everything compiles fine again.

@MarchingCube
Copy link
Collaborator

I found something similar (although incorrectly reported it in the compiler repo) kekekeks/XamlX#37

@molnard
Copy link

molnard commented Feb 17, 2021

Walkaround solution can be to delete compiled files with:

git clean -xdf

and rebuild the solution.

@MarchingCube
Copy link
Collaborator

This issue seems to appear fairly frequently lately and basically means that deleting XAML files without changing a line of code in a project will end up with this error.

Also in my case forcing 20+ devs to wipe their repo and rebuild for 10 minutes is not the greatest option. @kekekeks Are you going to have time to investigate this sometime?

@kekekeks
Copy link
Member

That error means that XAML resource is still present in either Roslyn-generated assembly or obj/$(Configuration)/$(TargetFramework)/Avalonia/resources file.

GenerateAvaloniaResources target is supposed to be re-run when resource is deleted, but I guess MSBuild doesn't handle file deletion that well.

@kekekeks
Copy link
Member

Mkay, reproduced with much simpler project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <Target Name="TestTarget" 
          BeforeTargets="CoreCompile;CoreResGen"
          Inputs="@(MyResource);$(MSBuildAllProjects)"
          Outputs="list.lst">
    <WriteLinestoFile 
        File="list.lst"
        Overwrite="True"
        Lines="@(MyResource)"
    />
   <Message Importance="high" Text="Files: @(MyResource)"/>
  </Target>
  <ItemGroup>
     <MyResource Include="*.txt"/>
     <UpToDateCheckInput Include="@(MyResource)" />
  </ItemGroup>
</Project>

When any of *.txt files gets removed TestTarget is NOT re-run.

From my point of view that's clearly a bug in MSBuild, but I might be missing something.

@MarchingCube
Copy link
Collaborator

Perhaps we should report it to https://github.com/dotnet/msbuild?

@MarchingCube
Copy link
Collaborator

Found one random SO answer claiming that missing inputs won't invalidate targets: https://stackoverflow.com/a/48483825

@kekekeks
Copy link
Member

Apparently that's by design and we are supposed to do the following:

  1. have a separate target that gathers the list of files and writes it to some file with WriteOnlyWhenDifferent
  2. add said file as an input for our target

An example of doing that is here https://github.com/Szer/GiraffeGenerator/blob/f488a4a0c693cc954557960da19015169e7f8f76/src/GiraffeGenerator.Sdk/build/GiraffeGenerator.Sdk.targets#L34-L46

@kekekeks
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants