Bug 61108 - Xamarin Android CI build fails on TFS
Summary: Xamarin Android CI build fails on TFS
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 8.1 (15.5)
Hardware: PC Windows
: --- major
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2017-12-15 13:56 UTC by Alex
Modified: 2018-02-08 12:47 UTC (History)
12 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro project and log (100.48 KB, application/x-zip-compressed)
2017-12-22 10:32 UTC, Alex
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alex 2017-12-15 13:56:03 UTC
# Steps to reproduce
1. Create a Xamarin.Forms solution
2. Create some project libraries and reference them into the portable Xamarin project.
3. Create an Android build definition in TFS
4. Queue the build

# Expected behavior
The build should be sucessfull

# Actual behavior
The build fails. The IncrementalClean process delete dlls that are need for the Android build.
Please note the build process works on the build machine with Visual Studio and msbuild.exe
Downgrade Xamarin 4.8.0.754 to 4.7.10.22 fixed the problem.  4.8.0.752 produce the same issue.
I found another guy with the same issue: https://developercommunity.visualstudio.com/content/problem/161766/xamarin-android-ci-build-fails-with-invalidoperati.html

# Supplemental info (logs, images, videos)
2017-12-15T11:20:39.6103809Z IncrementalClean
2017-12-15T11:20:39.6103809Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference1.dll".
2017-12-15T11:20:39.6113592Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference2.dll".
2017-12-15T11:20:39.6123342Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference3.dll".
2017-12-15T11:20:39.6123342Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference4.dll".
2017-12-15T11:20:39.6133145Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\GalaSoft.MvvmLight.Extras.dll".
2017-12-15T11:20:39.6133145Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\Microsoft.Practices.ServiceLocation.dll".
2017-12-15T11:20:39.6142908Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference5.dll".
2017-12-15T11:20:39.6142908Z   Deleting file "c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\GalaSoft.MvvmLight.dll".
2017-12-15T11:20:39.6885860Z ##[error]C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1500,2): Error : Exception while loading assemblies: System.InvalidOperationException: Failed to load assembly c:\agent\_work\4\b\Project.Droid\bin\UITests-Android\ProjectReference1.dll

# Test environment (full version information)
TFS 15.117.26714.0
Xamarin 4.8.0.754
VS 2015 Update 3
TFS Build Agent.Version 2.117.2
Comment 1 Michael Rumpler 2017-12-19 14:39:49 UTC
I also have exactly the same problem. 
I'm trying to build my Android project on a custom build agent in VSTS. I updated the custom build agent to
VS2017 prof. 15.5.2
Xamarin 4.8.0.753
Android SDK Build Tools 27.0.2

The log displays these messages:
IncrementalClean:
  Deleting file "C:\agent\_work\2\b\Release\RoyalCommon.Document.RoyalDocument.PCL.dll".
  Deleting file "C:\agent\_work\2\b\Release\RoyalCommon.Logging.RoyalLogging.PCL.dll".
  Deleting file "C:\agent\_work\2\b\Release\RoyalDocument.SecurityInterface.Android.dll".
  Deleting file "C:\agent\_work\2\b\Release\RoyalDocument.SecurityInterfaceLegacy.Android.dll".
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1500,2): Error : Exception while loading assemblies: System.InvalidOperationException: Failed to load assembly C:\agent\_work\2\b\Release\RoyalCommon.Document.RoyalDocument.PCL.dll

As you can see, the missing file is the first file it deleted only a couple of lines above.

It's strange that Xamarin.Android.Common.targets(1500,2) is not about IncrementalClean at all.

<Target Name="_ResolveAssemblies">
	<!--- Remove the ImplicitlyExpandDesignTimeFacades assemblies. We have already build the app there are not required for packaging  -->
	<ItemGroup>
		<FilteredAssemblies Include="$(OutDir)$(TargetFileName)"
				Condition="Exists ('$(OutDir)$(TargetFileName)')" />
		<FilteredAssemblies Include="%(ReferenceCopyLocalPaths.Identity)"
				Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.RelativeDir)' == '' "/>
		<FilteredAssemblies Include="%(ReferencePath.Identity)"
				Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' "/>
	</ItemGroup>
	<!-- Find all the assemblies this app requires -->
	<ResolveAssemblies
		Assemblies="@(FilteredAssemblies)"
		I18nAssemblies="$(MandroidI18n)"
		LinkMode="$(AndroidLinkMode)"
		ReferenceAssembliesDirectory="$(TargetFrameworkDirectory)">
      <Output TaskParameter="ResolvedAssemblies" ItemName="ResolvedAssemblies" />
      <Output TaskParameter="ResolvedUserAssemblies" ItemName="ResolvedUserAssemblies" />
      <Output TaskParameter="ResolvedFrameworkAssemblies" ItemName="ResolvedFrameworkAssemblies" />
      <Output TaskParameter="ResolvedSymbols" ItemName="ResolvedSymbols" />
      <Output TaskParameter="ResolvedDoNotPackageAttributes" ItemName="_ResolvedDoNotPackageAttributes" />
  </ResolveAssemblies>
</Target>

Line 1500 is the one with "<ResolveAssemblies" and there is no "IncrementalClean" task in that file.
Comment 2 Jon Douglas [MSFT] 2017-12-20 20:30:22 UTC
Can anyone attached to this bug report please include a reproduction project that will reproduce this behavior on VSTS or locally?

Just to clarify the reproduction step:

2. Create some project libraries and reference them into the portable Xamarin project.

Is this referring to Legacy Class Libraries(PCL) or .NET Standard Class Libraries being referenced?

These details will help me confirm this bug and understand what's going on.

Cross referencing the developer community issue here as well:

https://developercommunity.visualstudio.com/content/problem/161766/xamarin-android-ci-build-fails-with-invalidoperati.html
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-20 20:32:37 UTC
## Cross-referencing note for the Xamarin team

Perhaps related to Bug 60880, and possibly fixed in the upcoming Xamarin 15.6 Previews by the same fix?
Comment 4 Alex 2017-12-22 10:32:39 UTC
Created attachment 26048 [details]
Repro project and log

IncrementalClean process delete ClassLibrary.dll in the output folder.

The issue occurs when a PCL project reference another PCL.
In this repro project:
BuildFails.csproj
   >>>> ClassLibrary.csproj
      >>>> ClassLibrary2.csproj
Comment 5 Michael Rumpler 2017-12-22 10:39:28 UTC
Alex, please change the state back to NEW or Xamarin won't look at this ticket again.
Comment 6 Alex 2017-12-22 10:54:36 UTC
Done. Thanks for the hint Michael
Comment 7 Alex 2018-01-16 11:11:26 UTC
The issue still occurs with latest Xamarin version 4.8.0.757
Any news about this bug?
Comment 8 FieldstrikeMobile 2018-01-26 12:04:21 UTC
also seeing this issue. using VS15.5.5. Dont know if its related to this: https://github.com/xamarin/xamarin-android/issues/1182#issuecomment-359973560
Comment 9 FieldstrikeMobile 2018-01-26 12:05:11 UTC
PS. I would say this bug is CRITICAL. It breaks my build which in term means it breaks my release cycle meaning no new updates on Android
Comment 10 alex@agileapp.co 2018-01-31 10:04:06 UTC
Any news on this issue? Builds have just stopped working! I have Xamarin.Forms 2.5.0.122203 which is showing as the latest stable version, and there are no pre-releases available. Anyone find a workaround?
Comment 11 dean.ellis 2018-01-31 12:11:45 UTC
I think this is related to https://github.com/xamarin/xamarin-android/issues/1164.
Comment 12 dean.ellis 2018-01-31 12:31:11 UTC
PR is up https://github.com/xamarin/xamarin-android/pull/1255
Comment 14 Jon Douglas [MSFT] 2018-01-31 21:20:38 UTC
Marking RESOLVED FIXED as per https://bugzilla.xamarin.com/show_bug.cgi?id=61108#c13 this should be available in 15.7 Preview 1. For a workaround, please see the following comment:

https://github.com/xamarin/xamarin-android/issues/1164#issuecomment-362002602
Comment 15 Alex 2018-02-06 15:28:01 UTC
The workaround doesn't work.

Log:
The target "_RegisterAndroidFilesWithFileWrites" listed in a BeforeTargets attribute at "c:\agent\_work\5\s\BuildFails\BuildFails\BuildFails.Android\FixUp.targets (2,29)" does not exist in the project, and will be ignored.

2018-02-06T15:23:15.4010980Z IncrementalClean:
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\BuildFails.Android.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\BuildFails.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\FormsViewGroup.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\Xamarin.Forms.Core.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\Xamarin.Forms.Platform.Android.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\Xamarin.Forms.Xaml.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\ClassLibrary.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "obj\Release\linksrc\ClassLibrary2.dll.mdb".
2018-02-06T15:23:15.4010980Z   Deleting file "c:\agent\_work\5\b\Release\ClassLibrary.dll".
2018-02-06T15:23:15.4010980Z   Deleting file "c:\agent\_work\5\b\Release\ClassLibrary2.dll".
2018-02-06T15:23:15.5104791Z ##[error]C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1500,2): Error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'ClassLibrary.dll'

Could you please try your workaround in the repro project attached in this ticket?
Comment 16 dean.ellis 2018-02-06 15:53:55 UTC
Alex

Weird the "_RegisterAndroidFilesWithFileWrites" does not exist.. it must be an old version of Xamarin.Android on TFS which does not have that target....

You can try changing the BeforeTargets value in the FixUp.targets to 

    BeforeTargets="IncrementalClean"

and see if that helps.
Comment 17 Alex 2018-02-07 09:03:41 UTC
Thanks a lot. It works!
Comment 18 Eric 2018-02-08 12:47:16 UTC
Thanks for your support. The mentioned workaround 
https://github.com/xamarin/xamarin-android/issues/1164#issuecomment-362002602
does its job . I am able to build again in VSTS.