This is a possible area for follow-up related to https://github.com/xamarin/xamarin-android/pull/2795.
In my testing so far, this only seemed to affect builds that happened within Visual Studio. Command line builds aborted after they hit the error in the .NET Standard library, so they didn't attempt to run any targets in the Android app project.
Build the attached test case within Visual Studio 2019 version 16.2 or higher.
Test case: FilterAssembliesAfterError.zip
One of the following:
The Android app build aborts with no errors.
This is what now happens in Visual Studio 2019 version 16.2 if there are syntax errors in a referenced Android library project (in contrast to a .NET Standard library project). This has a nice consequence that only the errors from the Android class library project appear in the Error List.
CoreCompile target so that csc emits an error.This is what happens for a .NET Core app that references a .NET Standard library that contains syntax errors.
Or, if neither of those options is easy to do, maybe the build could fail with the old LinkAssemblies task error or ResolveLibraryProjectsImport task error for this particular scenario. That way, the error message would at least be familiar for existing users.
The app project emits an extraneous build error that is also unfamiliar because it did not exist in previous versions of Xamarin.Android:
error MSB4018: The "FilterAssemblies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'C:\Temp\FilterAssembliesAfterError\NetStandardLibrary1\bin\Debug\netstandard2.0\NetStandardLibrary1.dll'.
File name: 'C:\Temp\FilterAssembliesAfterError\NetStandardLibrary1\bin\Debug\netstandard2.0\NetStandardLibrary1.dll'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Xamarin.Android.Tasks.FilterAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\FilterAssembliesAfterError\AndroidApp1\AndroidApp1.csproj]
thats exactly what i was getting on windows. thanks for detailing this bug. I hope that it will be solved in next release as soon as possible
I'm also getting this error in Xamarin Forms App on VS 16.2.1 and Xamarin Android 9.4.1.0
Can anyone share a workaround please. My project work has been stalled due to this.
@Im-PJ , for the scenario described in this particular issue, if you are getting the same call stack shown in the description that says "Could not find file," that means that one of the projects referenced by your Android application project failed to build due to another error. To resolve the problem, you'll want to look at the other errors in Error List window and resolve those.
If you are seeing an error that is similar to the one shown in the description but without any additional errors from other projects, that would be a separate problem. One possibility could the slightly different error shown in https://github.com/xamarin/xamarin-android/pull/3379. If that issue also does not match the behavior you are seeing, then if you could submit a new issue with the full text of the error you are seeing, plus the saved diagnostic MSBuild output or a zipped up test case that demonstrates the issue, that would be perfect. Thanks in advance!
Thanks for explaining. Yes I'm getting "Could not find file" error as described in this issue. My android project only references portable .net standard project. I removed all nugets, cleaned solution but still it doesn't build. Im not getting any other error that can help me identify the issue.
May I know why this is happening. Everything was working fine with my project and all of sudden this comes up. Is it because of latest VS update? If so, is there any way to downgrade it.
@Im-PJ , I'm not sure what circumstances would be most likely to produce this error if it is not accompanied by other errors. If you could submit a new issue with the full text of the error you are seeing, plus the saved diagnostic MSBuild output or a zipped up test case that demonstrates the issue so the team can investigate further, that would be perfect. Thanks in advance!
Look at the dll listed in the error (NetStandardLibrary1 above) then check references in folders of projects that might cite it. I found it eventually that way. A vague error message but it meant what it said.
This happened with me after upgrading from X.F 3.6 to X.F 4.2
I was getting the same error but i am not sure directly connected with the same problem of yours but just for the info. Someone said that this problem may arise when you try to read a file that does not exist. And when i checked my codes i saw that a TargetType property of style was assigned to a missing class in Xaml. After i removed that property error has gone. Correct error details was not shown in the error list.
I am also getting this happened with me after upgrading from X.F 2.5 to X.F 4.2, what I do ??
When run my app in debug mode it deploy successfully but when in realease mode I have this error and app cannot deploy. Anyone know how to solve this yet?
MSB4018: The "LinkAssemblies" task failed unexpectedly.
Mono.Linker.MarkException: Error processing method: 'System.Void Unio.App.Forms.Droid.Resource::UpdateIdValues()' in assembly: 'Unio.App.Forms.Droid.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Int32 MvvmCross.Droid.Support.Design.Resource/Animation::tooltip_enter
at Mono.Linker.Steps.MarkStep.HandleUnresolvedField(FieldReference reference)
at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Done building project "Unio.App.Forms.Droid.csproj" -- FAILED.
@moniquealtero, what you're seeing is a bit different.
This issue is about the scenario where the "LinkAssemblies" error appears together with a FileNotFoundException, like:
System.IO.FileNotFoundException: Could not find file 'C:\Temp\FilterAssembliesAfterError\NetStandardLibrary1\bin\Debug\netstandard2.0\NetStandardLibrary1.dll'.
What you're seeing is that the linker is finding all of the assemblies, but it's not able to resolve one of the types within one of the assemblies:
Mono.Linker.MarkException: Error processing method: 'System.Void Unio.App.Forms.Droid.Resource::UpdateIdValues()' in assembly: 'Unio.App.Forms.Droid.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Int32 MvvmCross.Droid.Support.Design.Resource/Animation::tooltip_enter
One common cause of resolution errors like that is if some NuGet packages referenced by the project are out-of-date. If updating the NuGet packages doesn't help, and you get stuck on that error, please do submit a new issue to describe your scenario so the team can take a look. Thanks in advance!
As a clarification in case it might help for other users who come across this issue, this particular issue is only about changing the wording of the error message so that it's more familiar. The scenario covered by this particular GitHub issue is that I intentionally made a typo in a .NET Standard library referenced by a Xamarin.Android app. In order to fix that error, I would need to correct the typo I made in my own .NET Standard library project.
As an example of how the wording could be improved in the future, one good option would be for Xamarin.Android projects to produce the same error for this scenario as .NET Core and .NET Framework console apps:
CSC : error CS0006: Metadata file 'C:\Temp\FilterAssembliesAfterError\NetStandardLibrary1\bin\Debug\netstandard2.0\NetStandardLibrary1.dll' could not be found
@moniquealtero, what you're seeing is a bit different.
This issue is about the scenario where the "LinkAssemblies" error appears together with a
FileNotFoundException, like:
System.IO.FileNotFoundException: Could not find file 'C:\Temp\FilterAssembliesAfterError\NetStandardLibrary1\bin\Debug\netstandard2.0\NetStandardLibrary1.dll'.What you're seeing is that the linker is _finding_ all of the assemblies, but it's not able to resolve one of the types _within_ one of the assemblies:
Mono.Linker.MarkException: Error processing method: 'System.Void Unio.App.Forms.Droid.Resource::UpdateIdValues()' in assembly: 'Unio.App.Forms.Droid.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Int32 MvvmCross.Droid.Support.Design.Resource/Animation::tooltip_enterOne common cause of resolution errors like that is if some NuGet packages referenced by the project are out-of-date. If updating the NuGet packages doesn't help, and you get stuck on that error, please do submit a new issue to describe your scenario so the team can take a look. Thanks in advance!
Thank you, I'll try this steps.
Hi all.
I'm getting this too on VS for Mac 8.3.2 after attempting to produce an archive against Target Framework Android 10 (Q). Interestingly enough, our app actually deploys and BUILDS successfully on debug and release modes, so I think this rules out an error with dependencies not building successfully. The error, however, happens when we try to archive the app to produce an APK. The same happens in our CI pipeline while trying to create the binary using App Center against Xamarin.Android 9.4 and above.
path/to/userhome/.nuget/packages/microsoft.bcl.build/1.0.21/build/Microsoft.Bcl.Build.targets(243,5): warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317569.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: The "FilterAssemblies" task failed unexpectedly.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path "/path/to/project/bin/Release/netstandard2.1/MyProject.dll".
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0015e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:223
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:91
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:266
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Xamarin.Android.Tasks.FilterAssemblies.Execute () [0x0006f] in <e6e17f7092ca42eab0f975bb0c6d6c74>:0
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805
Hi all.
I'm getting this too on VS for Mac 8.3.2 after attempting to produce an archive against Target Framework Android 10 (Q). Interestingly enough, our app actually deploys and BUILDS successfully on debug and release modes, so I think this rules out an error with dependencies not building successfully. The error, however, happens when we try to archive the app to produce an APK. The same happens in our CI pipeline while trying to create the binary using App Center against Xamarin.Android 9.4 and above.
path/to/userhome/.nuget/packages/microsoft.bcl.build/1.0.21/build/Microsoft.Bcl.Build.targets(243,5): warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317569. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: The "FilterAssemblies" task failed unexpectedly. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path "/path/to/project/bin/Release/netstandard2.1/MyProject.dll". /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0015e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:223 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:91 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:266 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Xamarin.Android.Tasks.FilterAssemblies.Execute () [0x0006f] in <e6e17f7092ca42eab0f975bb0c6d6c74>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(520,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805
I'm not sure yet but I think that if you updated to Android Q all your nugget packages have to support it and not all of them do this yet.
You can check this in your Nuget Android packages at description section.

Cross-referencing notes for the team
The behavior of this scenario is improved in Visual Studio 2019 version 16.4 Preview by https://github.com/xamarin/xamarin-android/pull/3609. In that version, the error message no longer starts with the misleading mention of FilterAssemblies.
The behavior is fully fixed in the d16-5 development builds by https://github.com/xamarin/xamarin-android/pull/3720. Once the change from that pull request is published, this scenario will produce the standard Metadata file ... could not be found error from the CoreCompile target as seen for other C# project types like .NET Core console apps.
Release status update
A new Preview version has now been published on Windows that includes the fix to produce the standard Metadata file ... could not be found error message for this scenario. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.
The fix is not yet available on macOS. I will update this item again when a Preview version with the fix is available on macOS.
Fix included in Xamarin.Android 10.2.0.16.
Fix included on Windows in Visual Studio 2019 version 16.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.
Fix not yet available on macOS.
Hi Mr Brendan Zagaeski
I have this issue too.
I'm waiting for the release for mac. When will it come?
Hi again. About this issue
(before release for Mac)
I had this problem on Archiving and Release same as this comment
is this way correct? (I'm in hurry! and can't wait for Mac release)
I published PCL project (by right click on PCL) in release mode into the project folder/bin/release/netstandard2.1 then Archiving is ok!
what is your idea about that?
Hi @MehdiJafari84, that sounds interesting, like maybe somehow the current solution configuration might not be building the .NET Standard or PCL project automatically as needed when you build the Android app project that depends on it.
If you get stuck with investigating why the library isn't building when expected, you can submit a new issue with the diagnostic build output for the Android app project or a zipped up test case that demonstrates the issue, and the team can take a look. Thanks in advance!
Release status update
A new Preview version has now been published on macOS that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.
Fix included in Xamarin.Android 10.2.0.84.
Fix included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.
(Fix also included on Windows in Visual Studio 2019 version 16.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.)
Release status update
A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix.
Fix included in Xamarin.Android 10.2.0.100.
Fix included on Windows in Visual Studio 2019 version 16.5. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.
(Fix also included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)
Release status update
A new Release version has now been published on macOS that includes the fix for this item.
Fix included in Xamarin.Android 10.2.0.100.
Fix included on macOS in Visual Studio 2019 for Mac version 8.5. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.
(Fix also included on Windows in Visual Studio 2019 version 16.5 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)
Most helpful comment
Release status update
A new Preview version has now been published on Windows that includes the fix to produce the standard Metadata file ... could not be found error message for this scenario. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.
The fix is not yet available on macOS. I will update this item again when a Preview version with the fix is available on macOS.
Fix included in Xamarin.Android 10.2.0.16.
Fix included on Windows in Visual Studio 2019 version 16.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.
Fix not yet available on macOS.