Kristoffer Hove
Kristoffer Hove

Reputation: 46

The "LinkAssemblies" task failed unexpectedly - SB4018: System.IO.FileNotFoundException

Last week I quite suddenly got this error while building Xamarin.Android for release. Last time I built the project for release everything worked fine.

The projects builds when I choose to link no assemblies, but when I use “Link SDK assemblies only” it fails. And it fails across every branch I have. I have tried to build my master-branch that has not changed since before last time i worked, and that also fails now.

I have also tried to delete bin & obj and checked Android versions and that packages match

Visual Studio is updated, and also have re-installed it, also re-installed Xamarin and Android SDK.

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2145,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamrin.Android.Common.targets(2145,5): error MSB4018: System.IO.FileNotFoundException: Could not load assembly ‘ProjectName.Droid, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?

Upvotes: 2

Views: 373

Answers (2)

Kristoffer Hove
Kristoffer Hove

Reputation: 46

The solution was to remove <RunCodeAnalysis>true</RunCodeAnalysis> from the android.csproj-file. The problem was that the linker tried linkage before the packages got prepared for linking.

Upvotes: 0

Hennadii Sakhniuk
Hennadii Sakhniuk

Reputation: 45

Update

I've got an answer from a Xamarin.Android contributor who explained what has happened to the build process. The "SignAndroidPackage" MSBuild target no longer depends on the "Build" target so, I think, it implicates if an Android project has "DefaultTargets" set to only "SignAndroidPackage" then this target won't be able to find the project compiled DLL since it was not built. Thus I assume that this is why we have "LinkAssemblies" task failed.

To resolve the error I've added the "Build" target just before "SignAndroidPackage".enter image description here

Old comment

I've faced the same error in my project after migrating to Visual Studio 2019. Everything is fine in Visual Studio 2017 and Visual Studio for Mac. Thus I presumed that it might be a bug and raised an issue on GitHub.

We may both follow it here: https://github.com/xamarin/xamarin-android/issues/3715

Upvotes: 2

Related Questions