Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android linking cannot access file

Tags:

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.

  • The main Xamarin bug report is: https://bugzilla.xamarin.com/show_bug.cgi?id=56275 but was resolved in VS 15.2.
  • A forum topic (https://forums.xamarin.com/discussion/32976/updating-xamarin-broke-the-build-process-the-process-cannot-access-the-file-appname-dll-mdb) also talks about a similar issue being resolved in VS 15.5.1.
  • Other SO questions refer to older Xamarin or VS versions, or have unacceptable solutions (such as just turning off linking):
    • The Link Assemblies tasks failed unexpectedly Xamarin Forms

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
like image 282
Steve Avatar asked Mar 19 '18 06:03

Steve


1 Answers

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

like image 114
Ashray P. Shetty Avatar answered Sep 27 '22 21:09

Ashray P. Shetty