0
votes

I have created a xamarin project. When i build the project i get following error.

Severity Code Description Project File Line Suppression State Error The "XamlCTask" task failed unexpectedly. System.IO.IOException: The process cannot access the file 'D:\my\csharpprojects\sampleXamarin\sampleForm\sampleForm.Android\obj\Debug\81\sampleForm.Android.dll' because it is being used by another process.

Server stack trace: 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.ReadModule(String fileName, ReaderParameters parameters) at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters) at Xamarin.Forms.Build.Tasks.XamlCTask.Execute(IList`1& thrownExceptions) at Xamarin.Forms.Build.Tasks.XamlTask.Execute() at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() iliidit.Android

I tried restarting visual studio. Even tried restarting Windows. But no luck. Not sure why the compiler is unable to access the sampleForm.Android.dll file.

Toolset configuration

  • Microsoft Visual Studio Community 2017 Version 15.9.6 VisualStudio.15.Release/15.9.6+28307.344 Microsoft .NET Framework Version 4.7.03056
  • Xamarin 4.12.3.79 (d15-9@260fa6a34) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
  • Xamarin Designer 4.16.13 (45a16efd4) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
  • Xamarin Templates 1.1.128 (6f5ebb2) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
  • Xamarin.Android SDK 9.1.5.0 (HEAD/4b951a3e7) Xamarin.Android Reference Assemblies and MSBuild support.
  • Xamarin.iOS and Xamarin.Mac SDK 12.2.1.12 (65ec520)
  • Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
1
Have you edited any of the default xaml that was generated? Sometimes it's a syntactical error in your xaml that throws this exception.Stemado

1 Answers

1
votes

What happens during a Xamarin.Forms build, in this case:

  1. Roslyn/Csc compiles your C# code into a .NET assembly
  2. XamlC then compiles your XAML by modifying the assembly after the fact

Some process in the middle opened the file, could it be an antivirus software or Windows Defender? Does adding a Windows Defender exclusion for your project's directory solve the problem? If you just try to build again, does it go away?