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

Open
brendanzagaeski opened this issue Aug 1, 2019 · 15 comments

Comments

@brendanzagaeski
Copy link
Member

@brendanzagaeski brendanzagaeski commented Aug 1, 2019

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

@EmilAlipiev

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@Im-PJ 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

This comment has been minimized.

Copy link
Member Author

@brendanzagaeski brendanzagaeski commented Aug 12, 2019

@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

This comment has been minimized.

Copy link

@Im-PJ 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

This comment has been minimized.

Copy link
Member Author

@brendanzagaeski brendanzagaeski commented Aug 12, 2019

@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

This comment has been minimized.

Copy link

@danhermes danhermes commented Aug 27, 2019

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

This comment has been minimized.

Copy link

@mshwf mshwf commented Aug 28, 2019

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

@devopsoftware

This comment has been minimized.

Copy link

@devopsoftware devopsoftware commented Sep 8, 2019

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

This comment has been minimized.

Copy link

@Sumit2668 Sumit2668 commented Sep 24, 2019

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

@moniquealtero

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member Author

@brendanzagaeski brendanzagaeski commented Oct 14, 2019

@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

This comment has been minimized.

Copy link
Member Author

@brendanzagaeski brendanzagaeski commented Oct 14, 2019

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

This comment has been minimized.

Copy link

@moniquealtero moniquealtero commented Oct 15, 2019

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.