Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Hot Reload] ENC0003: Updating 'attribute' requires restarting the application caused by AssemblyInformationalVersionAttribute #36666

@jeromelaban

Description

@jeromelaban

Describe the bug

During Hot Reload, with .NET 7 or .NET 8, building WPF (or Uno Platform) app and hot reloading it in VS 2022 (17.7 or 17.8) can produce the following error:

MyApp.AssemlyInfo.cs (line 17): error ENC0003: Updating 'attribute' requires restarting the application.

Where the generated file is

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
using System;
using System.Reflection;
 
[assembly: System.Reflection.AssemblyCompanyAttribute("test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("test")]
[assembly: System.Reflection.AssemblyTitleAttribute("test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

Line 17 being:

[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]

Having tried to debug this issue, if feels like the Roslyn HotReload workspace is, for some reason, generating a AssemblyInformationalVersionAttribute sometimes:

var project = await _workspace.OpenProjectAsync(context.FileSet.Project.ProjectPath, cancellationToken: cancellationToken);

but since there's no way to get binlogs for the workspace's solution load, it's difficult to troubleshoot why the original value and the hotreloaded values may be different.

To Reproduce

The part being unclear is the set of conditions for this to happen, but here's a summary:

  1. Create a WPF app
  2. Hot reload it
  3. Stop the hot reload completely by stopping the app
  4. Start the hot reload session again

Workaround

Disabling assemblyversion generation helps:

<GenerateAssemblyInfo Condition="'$(Configuration)'=='Debug'">false</GenerateAssemblyInfo>

But can cause CA1416 to appear. Disabling AssemblyFileVersionAttribute and AssemblyInformationalVersionAttribute can also help as more precise:

Further technical details

Versions

  • .NET 7.0.403 or .NET 8.0.100 RC2
  • VS 17.7.6 or VS 17.8 Preview 6

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions