microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.84k stars 320 forks source link

The "ExpandPriContent" task failed unexpectedly. Cannot access a disposed object. #2895

Closed dotMorten closed 5 months ago

dotMorten commented 2 years ago

Describe the bug

I'm often experiencing the following bug when compiling. Usually it works, but once hitting this, I have to restart Visual Studio. Looks to be a failure in the telemetry code, preventing me from compiling. I don't have a consistent repro, but have observed it with both v1.0.0 and v1.1.4:

1>------ Build started: Project: Toolkit.SampleApp.Maui, Configuration: Debug Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018: The "ExpandPriContent" task failed unexpectedly.
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018: System.ObjectDisposedException: Cannot access a disposed object.
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018: Object name: 'it is not allowed to use disposed Microsoft.VisualStudio.Telemetry.TelemetrySession object.'.
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.VisualStudio.Telemetry.TelemetryDisposableObject.RequiresNotDisposed()
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.VisualStudio.Telemetry.TelemetrySession.SerializeSettings()
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.Build.AppxPackage.Telemetry.Get(IBuildEngine4 buildEngine, String vsTelemetrySession)
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.Build.AppxPackage.AppxPackagingTaskHelper..ctor(IBuildEngine4 buildEngine, TaskLoggingHelper logger, Action execute, Func`2 exceptionHandler, Action cleanup, Func`1 manifestFileNameGetter, String vsTelemetrySession)
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.Build.AppxPackage.AppxPackagingToolTaskBase.Execute()
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Users\mort5161\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\MrtCore.PriGen.targets(891,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "Esri.ArcGISRuntime.Toolkit.WinUI.csproj" -- FAILED.

Steps to reproduce the bug

No specific repro. Happens after building a maui app over and over. I've observed it on two different PCs, one running Win10 and the other Win11. VS version was 17.3.1 on both.

Expected behavior

No response

Screenshots

No response

NuGet package version

1.1.4

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 21H2 (22000)

IDE

Visual Studio 2022

Additional context

Visual Studio 17.3.1. Looks very similar to Xamarin telemetry issue (that was supposed to be fixed in 17.3.1 but I'm still occasionally observing that one too). See https://developercommunity.visualstudio.com/t/Unexpecter-error-of-task-Xamarin-Teleme/10096527

bmacombe commented 2 years ago

Had a similar error today building an Xamarin Forms UWP app with VS 17.3.4 I think. Updating to 17.3.5 fixed, but it seemed random.

2022-09-29T17:23:41.5430851Z ##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\Microsoft.AppXPackage.Targets(1718,5): Error MSB4018: The "ExpandPriContent" task failed unexpectedly.
System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
   at Microsoft.Build.Packaging.Pri.Tasks.ExpandPriContent.ExecuteImplementation()
   at Microsoft.Build.AppxPackage.AppxPackagingToolTaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
LadderLogic commented 1 year ago

@rohanp-msft is there a known workaround for this without having to restart the VS? Is there anything we could help with to resolve this issue? Happens quite frequently when there is a change in xaml files.

rohanp-msft commented 1 year ago

@LadderLogic AFAIK, there isn't another workaround (rebuilding the solution might be one, though that's just as bad). This was postponed due to some higher priority work. I will be able to look at this in a week's time. We apologize for the delay.

rohanp-msft commented 1 year ago

@LadderLogic Hi Nanda, do you have a repro of this?

rohanp-msft commented 1 year ago

Had a similar error today building an Xamarin Forms UWP app with VS 17.3.4 I think. Updating to 17.3.5 fixed, but it seemed random.

2022-09-29T17:23:41.5430851Z ##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\Microsoft.AppXPackage.Targets(1718,5): Error MSB4018: The "ExpandPriContent" task failed unexpectedly.
System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
   at Microsoft.Build.Packaging.Pri.Tasks.ExpandPriContent.ExecuteImplementation()
   at Microsoft.Build.AppxPackage.AppxPackagingToolTaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

This is unrelated other than this exception also occurs in the same task. Somehow, the PRI XML dump was invalid here. Anyway, it looks like the problem is gone for you after the upgrade.

LadderLogic commented 1 year ago

@LadderLogic Hi Nanda, do you have a repro of this?

@rohanp-msft, it's part of a large solution with multiple projects referencing the same xaml control library, but I'll try to make a small repo soon.

rohanp-msft commented 1 year ago

Since there haven't been any recent reports of this issue, we expect this is addressed by an update to VS. I am closing this issue. If it is reported again on latest VS, etc., we will revisit it.

ADD-David-Antolin commented 1 year ago

Yes, it is still happening in Visual Studio 2022 17.5.0 and WindowsAppsSDK 1.2.221109.1.

rohanp-msft commented 1 year ago

Changing Assignee per ownership change. Will let Robert @robertzhou-wpn follow-up as needed.

jmeyerworms commented 1 year ago

hello, i got the same error currently.

Projekt is a Xamarin Forms projekt, when Building the UWP Projekt i get the error.

visual studio community 17.5.1

Name Microsoft.WindowsAppRuntime.1.1 Version : 1005.616.1651.0

No WindowsAppSDK version installed.

Betriebsystemname Microsoft Windows 11 Pro Version 10.0.22621 Build 22621 Systemtyp x64-basierter PC

Error: grafik

soroshsabz commented 1 year ago

ITNOA

@rohanp-msft please reopen this issue

I do not think this issue is resolved

rohanp-msft commented 1 year ago

ITNOA

@rohanp-msft please reopen this issue

I do not think this issue is resolved

@soroshsabz The owners have changed (see the current Assignees of this issue). I notified them when you commented. @loneursid can provide the triage results.

Scottj1s commented 10 months ago

FYI - this seems to have helped others with the System.ObjectDisposedException: for VS builds: >set MSBUILDDISABLENODEREUSE=1 for MSBuilds: (above) or >msbuild /nodeReuse:false ...

DominikErnst commented 9 months ago

Same here! Solutions?

Scottj1s commented 7 months ago

We have root caused this issue to a bug in the MSIX packaging support logic in Windows App SDK and will have a fix available soon. There is no workaround.

timmarriott commented 6 months ago

I see the issue once in a while when building Windows Runtime Components which are C++ WinUI3 Desktop type components. I am using the latest everything VS2022 17.96, Latest Windows App SDK etc. When it happens it is after working for a while and normally a clean rebuild works to resolve but more recently that is failing. This is starting to become a productivity issue.

2>AccessServerWRC.vcxproj -> C:\Users\tim\Source\Repos\PDFAlign\x64\Debug\AccessServerWRC\AccessServerWRC.dll 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: The "ExpandPriContent" task failed unexpectedly. 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: System.ObjectDisposedException: Cannot access a disposed object. 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: Object name: 'it is not allowed to use disposed Microsoft.VisualStudio.Telemetry.TelemetrySession object.'. 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.VisualStudio.Telemetry.TelemetryDisposableObject.RequiresNotDisposed() 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.VisualStudio.Telemetry.TelemetrySession.SerializeSettings() 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.Build.AppxPackage.Telemetry.Get(IBuildEngine4 buildEngine, String vsTelemetrySession) 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.Build.AppxPackage.AppxPackagingTaskHelper..ctor(IBuildEngine4 buildEngine, TaskLoggingHelper logger, Action execute, Func2 exceptionHandler, Action cleanup, Func1 manifestFileNameGetter, String vsTelemetrySession) 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.Build.AppxPackage.AppxPackagingToolTaskBase.Execute() 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 2>C:\Users\tim\Source\Repos\Packages_nuget\Microsoft.WindowsAppSDK.1.5.240404000\build\MrtCore.PriGen.targets(913,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() 2>Done building project "AccessServerWRC.vcxproj" -- FAILED.

timmarriott commented 6 months ago

I have a suspicion that files might get left open which also may be why Clean fails once in a while. Which also may be why closing VS and opening again solves the issue.

Scottj1s commented 6 months ago

Here's an explanation of the fix (thanks, @evelynwu-msft), which will be available in WinAppSDK 1.6:

The Single-project MSIX Packaging build tasks were, by default, directly using VS's default telemetry session. After they finished running, they would dispose this default session. Later, if some other build task in the same MSBuild process accessed the now-disposed default session, an exception would be raised.