Bug 50914 - Unlike other C# project types, Xamarin.Android projects show warning ""ResolveLibraryProjectImports" task failed unexpectedly" and lack some IntelliSense features unless all referenced dependencies have been built
Summary: Unlike other C# project types, Xamarin.Android projects show warning ""Resolv...
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 7.1 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: master
Assignee: dean.ellis
URL:
: 23210 30844 51153 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-12-27 07:53 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-11-21 06:27 UTC (History)
8 users (show)

Tags: BZRC1S1
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (34.86 KB, application/zip)
2016-12-27 07:53 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 50914 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-12-27 07:53:38 UTC
Created attachment 19008 [details]
Test case

Unlike other C# project types, Xamarin.Android projects show warnings ""ResolveLibraryProjectImports" task failed unexpectedly" and "Some project features ... have been disabled" unless all referenced dependencies have been built




## Regression status: old regression introduced between July 2014 and August 2014

The precise text of the warnings has changed a bit over time, but the fundamental issue has remained largely unchanged. 

> BAD:  XamarinVS 4.3.0.490 (0373883), Xamarin.Android 7.1.0.14 (cea7c6e)  Cycle 9 Alpha  (December 19, 2016)
> 
> BAD:  XamarinVS 3.3.47.0  (0b2a123), Xamarin.Android (a5d5708)                          (August 2014)
> GOOD: XamarinVS 3.1.228.0 (2349ba7), Xamarin.Android (163212a)                          (July 2014)




## Steps to replicate

Open the attached test case in Visual Studio, and then see the "BAD Results" section for additional details.




## Steps followed to create the test case

1. Create a new "Visual C# > Android > Blank App (Android)" project.

2. Add a "Visual C# > Android > Class Library (Android)" project to the solution.  (You can use a portable library project at this step instead if you prefer.  The results are the same either way.)

3. Add an "iOS > iPhone > SingleView App (iPhone)" , an "iOS > Class Library (iOS)", a "Visual C# > Console Application", and a "Visual C# > Class Library".

4. Add a reference from each app project to its corresponding library project.




## BAD Results for the Android project



1. Two warnings appear under "View > Error List" (Testing note: Make sure you have the list set to display "Build + IntelliSense" messages.):


### Warning 1 (excerpt)

> The "ResolveLibraryProjectImports" task failed unexpectedly.
> System.IO.FileNotFoundException: Could not load assembly 'AndroidLibrary1, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
> File name: 'AndroidLibrary1.dll'
>    at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)

### Warning 2

> IDE0006	Error encountered while loading the project. Some
> project features, such as full solution analysis for the failed
> project and projects that depend on it, have been disabled.
(Note: This is a "secondary" warning.  This warning can be associated with a few different "primary" warnings.  This bug is _only_ about the case where Warning 1 also appears and there are no other warnings or errors.)



2. IntelliSense for the Android app project is incomplete.  For example:

- If you open the MainActivity.cs in the Android app project and navigate to "Edit > IntelliSense > Organize Usings", there is no "Remove Unnecessary Usings" menu item.  This is "bad" because for example the "using Android.Widget;" line _is_ unnecessary.

- The word "Bundle" in the `OnCreate()` override is black (no syntax highlighting).  This is "bad" because it should by syntax-highlighted as a class name.




## GOOD Results for the iOS project and the Console project


1. No warnings appear.


2. IntelliSense is complete:

- "Edit > IntelliSense > Organize Usings" includes the "Remove Unnecessary Usings" menu item.

- All class names are syntax-highlighted correctly.




## Workaround

Build the Android library project.  This fixes the warning messages and the IntelliSense.




## Additional testing environment info (brief)

Android SDK Tools 24.0.2
Android SDK Platform-tools 21
Android SDK Build-tools 23.0.1

Java JDK 8u111 (1.8.0_111) 64-bit

Microsoft Visual Studio Enterprise 2015
Version 14.0.25425.01 Update 3

Microsoft .NET Framework
Version 4.6.01055

Windows 8.1 (64-bit), Version 6.3 (Build 9600)
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2016-12-27 07:55:28 UTC
I ran through a few tests to narrow down the location of the regression.




## Test 1: The change is in the .targets files

Replacing all of the Xamarin.Android .targets files in XamarinVS 3.3.47 with the old files from 3.1.228 stops the problem.




## Test 2: The change is in the "Xamarin.Android.Common.targets" file

Replacing just the "Xamarin.Android.Common.targets" file in XamarinVS 3.3.47 with the old file from 3.1.228 stops the problem.




## Test 3: The problem is caused by the inclusion of `UpdateAndroidResources` in the `$(ResolveReferencesDependsOn)` property

Removing line 230 of "Xamarin.Android.Common.targets" in XamarinVS 3.3.47 is sufficient to stop the problem.  This is one of the lines that was added between 3.1.228 and 3.3.47.

### Context, including line numbers

> 226: <ResolveReferencesDependsOn>
> 227:     $(ResolveReferencesDependsOn);
> 228:     UpdateAndroidAssets;
> 229:     UpdateAndroidInterfaceProxies;
> 230:     UpdateAndroidResources
> 231: </ResolveReferencesDependsOn>



## Test 4: The hack from Test 3 is still effective in XamarinVS 4.3.0.490 (0373883)

Removing line 474 of "Xamarin.Android.Common.targets" in XamarinVS 4.3.0.490 (0373883) is sufficient to stop the problem.

### Context, including line numbers

> 470: <ResolveReferencesDependsOn>
> 471:     $(CoreResolveReferencesDependsOn);
> 472:     UpdateAndroidAssets;
> 473:     UpdateAndroidInterfaceProxies;
> 474:     UpdateAndroidResources;
> 475:     $(ApplicationResolveReferencesDependsOn);
> 476: </ResolveReferencesDependsOn>
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-12-27 07:57:29 UTC
## Next steps

The "hack" used to stop the problem in Tests 3 and 4 from Comment 1 might not be the ideal final fix for this issue.  Maybe it's important for `UpdateAndroidResources` to be included as a DependsOn in order for certain other behaviors to work as expected?  But if we're lucky, maybe it really is OK to skip it?  I'll turn to the Xamarin.Android team to help decide the best approach.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2016-12-27 08:09:29 UTC
*** Bug 23210 has been marked as a duplicate of this bug. ***
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2016-12-27 08:18:10 UTC
*** Bug 30844 has been marked as a duplicate of this bug. ***
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2016-12-30 02:37:45 UTC
*** Bug 51153 has been marked as a duplicate of this bug. ***
Comment 6 Curtis Mullett 2017-03-07 14:32:37 UTC
Was there any progress on this bug? The hack of removing line 474 doesn't seem to work for me. I still get warning 1 from the first comment on this thread as a build error. What I find strange is that the library that is now failing was working previously but no longer does, all packages in my library are of the same version as the packages in my app. It would be very helpful if you had any advise in fixing this issue if it is a mistake of my own thank you.

Build Log:
"
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1405,2): error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'UtilitiesXamarinLib, Version=1.2.6.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1405,2): error : File name: 'UtilitiesXamarinLib.dll'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1405,2): error :    at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1405,2): error :    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1405,2): error :    at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)
1>  Output Item(s): ResolvedAssemblies= (TaskId:130)
1>  Output Item(s): ResolvedUserAssemblies= (TaskId:130)
1>  Output Item(s): ResolvedFrameworkAssemblies= (TaskId:130)
1>  Output Item(s): ResolvedSymbols= (TaskId:130)
1>Done executing task "ResolveAssemblies" -- FAILED. (TaskId:130)
1>Done building target "_ResolveAssemblies" in project "App5.Droid.csproj" -- FAILED.: (TargetId:101)

"
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-09 01:28:46 UTC
Note from Comment 0:

> This bug is _only_ about the case where Warning 1 also appears and there are no other warnings or errors.
It is also only about the case where building "all referenced dependencies" _resolves_ the warning.

If you are seeing the issue as a build _error_ rather than as a _warning_, that is a different problem and will need to be investigated separately.  In that case, please be sure to review the Error List for any additional errors.  The most common cause of an _error_ is that the dependent library has failed to build due to some other error (see Bug 40782 for additional background context).  For additional questions after that, pick the option that best matches from [1].

[1] https://developer.xamarin.com/guides/cross-platform/troubleshooting/support-options/
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2017-10-26 03:06:59 UTC
## Verification status: Improved but not yet resolved in the latest preview version

Bug 58448 is a partial duplicate of this bug, just about the "Warning 2" symptom (from Comment 0).  A fix for Bug 58448 was added in https://github.com/xamarin/xamarin-android/pull/730.  As described in that pull request, the problem is apparently that the "design-time" build [1] of the Android library project intentionally does _not_ provide a .dll that can be consumed by the design-time build of the application project.  This is reasonable because design-time builds are meant to be minimal builds that "gather just enough information to populate the language service and other project services" [1].  But this means that Xamarin.Android's custom "ResolveLibraryProjectImports" task will always "fail unexpectedly" during the design-time build because it won't be able to find the library project .dll file.  The IntelliSense issues are a side-effect of the fact that the design-time build aborts early.

(Note: Errors and warnings that occur in _design-time_ builds are all shown as _warnings_ in the "View > Error List" window.)

https://github.com/xamarin/xamarin-android/pull/730 decreases the severity of this problem by instructing the design-time build to treat any "ResolveLibraryProjectImports" and "GenerateResourceDesigner" task failures as _warnings_ rather than errors.  This allows the design-time build to complete "successfully" and provides enough information to the language service to get normal IntelliSense behavior.

However, the current approach does _not_ stop the "task failed unexpectedly" warning message, and that message was the original motivation for this bug report (going back to Bug 23210).  The "task failed unexpectedly" warning will still appear any time a design-time build runs if the library project .dll is not present.  For example, it will appear in the error list any time the user adds a new "Class" item to the app project.



[1] https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#design-time-builds




## Next steps

- Do we know if these Tasks that depend on the library project .dll files really generate any information that gets used by IntelliSense or other pre-build IDE behaviors?  If not, then maybe we could add conditional logic to the Tasks that says "if this is a design-time build, then pretend the project does not have any references to library projects."

- If the Tasks _do_ generate important information for IntelliSense or other pre-build IDE behaviors, then maybe we could emit our own custom warning (in place of the current generic ""ResolveLibraryProjectImports" task failed unexpectedly" message) that explains which IntelliSense features or IDE behaviors will be missing until the library project .dll files have been built.



Thanks!