Bug 12835 - Can not load Xamarin.Android Project
Summary: Can not load Xamarin.Android Project
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Peter Collins
URL:
Depends on:
Blocks:
 
Reported: 2013-06-23 04:05 UTC by Stefan Schoeb
Modified: 2016-08-03 15:23 UTC (History)
11 users (show)

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

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 on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Stefan Schoeb 2013-06-23 04:05:58 UTC
Since I've updated to the latest alpha (4.7.10) I cannot load any android project, here is the exception:
There was an error attempting to initialize the Mono for Android extension.

-> More Details: System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'. at System.ComponentModel.Composition.Caching.AttributedModel.ReflectionCacheServices.<>c__DisplayClassf.b__e() at System.Lazy1.CreateValue()
   at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value()
   at Microsoft.Internal.LazyServices.GetNotNullValue[T](Lazy1 lazy, String argument) at System.ComponentModel.Composition.ReflectionModel.ReflectionParameterImportDefinition.ToImportingItem() at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.GetImportingItem(ImportDefinition definition) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.GetImportingItemFromDefinition(ImportDefinition definition) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition definition, IEnumerable1 exports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable1 imports, AtomicComposition atomicComposition) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part) at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore() at System.ComponentModel.Composition.Primitives.Export.get_Value() at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export) at System.ComponentModel.Composition.ExportServices.<>c__DisplayClass42.<CreateStronglyTypedLazyOfTM>b__1()
   at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue()
   at System.Lazy1.get_Value() at Mono.VisualStudio.Extension.Commands.CommandManager.AddAll(IServiceProvider owningPackage) at Mono.Android.VisualStudio.MonoAndroidPackage.Initialize()

System.Exception: There is already a logger with the name 'Xamarin.Android' at Mono.VisualStudio.Extension.LoggingService.AddLogger(ILogger logger) at Mono.Android.VisualStudio.MonoAndroidPackage.SetupLogging() at Mono.Android.VisualStudio.MonoAndroidPackage.Initialize()

My System: VmWare running Windows 8 64 Bit. VS2012 Update 2
Comment 1 Dominique Louis 2013-06-24 05:21:41 UTC
I have VS2012 Update 2, on Windows 7(NOT VM), and installed 4.7.10 and it opened up an Android project without any problems. Can you provide any more info?
Comment 2 Stefan Schoeb 2013-06-24 05:31:02 UTC
Ok here we go:
 - Working on Win8 (64Bit) in a VM
 - Got WP8 SDK installed
 - Got ReSharper installed
 - Xamarin.Android and Xamarin.iOS is installed

what else could be interesting for you?
Comment 3 Dominique Louis 2013-06-24 07:37:37 UTC
Hi Stefan,
  Are you running the latest Alpha of iOS too?


D.
Comment 4 Stefan Schoeb 2013-06-25 07:49:32 UTC
Nope, here is what I did:

Precondition:
Got my working Xamarin.Android/Xamarin.iOS machine (stable versions)

Steps:
1. Startup VS 2012
2. Receive Message for available alpha updates (got this enabled to know what is going on, never updated)
3. Clicked Download
4. Waited until new installer downloaded in chrome
5. Executed installer
6. Closed VS as installer forces me to
7. Install works fine
8. Open VS -> Try open project which was open before (Cross Plattform soultion including WP8, iOS, Android, WinRT, WPF, NUnit Test Project)
9. Bäm, error appears when VS tries to load Android project
Comment 5 Nischal 2013-07-31 02:54:52 UTC
Today we have checked this issue with following builds:
Windows8
VS 2012
X.Android 4.8.1-10
iOS for VS 1.3.250

I am getting the same issue when create or open any android application in VS 2012 when Xamarin.Android 4.8.1-10 installed  on windows. this is the gist for the same: https://gist.github.com/atin360/859541b9cd4441360e51

This issue is same as was happening in Bug 13287 for iOS
Comment 6 Mohit Kheterpal 2013-07-31 11:47:34 UTC
We have checked this issue on following environments :

Details of Working environment : 
https://gist.github.com/atin360/630dd90c8476b6a0926c

Details of Non Working Environment :
https://gist.github.com/atin360/fcea8fc30ed970901796
Comment 7 Mohit Kheterpal 2013-07-31 11:59:16 UTC
An update to comment 6 :

Other working environments :

Windows 7 :
https://gist.github.com/saurabh360/4aa42f025f85bc8554da

Windows 8 :
https://gist.github.com/AkhileshKumar01/37b9dc208362f7ae1c1f
Comment 8 PJ 2013-07-31 12:22:55 UTC
The MTVS used for comment 6 and comment 7 was 1.3.266. This is the common and unfortunate behavior when the extensions are not kept in sync.

PeterC, can you see if this is a blocker for our 4.8.1 release? It only has to be compatible with 1.3.250 for now.
Comment 9 Peter Collins 2013-07-31 13:18:43 UTC
Upgrading from the current stable versions of X.A and X.I-VS to X.A. 4.8.1-10 does not result in this behavior, I'm able to use both extensions without issue.
Comment 10 narayanp 2013-08-01 05:16:22 UTC
Today I have checked this issue with following builds:

Windows 8(32 bit)
VS 2012/2010
Xamarin.Android 4.8.1-13
iOS for VS 1.3.272

Now we are successfully able to create and open Android project in VS2012.

Hence closing this issue
Comment 11 zagaradrian 2013-08-28 02:16:50 UTC
Same bug with latest xamarin (4.8.1.13). Works perfect on Visual Studio 2010 but in VS 2012 I got exactly the message displayed here. If it helps, I can reproduce the error this way (to see it's not project dependant):
- open Visual studio 2012 (without any project/solution)
- Tools -> options -> Xamarin
- I gat the message: "There was an error attempting to initialize the Mono for Android extension."
Details:
System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'.
   at System.ComponentModel.Composition.Caching.AttributedModel.ReflectionCacheServices.<>c__DisplayClassf.<GetParameterFromCache>b__e()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Microsoft.Internal.LazyServices.GetNotNullValue[T](Lazy`1 lazy, String argument)
   at System.ComponentModel.Composition.ReflectionModel.ReflectionParameterImportDefinition.ToImportingItem()
   at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.GetImportingItem(ImportDefinition definition)
   at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.GetImportingItemFromDefinition(ImportDefinition definition)
   at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition definition, IEnumerable`1 exports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part)
   at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
   at System.ComponentModel.Composition.Primitives.Export.get_Value()
   at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export)
   at System.ComponentModel.Composition.ExportServices.<>c__DisplayClass4`2.<CreateStronglyTypedLazyOfTM>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Mono.VisualStudio.Extension.Commands.CommandManager.AddAll(IServiceProvider owningPackage)
   at Mono.Android.VisualStudio.MonoAndroidPackage.Initialize()
Comment 12 zagaradrian 2013-10-17 07:51:27 UTC
And the same for version 4.8.3
Please provide some workaround!
Comment 13 PJ 2013-10-17 11:35:23 UTC
Zagaradrian, sorry to hear of your troubles.

This problem is often related to an incompatibility between the Xamarin.Android you have installed and the Xamarin.iOS for VS you have installed.

What version of Xamarin.iOS for VS do you have installed (if any)? If you're not on it, you should try using the current stable 1.4.2 build.

If this does not solve the issue, you may need to uninstall both Xamarin.Android and Xamarin.iOS for VS and re-install only the current stable builds.

During that process, you will likely hit bug 12858, and the workaround for that bug is to delete the directory listed in the warning dialog. (It's safe to do so).

Sorry for the experience you're having, hope we can fix it!
Comment 14 Brendan Zagaeski (Xamarin Team, assistant) 2013-10-22 17:34:22 UTC
Another user is seeing this on:

Windows 7 SP1, 64 bit
Microsoft Visual Studio Professional 2012
Version 11.0.60610.01 Update 3
Microsoft .NET Framework
Version 4.5.50938

Xamarin.Android   4.8.03015 (a25a31d0)
Xamarin.iOS   1.4.2 (7e177260)

Visual Studio extensions:
NuGet
Web Developer Tools
AnkhSVN
SharpSvn
JetBrains dotCover
JetBrains ReSharper
NCrunch
PostSharp
Color Theme Designer


I'll recommend one more round of clearing and reinstalling Xamarin.iOS, Xamarin.Android, and Xamarin Shell. Is there a chance an interaction with other Visual Studio extensions could be a factor?
Comment 15 zagaradrian 2013-10-23 02:23:40 UTC
Please provide some details for clearing/reinstalling Xamarin.iOS,
Xamarin.Android, and Xamarin Shell. I'm far from being a beginner (I am MS administrator and programming .NET from many years), but I would apreciate some steps for that job.

Thank you,
Adrian
Comment 16 Brendan Zagaeski (Xamarin Team, assistant) 2013-10-25 17:09:10 UTC
To thoroughly remove the Visual Studio plugins:

1. Uninstall Xamarin.Android and Xamarin.iOS from the Windows Control Panel.

2. Open the registry editor (regedit)
3. Look for this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDlls

4. Find all the entries that match this pattern:
C:\Program Files*\Microsoft Visual Studio 1*.0\Common7\IDE\Extensions\Xamarin

5. Delete them.

6. Back in Explorer, delete any remaining files from the Xamarin Visual Studio extension folders:
C:\Program Files*\Microsoft Visual Studio 1*.0\Common7\IDE\Extensions\Xamarin



## One other test to try

Since this error is commonly caused by a conflict between the Xamarin.iOS and Xamarin.Android versions, you might test Xamarin.Android by itself during the reinstallation process. That is, you can first install just Xamarin.Android. Then you can check if Xamarin.Android works in Visual Studio before installing Xamarin.iOS.
Comment 17 zagaradrian 2013-10-27 01:53:23 UTC
Thank you for guidance. I followed the steps (but I installed just Xamarin.Android, as I don't use Ios for the time being). Now it's working fine with VS 2012. So that problem is solved.
Comment 18 Brendan Zagaeski (Xamarin Team, assistant) 2013-10-28 17:02:28 UTC
Glad to hear that has at least worked around the problem for you for now. With some luck, by the time you once again wish to install both Xamarin.iOS and Xamarin.Android side-by-side, the problem will have been resolved by updates, and you'll have no trouble!
Comment 19 Sohail Amir 2013-12-05 09:03:37 UTC
I can't get 4.10.1 to even install correctly. I get the attached error.
Comment 20 Sohail Amir 2013-12-05 09:04:10 UTC
Sorry. Updated wrong post.