Forum Visual Studio

VS 2019 gives error 'Could not load assembly Xamarin.Android.Support.v7.AppCompat'

I am working on a project where I am trying to have a VS Android project access and deploy an AAR that was created in Android Studio. The Android project in the VS solution is able to reference the classes in the AAR (which is attached as a Binding Library type of project), and the entire solution builds with no errors. However, when I try to deploy the solution to an attached Android tablet I get the following error:

MSB4018: The "GenerateJavaStubs" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.v7.AppCompat, Version=, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.Android.Support.v7.AppCompat.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName)
   at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.AddJavaTypes(List`1 javaTypes, TypeDefinition type)
   at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.GetJavaTypes(IEnumerable`1 assemblies, IAssemblyResolver resolver)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

In the VS Android project I have NuGet packages for Xamarin.Androidx.* (including AppCompat and Transition) along with Xamarin.Android.Support.v7.AppCompat. I have also tried adding the v7.AppCompat to the binding library project. In addition, when I look at the output window I see several apparently successful references to the v7.AppCompat package prior to the error.

I am using Visual Studio Professional 2019 and deploying to a Samsung Galaxy S3 tablet which has been upgraded to Android 9. My project is set to target Android 9. (I am deploying to a tablet instead of the emulator because the app is using microphone input, which doesn't appear to be available in the emulator.)

Does anyone have any suggestions for how to solve this error?
Ron L.


  • vitthalpatilvitthalpatil USMember ✭✭

    rlounsbury , Did you find any solution?

  • rlounsburyrlounsbury Member ✭✭

    No, I didn't. We abandoned the attempt.

  • LuhminatorLuhminator USMember ✭✭

    I have the same issue. Is any progress?

  • rlounsburyrlounsbury Member ✭✭

    No, as I said in October, we abandoned the attempt.

  • LuhminatorLuhminator USMember ✭✭

    I "solved" this strange issue by this steps:

    1. remove bin and obj folders
    2. remove ALL nuget packages in problematic project
    3. clean project
    4. close VS and reopen
    5. install xamarin Forms first
    6. add all neceasery packages by the needs
    7. rebuild project

    VS in some cases get the hint with "add missing package reference directly into csproj". But this solution cause next errors with duplicity entries. So i install everyfing by the nuget manager and duplicity entry (Program type already present ...) was missed

    My tip. Install only necessary packages. This error is very weird and i spent a lot of time with this random error. I didn't find the place where was the broken reference defined.

    If anyone has any finding post it for next generation.

Sign In or Register to comment.