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

After Update from 11.0 to 11.1.3 published app has runtime errors with double packed resources #16838

Open
peter-friedland-t2i opened this issue Aug 28, 2024 · 3 comments
Labels

Comments

@peter-friedland-t2i
Copy link

peter-friedland-t2i commented Aug 28, 2024

Describe the bug

I have updated our avalonia application from 11.0.11 to 11.1.3. The application builds and runs properly from IDE or dotnet run. But if I publish the app self contained for windows at runtime the following error occurs:

System.ArgumentException: An item with the same key has already been added. Key: /Assets/Icons.axaml
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](List`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Avalonia.Platform.Internal.AssemblyDescriptor..ctor(Assembly assembly)
   at Avalonia.Platform.StandardAssetLoader..ctor(IAssemblyDescriptorResolver resolver, Assembly assembly)
   at Avalonia.Platform.StandardAssetLoader..ctor(Assembly assembly)
   at Avalonia.Platform.StandardRuntimePlatformServices.Register(Assembly assembly)
   at Avalonia.AppBuilder.<UseStandardRuntimePlatformSubsystem>b__68_0()
   at Avalonia.AppBuilder.SetupUnsafe()
   at Avalonia.AppBuilder.Setup()
   at Avalonia.AppBuilder.SetupWithLifetime(IApplicationLifetime lifetime)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at Company.Application1.App.Program.Main(String[] args) in C:\Users\peter.friedland\source\repos\HyperPlan-App\source\HyperPlan.App\Program.cs:line 27

Here is the project file of the avalonia app:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
        <Nullable>enable</Nullable>
        <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
        <ApplicationManifest>app.manifest</ApplicationManifest>
        <SelfContained>true</SelfContained>
        <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
        <RootNamespace>Company.Application1.App</RootNamespace>
        <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
        <AssemblyName>Application1.App</AssemblyName>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <TrimMode>full</TrimMode>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
        <DocumentationFile>bin\Release\Application1.App.xml</DocumentationFile>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
        <NoWarn>1701;1702</NoWarn>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
        <DocumentationFile>bin\Debug\Application1.App.xml</DocumentationFile>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Avalonia" Version="11.1.3" />
        <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.3" />
        <PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.0.10" />
        <PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
        <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.3" />
        <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
        <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
        <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
        <PackageReference Include="GitVersion.MsBuild" Version="6.0.2">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Kitware.AvaloniaControls" Version="9.3.2023.1015" />
        <PackageReference Include="Kitware.mummy.Runtime" Version="1.1.0" />
        <PackageReference Include="Kitware.VTK" Version="9.3.2023.1015" />
        <PackageReference Include="Lamar" Version="13.1.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
        <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
        <PackageReference Include="NLog" Version="5.3.3" />
        <PackageReference Include="NLog.Appsettings.Standard" Version="2.1.0" />
        <PackageReference Include="NLog.Extensions.Logging" Version="5.3.12" />
        <PackageReference Include="PdfiumViewer" Version="2.13.0">
            <NoWarn>NU1701</NoWarn>
        </PackageReference>
        <PackageReference Include="PdfiumViewer.Native.x86_64.v8-xfa" Version="2018.4.8.256" />
        <PackageReference Include="ScottPlot.Avalonia" Version="5.0.37" />
        <PackageReference Include="Company.Application1.ModelDefinition" Version="0.7.0-alpha.23" />
		<PackageReference Include="Company.Application1.Model" Version="0.7.0-alpha.22" />
    </ItemGroup>

    <ItemGroup>
        <AvaloniaResource Include="Assets\**" />
    </ItemGroup>

    <ItemGroup>
        <Compile Update="View\MainWindow.axaml.cs">
            <DependentUpon>MainWindow.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Assets\Resources.Designer.cs">
            <DesignTime>True</DesignTime> 
            <AutoGen>True</AutoGen>
            <DependentUpon>Resources.resx</DependentUpon>
        </Compile>
        <Compile Update="Resources.Designer.cs">
            <DesignTime>True</DesignTime>
            <AutoGen>True</AutoGen>
            <DependentUpon>Resources.resx</DependentUpon>
        </Compile>
        <Compile Update="Pages\DataImport\DataImportPageView.axaml.cs">
            <DependentUpon>PatientImportPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\PatientImport\PatientImportPageView.axaml.cs">
            <DependentUpon>PatientImportPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\ApplicatorSetup\ApplicatorSetupPageView.axaml.cs">
            <DependentUpon>DataImportPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\SarPlanning\SarPlanningPageView.axaml.cs">
            <DependentUpon>ApplicatorSetupPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\SimulationQueue\SimulationQueuePanelView.axaml.cs">
            <DependentUpon>ApplicatorSetupPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\TestVTK\TestVTK.axaml.cs">
            <DependentUpon>ApplicatorSetupPageView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Shell\Dialogs\YesNoDecisionDialogView.axaml.cs">
            <DependentUpon>YesNoDecisionView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Shared\Controls\ApplicatorRingParametersView.axaml.cs">
            <DependentUpon>ApplicatorRingParametersView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\PatientImport\PatientImportDialogView.axaml.cs">
            <DependentUpon>ConfirmationDialogView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
        <Compile Update="Shared\MedicalViews\CtSliceView.axaml.cs">
          <DependentUpon>CtSliceView.axaml</DependentUpon>
          <SubType>Code</SubType>
        </Compile>
        <Compile Update="Shared\MedicalViews\VtkImageView.axaml.cs">
          <DependentUpon>VtkImageView.axaml</DependentUpon>
          <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\Evaluation\ApprovePlanDialogView.axaml.cs">
          <DependentUpon>ApprovePlanDialogView.axaml</DependentUpon>
          <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\DataImport\CopyFileDialogView.axaml.cs">
          <DependentUpon>CopyFileDialogView.axaml</DependentUpon>
          <SubType>Code</SubType>
        </Compile>
        <Compile Update="Pages\DataImport\ImportDataFromExternalDialogView.axaml.cs">
          <DependentUpon>ImportDataFromExternalDialogView.axaml</DependentUpon>
          <SubType>Code</SubType>
        </Compile>
        <Compile Update="Shell\Dialogs\UserManagement\AdminUserMangementDialogView.axaml.cs">
            <DependentUpon>AdminUserMangementDialogView.axaml</DependentUpon>
            <SubType>Code</SubType>
        </Compile>
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Update="Resources.resx">
            <Generator>PublicResXFileCodeGenerator</Generator>
            <LastGenOutput>Resources.Designer.cs</LastGenOutput>
        </EmbeddedResource>
    </ItemGroup>

    <ItemGroup>
        <None Update="nlog.config">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\Application1.ModelMock\Application1.ModelMock.csproj" />
        <ProjectReference Include="..\Application1.UiTheme\Application1.UiTheme.csproj" />
    </ItemGroup>

    <ItemGroup>
        <None Remove="appsettings.json" />
        <Content Include="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <None Remove="Data\help.pdf" />
        <Content Include="Data\help.pdf">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

    <ItemGroup>
      <UpToDateCheckInput Remove="Shared\Controls\Histogram\HistogramEditor.axaml" />
    </ItemGroup>

    <ItemGroup>
      <AdditionalFiles Include="Pages\Segmentation\Histogram\HistogramEditor.axaml" />
    </ItemGroup>
</Project>

To Reproduce

  1. Publish upgraded app from 11.0.11 to 11.1.3 by updating avalonia nuget packages
  2. publish for windows

Expected behavior

App runs and does not embed resources twice, so that published apps can be used again.

Avalonia version

11.1.3

OS

Windows

Additional context

I have debugged it from sources and I can really see that the resource named is embedded twice in the binary stream.

I have already performed the following changes with in between removed obj folders to ensure proper rebuild:

  1. Remove trimming from project file and nuke build
  2. remove <AvaloniaResource Include="Assets\**" /> from project, which changes the error to that the Resource app is not found any more and it should have an x:class or defined as avaloniaResource, which is weird because the app.xaml is not in the folder.

I am looking forward for some hints what I can do instead of just tinkering around and hoping that it works again.

@kebox7
Copy link

kebox7 commented Aug 28, 2024

Hi, @peter-friedland-t2i.

Try adding the following to your project file. Maybe it will help.

<PropertyGroup>
  <AvaloniaIncludeApplicationIconAsWindowIcon>false</AvaloniaIncludeApplicationIconAsWindowIcon>
</PropertyGroup>

@peter-friedland-t2i
Copy link
Author

Hi, @peter-friedland-t2i.

Try adding the following to your project file. Maybe it will help.

<PropertyGroup>
  <AvaloniaIncludeApplicationIconAsWindowIcon>false</AvaloniaIncludeApplicationIconAsWindowIcon>
</PropertyGroup>

thank you for your help. I give it a try but I am not really sure that this will help guess you have been misslead by the name: Icons.axaml. its a resource dictionary containing geometrydrawings.

@kebox7
Copy link

kebox7 commented Aug 28, 2024

I am not really sure that this will help guess you have been misslead by the name:

Yes indeed, I was mistaken. I apologize. 😳

@AvaloniaUI AvaloniaUI deleted a comment Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
@peter-friedland-t2i @kebox7 and others