Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XA0107 Ignoring '' as it is a Reference Assembly #3898

Closed
maratoss opened this issue Nov 11, 2019 · 33 comments
Closed

XA0107 Ignoring '' as it is a Reference Assembly #3898

maratoss opened this issue Nov 11, 2019 · 33 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@maratoss
Copy link

Steps to Reproduce

  1. Create an empty Xamarin.Android app from VisualStudio
  2. Add Quartz nuget v3.0.7 or v3.0.6
  3. Build the project

This is reproduced only on my Teamcity machine.
On my local PC it works well.
And one more strange thing is this warning with no path to file

warning XA0107: Ignoring  as it is a Reference Assembly

I tried to build with VS and with MSBuild same result.
Seems smth wrong with a configuration of my buid machine, but i do not have a clue what need to change to get it worked.

Expected Behavior

Build success

Actual Behavior

Build failed with following errors:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" -t:Rebuild -v:d -restore:true App1.csproj

image

1>------ Rebuild All started: Project: App1, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>  App1 -> C:\repositories\TestApp1\App1\bin\Debug\App1.dll
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): error XA2002: Can not resolve reference: `System.Configuration.ConfigurationManager`, referenced by `Quartz`. Please add a NuGet package or assembly reference for `System.Configuration.ConfigurationManager`, or remove the reference to `Quartz`.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Version Information

Microsoft Visual Studio Community 2019
Version 16.3.8
VisualStudio.16.Release/16.3.8+29503.13
Microsoft .NET Framework
Version 4.7.03062

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA662
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.3.286.43615
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   16.3.286.43615
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.3.286.43615
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.3.286.43615
Azure Functions and Web Jobs Tools

C# Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 - v2.9.20816.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.0.83+gbc8a4b23ec
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.3.7 (9d260c5)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.3.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61908.27190
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.10821.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6   16.3.0-beta.19455.1+0422ff293bb2cc722fe5021b85ef50378a9af823
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.3.0.278 (d16-3@40034cd)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.3.0.256 (remotes/origin/d16-3@8a223bfd7)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.3.565 (27e9746)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.0.6.2 (d16-3/c407838)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: mono/mono/2019-06@476d72b9e32
    Java.Interop: xamarin/java.interop/d16-3@5836f58
    LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
    LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.27.1@8212a2d
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333


Xamarin.iOS and Xamarin.Mac SDK   13.6.0.12 (e3c2b40)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

log.txt

@jpobst jpobst added the Area: App+Library Build Issues when building Library projects or Application projects. label Nov 12, 2019
@jonathanpeppers
Copy link
Member

@maratoss can you attach a diagnostic MSBuild log?

I think -v:d means "detailed" and it's missing some info, try doing either -v:diag or even better use -bl to get a binary log, thanks!

@jonathanpeppers jonathanpeppers added the need-info Issues that need more information from the author. label Nov 12, 2019
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Nov 12, 2019
@maratoss
Copy link
Author

maratoss commented Nov 13, 2019

@jonathanpeppers

log for this cmd:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" -t:Rebuild -v:diag -restore:true App1.csproj -bl > log.txt

logs.zip

@jonathanpeppers
Copy link
Member

So I compared your log:

Adding C:\Users\Administrator\.nuget\packages\quartz\3.0.7\lib\netstandard2.0\Quartz.dll to topAssemblyReferences
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
Adding C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll to topAssemblyReferences

To my log with a File -> New Project:

Adding C:\Users\jopepper\.nuget\packages\quartz\3.0.7\lib\netstandard2.0\Quartz.dll to topAssemblyReferences
Adding C:\Users\jopepper\.nuget\packages\system.configuration.configurationmanager\4.5.0\lib\netstandard2.0\System.Configuration.ConfigurationManager.dll to topAssemblyReferences
Adding C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll to topAssemblyReferences

It looks like your build isn't picking up System.Configuration.ConfigurationManager?

Since, this is only happening on your build server. If you delete your NuGet cache at C:\Users\Administrator\.nuget\packages\ and try again, does the problem go away?

@maratoss
Copy link
Author

It looks like your build isn't picking up System.Configuration.ConfigurationManager?

yes, it cannot pick that depended library for some reason

same problem after:

C:\repositories\TestApp1>dotnet nuget locals --clear all

info : Clearing NuGet HTTP cache: C:\Users\Administrator\AppData\Local\NuGet\v3-cache
info : Clearing NuGet global packages folder: C:\Users\Administrator\.nuget\packages
info : Clearing NuGet Temp cache: C:\Users\Administrator\AppData\Local\Temp\2\NuGetScratch
info : Clearing NuGet plugins cache: C:\Users\Administrator\AppData\Local\NuGet\plugins-cache

then run

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" -t:Rebuild -restore:true App1.csproj

Build FAILED.

"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(ResolveAssemblyReferences target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be res
olved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [C:\repositories\TestApp1\App1\App1.csproj]


"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(_GetPrimaryCpuAbi target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.Debugging.targets(435,2): warning : One or more errors occurred. [C:\repositories\TestApp1\App1\App1.csproj]


"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(_ResolveAssemblies target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): warning XA0107: Ignoring  as it is a Reference Assembly [C:\repositories\TestApp1\App1\App1.csproj]


"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(_ResolveAssemblies target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1824,2): error XA2002: Can not resolve reference: `System.Configuration.ConfigurationManager`, referenced by `Quartz`
. Please add a NuGet package or assembly reference for `System.Configuration.ConfigurationManager`, or remove the reference to `Quartz`. [C:\repositories\TestApp1\App1\App1.csproj]

    6 Warning(s)
    1 Error(s)

Time Elapsed 00:00:16.13

@maratoss
Copy link
Author

@jonathanpeppers btw do you have an idea why the link to the package is missing in that warning?

warning XA0107: Ignoring as it is a Reference Assembly

@jonathanpeppers
Copy link
Member

Is it the same version of Visual Studio (such as VS 2019 16.3.9) on both machines? The version of MSBuild and NuGet could affect this, but it shouldn't matter if you have Enterprise vs Community.

Looking at the code we might need a string.IsNullOrEmpty instead of ??:
https://github.com/xamarin/xamarin-android/blob/ab801ce89b2b43fd0fbc8ced34d1ff1d5e0947ab/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs#L93-L94

But that doesn't explain the problem, it would just fix the warning message.

@maratoss
Copy link
Author

TC machine 16.3.8, local machine 16.3.5

@jonathanpeppers
Copy link
Member

It looks like we already have a fix for the warning: 4d3d650

But this isn't shipping until a future release (16.5 Preview 1). I'll post a link to a build you can try when we have one.

@maratoss
Copy link
Author

okay, thanks

@CSkoubo
Copy link

CSkoubo commented Nov 22, 2019

I am seeing similar issue on our on prem azure devops system. Strangely i can make it work if i use default nuget restore folder. However if i in the Nuget Restore step change the "destination folder" i am no longer able to build, and receive above error and warnings. This happens for multiple references. I will try and make a demo project. However our system is very complex, and i might not be able to do it.

This is on a VS2019 agent only, if i use an Agent with VS17 and VS19 it works fine.

@jonathanpeppers
Copy link
Member

@CSkoubo what are you doing to change the NuGet restore folder? Can you post an example? I can try that.

@pasn
Copy link

pasn commented Dec 11, 2019

I found the minimal example where I can reproduce the problem.

My setup:
V2019 v16.4.0
Xamarin.Android.SDK 10.1.0.30

  1. Create two projects:
  • Xamarin.Android application (let's call it App)
  • .NET Standard 2.0 project (let's call him NS)
  1. Add System.Configuration.Manager 4.7.0 nuget as dependency to NS
  2. Reference NS from App project
  3. Probably you need to use some objects from dependencies to make them affect the build
  4. Run VS2019 Command-Line Prompt
  5. Restore packages to specific directory:
    nuget restore <path-to-App-csproj> -PackagesDirectory packages
  6. Build Android project
    msbuild App\App.csproj

Result:

(...)\Xamarin.Android.Common.targets(1808,2): warning XA0107: Ignoring as it is a Referen
ce Assembly
(same warning 3 more times)
(...)
(...)\Xamarin.Android.Common.targets(1808,2): error XA2002: Can not resolve reference: System.Configuration.ConfigurationManager, referenced by DependencyInNetStandard. Please add a NuGet package or assembly reference for System.Configuration.ConfigurationManager, or remove the reference to DependencyInNetStandard.

I attach my minimal example.
Xamarin.Android.VS2019.zip

@jonathanpeppers
Copy link
Member

@pasn I'm not getting any build warnings, but I have VS 16.4.1 (just came out).

Can you try msbuild .\Android.App.sln /bl? In the current directory there will be a msbuild.binlog file you can zip and upload here.

@pasn
Copy link

pasn commented Dec 11, 2019

Sure. Here you are:
msbuild.binlog.zip

@pasn
Copy link

pasn commented Dec 11, 2019

@jonathanpeppers I reproduced the problem with VS 16.4.1 using exactly the same steps

@jonathanpeppers
Copy link
Member

I see an error in your log:

C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5):
error NETSDK1004: Assets file 'D:\Projects\Playground\Xamarin.Android.VS2019\DependencyInNetStandard\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. 
[D:\Projects\Playground\Xamarin.Android.VS2019\DependencyInNetStandard\DependencyInNetStandard.csproj]

Can you use /restore on the msbuild command, instead of using the nuget command?

If using <PackageReference/> you actually can't use nuget to restore.

@pasn
Copy link

pasn commented Dec 12, 2019

@jonathanpeppers thanks for info, I did not know that nuget.exe does not support Package References. Support for it was added in nuget 4.3.0. I tried to use msbuild /restore instead, but I have the same result. I also checked that after I do it, 'D:\Projects\Playground\Xamarin.Android.VS2019\DependencyInNetStandard\obj\project.assets.json' file is present. Could you re-check my new binary log and maybe try to unzip my example and execute this command on your side:
msbuild /restore /p:RestorePackagesPath=packages Android.App.sln /bl

New binlog:
msbuild.binlog.zip

@jonathanpeppers
Copy link
Member

@pasn on 16.4, I get the blank filename warnings, but we have fixed this warning in 16.5 preview:


"C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\Android.App.sln" (default target) (1:2) ->
"C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\App\App.csproj" (default target) (3:6) ->
(_ResolveAssemblies target) ->
  C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.configuration.configurationmanager\4.7.0\ref\netstandard2.0\System.Configuration.ConfigurationManager.dll : warning XA0107: Ignoring Reference  Assembly `C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.configuration.configurationmanager\4.7.0\ref\netstandard2.0\System.Configuration.ConfigurationManager.dll`. [C:\Users\jopepper\Downlo ads\Xamarin.Android.VS2019\App\App.csproj]
  C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.security.accesscontrol\4.7.0\ref\netstandard2.0\System.Security.AccessControl.dll : warning XA0107: Ignoring Reference Assembly `C:\Users\jope pper\Downloads\Xamarin.Android.VS2019\packages\system.security.accesscontrol\4.7.0\ref\netstandard2.0\System.Security.AccessControl.dll`. [C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\App\App.csproj]         C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.security.permissions\4.7.0\ref\netstandard2.0\System.Security.Permissions.dll : warning XA0107: Ignoring Reference Assembly `C:\Users\jopepper \Downloads\Xamarin.Android.VS2019\packages\system.security.permissions\4.7.0\ref\netstandard2.0\System.Security.Permissions.dll`. [C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\App\App.csproj]
  C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.security.principal.windows\4.7.0\ref\netstandard2.0\System.Security.Principal.Windows.dll : warning XA0107: Ignoring Reference Assembly `C:\Us ers\jopepper\Downloads\Xamarin.Android.VS2019\packages\system.security.principal.windows\4.7.0\ref\netstandard2.0\System.Security.Principal.Windows.dll`. [C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\App\A pp.csproj]


"C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\Android.App.sln" (default target) (1:2) ->
"C:\Users\jopepper\Downloads\Xamarin.Android.VS2019\App\App.csproj" (default target) (3:6) ->
(_ResolveAssemblies target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1815,2): error XA2002: Can not resolve reference: `System.Configuration.ConfigurationManager`,  referenced by `DependencyInNetStandard`. Please add a NuGet package or assembly reference for `System.Configuration.ConfigurationManager`, or remove the reference to `DependencyInNetStandard`. [C:\Users\jopeppe r\Downloads\Xamarin.Android.VS2019\App\App.csproj]

    4 Warning(s)
    1 Error(s)

I added this to App.csproj and it fixed the issue, no warnings/errors now:

<Reference Include="System.Configuration.ConfigurationManager" />

Does that work for you?

In the .NET 5 timeframe, we hope to rework the MSBuild task emitting the warnings/errors here.

@pasn
Copy link

pasn commented Dec 13, 2019

@jonathanpeppers, here are more details about the issue. I expect these two commands both to produce the same result:

  1. msbuild /restore Android.App.sln
    Result: 0 warnings, 0 errors
  2. msbuild /restore /p:RestorePackagesPath=packages Android.App.sln
    Result: 4 warnings, 1 error

For VS2017 both builds would end with success, but not for VS2019.

Broader context is that we have big solution with Android, iOS, .NET Core and .NET Framework applications using a lot of .NET Standard libraries. We are now migrating from VS2017 to VS2019. Xamarin.Android's _ResolveAssemblies task is the only blocker for this migration.

If this issue is not solved, restoring packages to separate path would require testing every time when new package is added/updated/removed. Transitive dependencies resolution (added with Package References) won't be that useful as it was before. I could add missing references to Android project, but I see it as a workaround and not the real solution. Could you check why restoring to separate directory works differently from restoring to the default one?

I provide you with the binlog file for successful build for comparison. The only difference I could see in diagnostics log is that the task producing XA0107 warning for failed build would find the DLL from lib folder instead.

msbuild_restore_to_default.binlog.zip

@jonathanpeppers
Copy link
Member

I could add missing references to Android project, but I see it as a workaround and not the real solution.

Does this actually solve your problem in your real project? It would be adding the one reference in the main app project.

The real solution is to completely remove <ResolveAssemblies/> from Xamarin.Android, but since that could potentially break a lot of projects we are still figuring out how to do it.

Let me know if the workaround works in your real solution or not, thanks!

@bddckr
Copy link

bddckr commented Dec 14, 2019

Same issue here (with Microsoft hosted agents on Azure DevOps).

Our CI pipeline was setting the NuGet package path to have control over it for caching purposes (like documented). We didn't want to cache the existing packages the build agent already comes with, and instead we only want the packages our builds actually require. As such we specified the path instead of using the default one.

As @pasn explained, simply not setting the packages path resolves the issue for us. We've currently turned off the caching anyway, but in the future, we may turn it back on. Then later we may decide to split our solution (.NET Core 3.0+, .NET Standard 2.1+, Xamarin.Android 10.0+) up, so we build and cache the Xamarin.Android projects independently. I'm not looking forward to that pipeline complexity because we also reference our projects from the Xamarin.Android ones...

tl;dr: Using the default NuGet packages path works for us, too.


The reason we're not using the other (potential) workaround mentioned, i.e. adding the package reference to the Xamarin project: We are hitting this issue with at least 3 packages already and do not want to specify transitively needed packages manually this way.

@pasn
Copy link

pasn commented Dec 14, 2019

Does this actually solve your problem in your real project? It would be adding the one reference in the main app project.

We will try it next week. Treat this nuget as an example. We have the same problem with System.IO.Pipelines package and not sure how many more such errors may appear in the rest of our Android apps. Still, Do you know what is the source of different behaviour between these two scenarios?

@pasn
Copy link

pasn commented Dec 17, 2019

Hi @jonathanpeppers. I tried your workaround and added this to App.csproj:
<Reference Include="System.Configuration.ConfigurationManager" />

Unfortunately this has no impact. I tried it on our real solution, but later on also on this min example. My colleague tried it as well and also could not get it to work. We also tried to include nuget package directly in Android project, but it also did not help.

Are you sure that you are building with this command?
msbuild /restore /p:RestorePackagesPath=packages Android.App.sln

The only workaround we know now is to restore to default directory. This is ok on dev machines, but not in our CI. This is because we have multiple agents working on the same machine and many build definitions, so we want to minimize the impact they have on each other.

PS: System.Configuration.ConfigurationManager is not the only package we have problems with. Other examples:

error XA2002: Can not resolve reference: Microsoft.Bcl.AsyncInterfaces, referenced by System.Text.Json. Please add a NuGet package or assembly reference for Microsoft.Bcl.AsyncInterfaces, or remove the reference to System.Text.Json.

error XA2002: Can not resolve reference: System.IO.Pipelines, referenced by Microsoft.AspNetCore.SignalR.Client.Core. Please add a NuGet package or assembly reference for System.IO.Pipelines, or remove the reference to Microsoft.AspNetCore.SignalR.Client.Core.

@grendello grendello removed the need-info Issues that need more information from the author. label Jan 23, 2020
@ToreDemant
Copy link

@jonathanpeppers : is it possible to somehow work around this issue by modifying the in the affected projects after the import of Xamarin targets?

@rneeft
Copy link

rneeft commented Jan 23, 2020

Hi all,

Another package that is giving issues is the Extension framework from the Asp core team. When following the blog post from James Montemagno about using the Asp Core DI framework the build servers (Hosted and private) are unable to build the Android project. It gives the same (kind of) errors:

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1808,2): Error XA2002: Can not resolve reference: Microsoft.Bcl.AsyncInterfaces, referenced by Microsoft.Extensions.Hosting.Abstractions. Please add a NuGet package or assembly reference for Microsoft.Bcl.AsyncInterfaces, or remove the reference to Microsoft.Extensions.Hosting.Abstractions.

Issue on the dotnet extension GitHub page has been opened on: https://github.com/dotnet/extensions/issues/1631

For troubleshooting I've created the a GitHub repo at https://github.com/rneeft/XamarinDotNetCoreIssue

The Android project is building fine on my dev machine but it doesn't build on the build agents.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 24, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
@jonathanpeppers
Copy link
Member

The Android project is building fine on my dev machine but it doesn't build on the build agents.

@rneeft does your local machine have a newer Xamarin.Android than the build agents? That could be the cause.

We are trying to rework this code path that has been around since the beginning of Xamarin.Android (before my time). It will take some time as it is not easy: #4171

If this change breaks existing projects, things will be even more complicated.

@rneeft
Copy link

rneeft commented Jan 25, 2020

@jonathanpeppers I don't think so but to be sure I've setup a new Windows Server 2019 with Visual Studio 2019 and configure it as a build agent. It still gives errors. I've installed the same components as on my local machine. (In the repo https://github.com/rneeft/XamarinDotNetCoreIssue/blob/master/machine/.vsconfig I've push my .vsconfig)

Solution is building fine when cloned on the build server and build via visual studio manually.

Please let me know if I need to do/test something.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 27, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 29, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 29, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

We can also remove:

* Any of the `<PackageReference Include="NuGet.*" />` packages we are
  using.

* `MetadataResolver` class, `NuGetLogger` class

The first issue I found was that we have to include these references
by default:

    Java.Interop;
    Mono.Security;
    System.Net.Http;
    System.ServiceModel.Internals;
    System.Runtime;

`System.dll` references `Mono.Security.dll`. `Mono.Android.dll`
references `System.Net.Http.dll` due to `AndroidClientHandler`.

The dependency tree for `System.ServiceModel.Internals.dll` is
somewhat more convoluted:

    Adding assembly reference for Mono.Android, recursively...
      Adding assembly reference for System.Drawing.Common, recursively...
        Adding assembly reference for System.Runtime.Serialization, recursively...
          Adding assembly reference for System.ServiceModel.Internals, recursively...

The next issue I hit was building the SmartHotel360 app in `Release`:

    error XALNK7000: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.CodeDom.Compiler.ICodeGenerator' (defined in assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') with scope 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.CodeDom.Compiler.ICodeGenerator
    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
    at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    --- End of inner exception stack trace ---
    at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) in C:\src\xamarin-android\external\Java.Interop\src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics\Diagnostic.cs:line 166
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
    at Xamarin.Android.Tasks.AndroidTask.Execute()

I reworked `<LinkAssemblies/>` to use a single `AssemblyResolver` that
uses `FrameworkDirectories` as search directories:

    <LinkAssemblies
      ...
      FrameworkDirectories="$(_XATargetFrameworkDirectories);$(_XATargetFrameworkDirectories)Facades"

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 29, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

We can also remove:

* Any of the `<PackageReference Include="NuGet.*" />` packages we are
  using.

* `MetadataResolver` class, `NuGetLogger` class

The first issue I found was that we have to include these references
by default:

    Java.Interop;
    Mono.Security;
    System.Net.Http;
    System.ServiceModel.Internals;
    System.Runtime;

`System.dll` references `Mono.Security.dll`. `Mono.Android.dll`
references `System.Net.Http.dll` due to `AndroidClientHandler`.

The dependency tree for `System.ServiceModel.Internals.dll` is
somewhat more convoluted:

    Adding assembly reference for Mono.Android, recursively...
      Adding assembly reference for System.Drawing.Common, recursively...
        Adding assembly reference for System.Runtime.Serialization, recursively...
          Adding assembly reference for System.ServiceModel.Internals, recursively...

The next issue I hit was building the SmartHotel360 app in `Release`:

    error XALNK7000: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.CodeDom.Compiler.ICodeGenerator' (defined in assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') with scope 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.CodeDom.Compiler.ICodeGenerator
    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
    at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    --- End of inner exception stack trace ---
    at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) in C:\src\xamarin-android\external\Java.Interop\src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics\Diagnostic.cs:line 166
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
    at Xamarin.Android.Tasks.AndroidTask.Execute()

I reworked `<LinkAssemblies/>` to use a single `AssemblyResolver` that
uses `FrameworkDirectories` as search directories:

    <LinkAssemblies
      ...
      FrameworkDirectories="$(_XATargetFrameworkDirectories);$(_XATargetFrameworkDirectories)Facades"

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 29, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

We can also remove:

* Any of the `<PackageReference Include="NuGet.*" />` packages we are
  using.

* `MetadataResolver` class, `NuGetLogger` class

The first issue I found was that we have to include these references
by default:

    Java.Interop;
    Mono.Security;
    System.Net.Http;
    System.Runtime;
    System.Runtime.Serialization;
    System.ServiceModel.Internals;

`System.dll` references `Mono.Security.dll`. `Mono.Android.dll`
references `System.Net.Http.dll` due to `AndroidClientHandler`.

The dependency tree for `System.ServiceModel.Internals.dll` is
somewhat more convoluted:

    Adding assembly reference for Mono.Android, recursively...
      Adding assembly reference for System.Drawing.Common, recursively...
        Adding assembly reference for System.Runtime.Serialization, recursively...
          Adding assembly reference for System.ServiceModel.Internals, recursively...

The next issue I hit was building the SmartHotel360 app in `Release`:

    error XALNK7000: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.CodeDom.Compiler.ICodeGenerator' (defined in assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') with scope 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.CodeDom.Compiler.ICodeGenerator
    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
    at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    --- End of inner exception stack trace ---
    at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) in C:\src\xamarin-android\external\Java.Interop\src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics\Diagnostic.cs:line 166
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
    at Xamarin.Android.Tasks.AndroidTask.Execute()

I reworked `<LinkAssemblies/>` to use a single `AssemblyResolver` that
uses `FrameworkDirectories` as search directories:

    <LinkAssemblies
      ...
      FrameworkDirectories="$(_XATargetFrameworkDirectories);$(_XATargetFrameworkDirectories)Facades"

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 30, 2020
One of the remaining pain points in the Xamarin.Android build is the
`<ResolveAssemblies/>` MSBuild task.

1. It isn't particularly fast and runs on *every* build. During the
   devloop it runs twice for `Build` and `Install`. It runs for DTBs,
   designer builds, too.

2. It breaks for certain NuGet packages as mentioned on a few Github
   issues:

dotnet#3898
dotnet#4074

After some research and looking at build logs, we may be able to
rework the behavior:

1. Remove NuGet-related code and recursive assembly searching.

2. Use `@(_ReferencePath)` and `@(_ReferenceDependencyPaths)`.

3. Include assemblies even if they have `%(ResolvedFrom)` ==
   `ImplicitlyExpandDesignTimeFacades`.

We can also remove:

* Any of the `<PackageReference Include="NuGet.*" />` packages we are
  using.

* `MetadataResolver` class, `NuGetLogger` class

The first issue I found was that we have to include these references
by default:

    Java.Interop;
    Mono.Security;
    System.Net.Http;
    System.Runtime;
    System.Runtime.Serialization;
    System.ServiceModel.Internals;

`System.dll` references `Mono.Security.dll`. `Mono.Android.dll`
references `System.Net.Http.dll` due to `AndroidClientHandler`.

The dependency tree for `System.ServiceModel.Internals.dll` is
somewhat more convoluted:

    Adding assembly reference for Mono.Android, recursively...
      Adding assembly reference for System.Drawing.Common, recursively...
        Adding assembly reference for System.Runtime.Serialization, recursively...
          Adding assembly reference for System.ServiceModel.Internals, recursively...

The next issue I hit was building the SmartHotel360 app in `Release`:

    error XALNK7000: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.CodeDom.Compiler.ICodeGenerator' (defined in assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') with scope 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.CodeDom.Compiler.ICodeGenerator
    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
    at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    --- End of inner exception stack trace ---
    at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) in C:\src\xamarin-android\external\Java.Interop\src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics\Diagnostic.cs:line 166
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
    at Xamarin.Android.Tasks.AndroidTask.Execute()

I reworked `<LinkAssemblies/>` to use a single `AssemblyResolver` that
uses `FrameworkDirectories` as search directories:

    <LinkAssemblies
      ...
      FrameworkDirectories="$(_XATargetFrameworkDirectories);$(_XATargetFrameworkDirectories)Facades"

With these changes I am still able to build SmartHotel360, and the
`<ResolveAssemblies/>` is an order of magnitude quicker:

    Before:
    310 ms  ResolveAssemblies                          1 calls
    After:
     44 ms  ResolveAssemblies                          1 calls

So this would save ~532ms (x2 620ms -> 88ms) from the dev-loop.

This is a big WIP, as I need to figure out what types of projects this
might break. Let's see what happens on CI!
@maratoss
Copy link
Author

maratoss commented Mar 28, 2020

@jonathanpeppers
Yay! Problem is gone after upgrade to VS 16.5.1.
Thanks!

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" -t:Rebuild -v:d -restore:true App1.csproj

Build succeeded.

"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(_GetPrimaryCpuAbi target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.Debugging.targets(423,2): warning : One or more errors occurred. [C:\repositories\TestApp1\App1\App1.csproj]


"C:\repositories\TestApp1\App1\App1.csproj" (Rebuild target) (1:7) ->
(ResolveAssemblyReferences target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be reso
lved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [C:\repositories\TestApp1\App1\App1.csproj]

    2 Warning(s)
    0 Error(s)

Time Elapsed 00:00:38.15

@rneeft
Copy link

rneeft commented Apr 16, 2020

yes @jonathanpeppers and @maratoss I also confirm the issue is gone. My test project is building fine now on the build server. Great work guys!!

@brendanzagaeski
Copy link
Contributor

Thanks for the follow-up maratoss and rneeft! Based on those results and the close relation of the symptoms to #3920 and #4182, which were both fixed by 40d4df6 (from #3938), I will close this issue as fixed in Xamarin.Android 10.2 and Visual Studio 2019 version 16.5.

@markjerz
Copy link

Hello, I've got the same (or very similar) error happening. If I create a new Xamarin Forms App targeting iOS and Android, install IPFS.Engine via nuget then I get the following:

Build FAILED.

"F:\Projects\Files\Files.Android\Files.Android.csproj" (Rebuild target) (1:7) ->
(_ResolveAssemblies target) ->
  C:\Users\mark\.nuget\packages\tmds.libc\0.2.0\ref\netstandard2.0\Tmds.LibC.dll : warning XA0107: Ignoring Reference A
ssembly `C:\Users\mark\.nuget\packages\tmds.libc\0.2.0\ref\netstandard2.0\Tmds.LibC.dll`. [F:\Projects\Files\Files.Android\Files.Android.csproj]


"F:\Projects\Files\Files\Files.Android\Files.Android.csproj" (Rebuild target) (1:7) ->
(_ResolveAssemblies target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(
1660,2): error XA2002: Can not resolve reference: `Tmds.LibC`, referenced by `Makaretu.Dns.Multicast`. Please add a NuG
et package or assembly reference for `Tmds.LibC`, or remove the reference to `Makaretu.Dns.Multicast`. [F:\Projects\Files\Files\Files.Android\Files.Android.csproj]

    1 Warning(s)
    1 Error(s)

Looks like one of the packages that the installed package references is a "referenced assembly". Annoyingly, this used to build but then I updated my VS, in an attempt to fix one thing, and it broke this instead. I'm on VS 2019 version 16.6.0, Xamarin.Android SDK is at 10.3.1.0 (i.e. everything is latest version)

Anybody got any thoughts on how to fix this? I've updated everything already!

@brendanzagaeski
Copy link
Contributor

@markjerz, if you get a chance, if you can open a new issue for that behavior and attach a .zip file of your diagnostic MSBuild output or a .zip file of a small test project that reproduces the issue so that the team can take a look, that would be excellent. Thanks in advance!

@markjerz
Copy link

@brendanzagaeski This seemed so close to this issue that I replied here, apologies.

I've now opened a new issue here: #4729

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests