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:
- Create a WPF app
- Hot reload it
- Stop the hot reload completely by stopping the app
- 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:
|
<Target Name="GetAssemblyAttributes" |
Further technical details
Versions
- .NET 7.0.403 or .NET 8.0.100 RC2
- VS 17.7.6 or VS 17.8 Preview 6
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:
Where the generated file is
Line 17 being:
Having tried to debug this issue, if feels like the Roslyn HotReload workspace is, for some reason, generating a
AssemblyInformationalVersionAttributesometimes:sdk/src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs
Line 69 in 6710347
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:
Workaround
Disabling assemblyversion generation helps:
But can cause CA1416 to appear. Disabling
AssemblyFileVersionAttributeandAssemblyInformationalVersionAttributecan also help as more precise:sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.GenerateAssemblyInfo.targets
Line 75 in 6710347
Further technical details
Versions