c# – Xamarin Android linking cannot access file-ThrowExceptions

Exception or error:

I have a Xamarin Android project that I am trying to use Sdk and User Assembly linking with.

If I set the Android project to Sdk Assembly Linking only, the APK is created and deployed successfully and works.

However, when I set Sdk and User Assembly linking, with no other changes, I get the following error only when I deploy. The solution builds succesfully.

The "LinkAssemblies" task failed unexpectedly.    
System.IO.IOException: The process cannot access the file '<path-to-project>\AppName\AppName.Android\obj\Release\android\assets\AppName.Core.dll' because it is being used by another process.
    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 Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
    at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory)
    at Mono.Linker.Steps.OutputStep.OutputAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.OutputStep.ProcessAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, 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()

AppName.Core.dll is another library project in my solution that is set to build as NetStandard 2.0.

I have looked through many other bug reports and forum posts regarding a similar issue to this, but most seem related to an earlier bug with Visual Studio 15.5.1 that has since been fixed.

Regardless, I have tried just about every solution suggested in those links including:

  • closing and reopening Visual Studio
  • deleting /bin and /obj folders
  • opening Visual Studio as Administrator
  • running MsBuild from a command prompt with VS closed

As well as various combinations of the above.

My custom linker.xml contains an exception for my library project:

<?xml version="1.0" encoding="utf-8" ?>
    <assembly fullname="AppName.Core" ></assembly>        

As this point I seem to have exhausted all available options and am no closer to a workable solution. Suggestions on solutions, workarounds, or other debugging paths to follow would be most appreciated.

My Android Options config:

Android Options

Version Information:

  • Visual Studio Version: 15.5.6
  • Xamarin Forms Version:
  • Xamarin Version:
How to solve:

Please refer this link :


There are two solutions :

  1. Close Visual Studio
  2. deleting all the files in the bin\Debug folder
  3. delete the .suo file
  4. open Visual Studio in Administrator mode

If you have Xamarin Studio try this :

  1. Open the solution in XamarinStudio and deploy it to the Android phone
  2. Close the XamarinStudio
  3. Open the solution in VisualStudio and deploy it to Android Phone

Hope this helps!!

Leave a Reply

Your email address will not be published. Required fields are marked *