"The XamarinTelemetry task failed unexpectedly" on second build

Viewed 2915

With the latest VS preview (VS 17.3 Preview 3), with both Android and iOS, building my application works the first time I build it, but the second time it fails with

The "XamarinTelemetry" task failed unexpectedly.

Looking at the logs I see this:

1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: The "XamarinTelemetry" task failed unexpectedly.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: File name: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Microsoft.VisualStudio.Telemetry.TelemetrySessionSettings.GetFaultEventBucketFilterJson(List`1 bucketFilters)
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Microsoft.VisualStudio.Telemetry.TelemetrySessionSettings.ToString()
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Microsoft.VisualStudio.Telemetry.TelemetrySession.SerializeSettings()
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Xamarin.Common.Tasks.Telemetry.GetSession(IBuildEngine4 buildEngine, String vsTelemetrySession) in D:\a\_work\1\s\src\MSBuild\Xamarin.Common.Tasks\Telemetry.cs:line 62
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Xamarin.Common.Tasks.XamarinTelemetry.Execute() in D:\a\_work\1\s\src\MSBuild\Xamarin.Common.Tasks\XamarinTelemetry.cs:line 31
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: 
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: WRN: Assembly binding logging is turned OFF.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: Note: There is some performance penalty associated with assembly bind failure logging.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018: To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Xamarin.Sdk.targets(138,9): error MSB4018:

The only workaround I've found is to clean the entire solution and rebuild, which succeeds, but then fails again the next time I try to build.

Has anyone found a solution to this?

7 Answers

First off, don't shoot the messenger here..

UPDATE: August 16, 2022

According to Visual Studio v17.3.1's Release Notes, this issue has been resolved. However, if not, there's still the following

As per the workaround thread on Visual Studio's dev community thread:

  1. Open, Xamarin.Sdk.targets in Admin Mode (I use, Notepad++)
    • C:\Program Files\Microsoft Visual Studio\2022\Preview\Msbuild\Xamarin\Xamarin.Sdk.targets
  2. Comment out the <XamarinTelemetry ... />
  3. Save file and rebuild the solution.

Though it does work in the interim, please forward your official feedback on the official VS Developer Community thread in the link below.

There are several config files in the VS installation which reference 13.0.0.0

<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />

I replaced these with

<bindingRedirect oldVersion="0.0.0.0-13.0.1.0" newVersion="13.0.1.0" />

and was able to build. It seems that the 13.0.0.0 is not publicly available as nuget package...

In Visual Studio 17.3.0, I right-clicked on the projects and selected "Clean".

Then I tried again to right-click the project and selected "Build" and it worked, the "The XamarinTelemetry task failed unexpectedly" error did not occur.

This is in a solution that contains a .NET Standard 2.0 library that references Xamarin Forms and the project in question is an ASP.NET Core 3.1 API referencing the library.

I experienced this today and all I did was rebuild the solution, clicked the "save all", closed the application and opened it again but it did not work. I rebuilt the project but it did not work either. So again, I just repeat the process by closing the visual studio, rebuild and run 2 times (also I went to the error file just viewed it) and it works fine. I don't know what differences it made but it works when you repeat the process.

Edit: The error is still repeating. I just use the Factory Reset when the error occurs.

I had the exact same issue with my Xamarin forms solution, after upgrading from 17.2 to 17.3. Today I installed 17.3.2. A dozen builds later and it seems that the issue has been addressed.

Xamarin is not meant to be developed in VS 17.3 Preview, as Microsoft plan on replacing it with MAUI, and stopping support for Xamarin (Might not be now with VS 17.3 but it is in the near future). If you don't want to use MAUI then your best option for Xamarin currently is VS 17.2, as it still fully supports Xamarin.

My solution to this problem was installing both VS 17.2 and 17.3 Preview and using them for Xamarin and MAUI respectively.

Related