23

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

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" ?>
<linker>    
    ...    
    <assembly fullname="AppName.Core" ></assembly>        
    ...        
</linker>

At 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: 2.5.0.280555
  • Xamarin Version: 26.1.0.1
Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
Steve
  • 9,335
  • 10
  • 49
  • 81
  • 1
    dit you try removing Multi-dex or/and proguard from your configuration ? Something it not works with different linking other than the default one – OrcusZ Mar 21 '18 at 08:17
  • @OrcusZ we require both Multi-dex and Proguard to be enabled. – Steve Mar 21 '18 at 08:23
  • Can you just try to know if the issue comes from this options or not ? Furthermore the official documentation about linker from MS : https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker – OrcusZ Mar 21 '18 at 09:55
  • @OrcusZ I tried turning off both Proguard and Multidex and got the same result. – Steve Mar 22 '18 at 00:25
  • Maybe the obvious question, but did you report a bug on this yet? Stack Overflow isn't the best place to get **answers about potential bugs**. File a bug in the repository directly. https://github.com/xamarin/xamarin-android/issues/new – Jon Douglas Mar 22 '18 at 02:19
  • @JonDouglas I'm trying to work out if it is a bug first. There doesn't seem to be anything substantially strange about my setup and I can't find anyone else having a similar issue, leading me to think it's something I'm doing. – Steve Mar 22 '18 at 02:23
  • @Steve Based on everything you've written thus far, I would suspect a bug involving a file locking scenario. Definitely would be better filed as a bug to be looked at sooner than later. Also hopefully to not waste anymore of your time in the light it's a bug. – Jon Douglas Mar 22 '18 at 02:31

1 Answers1

1

Please refer this link :

https://forums.xamarin.com/discussion/32976/updating-xamarin-broke-the-build-process-the-process-cannot-access-the-file-appname-dll-mdb

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

  • I specifically link that thread in my question and explained I have already tried those basic steps. – Steve Mar 27 '18 at 11:57