WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

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

Open dotMorten opened this issue 2 years ago • 18 comments

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

dotMorten avatar Aug 23 '22 19:08 dotMorten

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()

bmacombe avatar Sep 29 '22 17:09 bmacombe

@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.

LadderLogic avatar Nov 11 '22 19:11 LadderLogic

@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 avatar Nov 11 '22 20:11 rohanp-msft

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

rohanp-msft avatar Nov 23 '22 00:11 rohanp-msft

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.

rohanp-msft avatar Nov 23 '22 00:11 rohanp-msft

@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.

LadderLogic avatar Nov 29 '22 23:11 LadderLogic

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.

rohanp-msft avatar Feb 01 '23 00:02 rohanp-msft

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

ADD-David-Antolin avatar Feb 24 '23 14:02 ADD-David-Antolin

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

rohanp-msft avatar Feb 24 '23 18:02 rohanp-msft

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

jmeyerworms avatar Mar 13 '23 17:03 jmeyerworms

ITNOA

@rohanp-msft please reopen this issue

I do not think this issue is resolved

soroshsabz avatar Jul 15 '23 09:07 soroshsabz

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.

rohanp-msft avatar Aug 24 '23 00:08 rohanp-msft

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

Scottj1s avatar Dec 15 '23 19:12 Scottj1s

Same here! Solutions?

DominikErnst avatar Jan 24 '24 16:01 DominikErnst

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.

Scottj1s avatar Mar 14 '24 17:03 Scottj1s

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.<ExecuteInstantiatedTask>d__26.MoveNext() 2>Done building project "AccessServerWRC.vcxproj" -- FAILED.

timmarriott avatar Apr 24 '24 22:04 timmarriott

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.

timmarriott avatar Apr 24 '24 22:04 timmarriott

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.

Scottj1s avatar Apr 25 '24 18:04 Scottj1s