Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraneous "The "FilterAssemblies" task failed unexpectedly" error appears for builds inside Visual Studio if an app references a .NET Standard library that did not build successfully #3423

Closed
brendanzagaeski opened this issue Aug 1, 2019 · 23 comments
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@brendanzagaeski
Copy link
Contributor

This is a possible area for follow-up related to #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.

Steps to reproduce

Build the attached test case within Visual Studio 2019 version 16.2 or higher.

Test case: FilterAssembliesAfterError.zip

Expected behavior

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.

  • Or the build proceeds all the way to the 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.

Actual behavior

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]

Log file

MSBuildBinlogs.zip

@brendanzagaeski brendanzagaeski added the Area: App+Library Build Issues when building Library projects or Application projects. label Aug 1, 2019
@brendanzagaeski brendanzagaeski added this to the Under Consideration milestone Aug 1, 2019
@EmilAlipiev
Copy link

EmilAlipiev commented Aug 4, 2019

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

@Im-PJ
Copy link

Im-PJ commented Aug 12, 2019

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.

@brendanzagaeski
Copy link
Contributor Author

@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 #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!

@Im-PJ
Copy link

Im-PJ commented Aug 12, 2019

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.

@brendanzagaeski
Copy link
Contributor Author

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

@danhermes
Copy link

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.

@mshwf
Copy link

mshwf commented Aug 28, 2019

This happened with me after upgrading from X.F 3.6 to X.F 4.2

@devopsoftware
Copy link

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.

@Sumit2668
Copy link

I am also getting this happened with me after upgrading from X.F 2.5 to X.F 4.2, what I do ??

@moniquealtero
Copy link

moniquealtero commented Oct 14, 2019

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.

@brendanzagaeski
Copy link
Contributor Author

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

@brendanzagaeski
Copy link
Contributor Author

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
Copy link

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

Thank you, I'll try this steps.

@lesterbotello
Copy link

lesterbotello commented Oct 16, 2019

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 

@moniquealtero
Copy link

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.

Screenshot_3

@brendanzagaeski
Copy link
Contributor Author

Cross-referencing notes for the team

The behavior of this scenario is improved in Visual Studio 2019 version 16.4 Preview by #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 #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.

@brendanzagaeski
Copy link
Contributor Author

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.

@MehdiJafari84
Copy link

Hi Mr Brendan Zagaeski
I have this issue too.
I'm waiting for the release for mac. When will it come?

@MehdiJafari84
Copy link

MehdiJafari84 commented Dec 8, 2019

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?

@brendanzagaeski
Copy link
Contributor Author

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!

@brendanzagaeski
Copy link
Contributor Author

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

@brendanzagaeski
Copy link
Contributor Author

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

@brendanzagaeski
Copy link
Contributor Author

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/.)

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

10 participants