Bug 10433 - Random "The type or namespace name 'XXX' could not be found" errors when building
Summary: Random "The type or namespace name 'XXX' could not be found" errors when buil...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 4.4.x
Hardware: PC Mac OS
: Highest major
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2013-02-19 06:59 UTC by Sebastian Krysmanski
Modified: 2014-01-22 06:26 UTC (History)
7 users (show)

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


Attachments
Example project for reproducing this issue (21.31 KB, application/zip)
2013-02-19 06:59 UTC, Sebastian Krysmanski
Details

Description Sebastian Krysmanski 2013-02-19 06:59:52 UTC
Created attachment 3420 [details]
Example project for reproducing this issue

Over the last couple of days I was getting some weird errors when compiling a MfA solution (Visual Studio 2012, MfA 4.4.55):

  The type of namespace name 'XXX' could not be found (are you missing a using directive or an assembly reference?)

The weird thing was that the error only occurred randomly. Once it occurred, I just had to build the solution again (without any changes) and the error would disappear. (There is no actual error but the compiler complains anyway.)

Today, I decided to track down the problem. Before I get into the details, here's a video of the problem:

  http://www.youtube.com/watch?v=f7PMNHnUDFY

I found out that the problem only occurred after packaging a project (using "Build" -> "Package ProjectName for Android (.apk)").

So I trimmed down my solution and attached it to this report.

To reproduce the error (see video):

 1. Open solution ResourceErrorsAfterPackaging.sln
 2. Set "StepDetector" as startup project
 3. Build the solution
 4. Package the "StepDetector" project (using "Build" -> "Package StepDetector for Android (.apk)")
 5. Make a small change to "MainActivity.cs" in "StepDetector", so that VS thinks it needs to compile the StepDetector project
 6. Build the solution (using "Build" -> "Build Solution"; don't use "Rebuild Solution").
 7. Repeat steps 5 and 6 a couple of times (2 - 5) to trigger the error. If it doesn't occur, first do step 4 again, and then repeat steps 5 and 6.

I think the cause is (somehow) that the project "Commons.MonoDroid" is referenced in all other projects.

Here are the ways I found to make the error disappear (in the example solution):

 * Remove the "DebugInfoExchangeProtocol.MonoDroid" project from the solution. Note that the library project "DebugInfoExchangeProtocol.MonoDroid" is not referenced by the "StepDetector" project (or any other project).
 * Remove any of the existing project references.
 * Move the "Commons.MonoDroid" project from "<solutiondir>/commonslib/monodroid" to "<solutiondir>/commons".

I also noted that the error is easier to trigger the more projects (and references?) you have in your solution. On my original solution, I can trigger the error every time (unlike the example solution attached to this post).
Comment 1 Jonathan Pryor 2013-05-23 14:25:00 UTC
Vinicious: This looks like a race condition. We suspect someone is using Threads or the TPL to perform some tasks, and this is why it randomly fails when building.
Comment 4 PJ 2013-10-23 15:30:08 UTC
Definitely didn't make it into 4.8.3, and Vinicius is consumed right now with 4.10.1 and 1.8 issues. Perhaps this could be re-assigned to Dean.
Comment 6 dean.ellis 2013-11-14 11:03:27 UTC
I've managed to replicate this issue. 

The output from the msbuild job is at https://gist.github.com/dellis1972/d4b4b3346f881f848334

gonna start looking into why this is happening.
Comment 7 dean.ellis 2013-11-14 11:14:20 UTC
looks like the MapLocation.MonoDroid is loosing its reference to Commons.MonoDroid

https://gist.github.com/dellis1972/d4b4b3346f881f848334#file-gistfile1-txt-L10929
Comment 8 dean.ellis 2014-01-08 11:57:35 UTC
This has been fixed in XamarinVS/master/3b86509eb4

The problem seems to have been caused by the Android extension shelling out to  msbuild to do the deployment and packaging instead of using the internal MSbuild engine within visual studio. 
Moving the deployment and packaging to use the internal engine resolves the issue, the example provided now builds correctly with the fix. 

This fix should be in the 1.12 release.

Sebastian it would be helpful for us to be able to include the sample you provided in our unit tests, can we have your permission to do so please?
Comment 9 Andreas 2014-01-13 11:23:02 UTC
Guess you meant the 4.12 release?
Comment 10 Jonathan Pryor 2014-01-13 16:50:22 UTC
No, he meant the 1.12 release. Our version numbers are...confusing. :-/

In this case, he means "Visual Studio plugin v1.12". The Visual Studio plugin is in turn included within Xamarin.Android and Xamarin.iOS (for now...), and (depending on timing) will either be included in XA 4.12 or be punted until XA 4.14.
Comment 11 Andreas 2014-01-14 01:52:38 UTC
Hi Jonathan, thanks for clarification - I want to try to enable parallel builds after you release the fix, so clear evidence which version will contain the solution is quite useful to me ;-)
Comment 12 Prashant manu 2014-01-22 06:26:24 UTC
I have checked this issue with following builds:

All Windows
VS 2013/2012/2010
X.Android 4.13.0-39

I have followed all steps. I am not able to reproduce this issue.

Note You need to log in before you can comment on or make changes to this bug.