Question

I have a PCL project where I'm trying to use the Microsoft-provided PCL version of System.Net.Http and its dependencies, all installed via Nuget. This all works great in OSX (I'm able to build the PCL, and use it successfully in both an iOS and an Android project).

However, on Windows, I'm running into the issue described in this Stack Overflow thread, where the compiler is throwing warnings about references not being resolved (the warning under #3 in the Stack Overflow question) and failing with an error about the Http namespace not existing (the error in #2 in the Stack Overflow question).

I've attempted the solution described in that Stack Overflow question, but Xamarin Studio crashes if I change the current profile (in Project Options > Build > General) from Profile136 (the default) to Profile78 (the proposed solution). The profile change does get saved to my project, and the crash recurs if I try to relaunch Xamarin Studio. The exception and a (partial) stack trace are shown below.

Any suggestions on how to resolve this exception, or an alternate solution to the issue described in the Stack Overflow thread?

System.StackOverflowException was unhandled
Message: An unhandled exception of type 'System.StackOverflowException' occurred in ICSharpCode.NRefactory.dll

Stack trace:

> ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.TopLevelTypeNameComparer.GetHashCode(ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName obj) Unknown
  mscorlib.dll!System.Collections.Generic.Dictionary<ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName,ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition>.FindEntry(ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName key)  Unknown
  mscorlib.dll!System.Collections.Generic.Dictionary<ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName,ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition>.TryGetValue(ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName key, out ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition value) Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultUnresolvedAssembly.DefaultResolvedAssembly.GetTypeDefinition(ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName topLevelTypeName)  Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.TypeSystemExtensions.GetTypeDefinition(ICSharpCode.NRefactory.TypeSystem.IAssembly assembly, ICSharpCode.NRefactory.TypeSystem.FullTypeName fullTypeName)  Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.Implementation.GetClassTypeReference.Resolve(ICSharpCode.NRefactory.TypeSystem.ITypeResolveContext context)  Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultUnresolvedAssembly.DefaultResolvedAssembly.GetTypeDefinition(ICSharpCode.NRefactory.TypeSystem.TopLevelTypeName topLevelTypeName)  Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.TypeSystemExtensions.GetTypeDefinition(ICSharpCode.NRefactory.TypeSystem.IAssembly assembly, ICSharpCode.NRefactory.TypeSystem.FullTypeName fullTypeName)  Unknown
  ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.Implementation.GetClassTypeReference.Resolve(ICSharpCode.NRefactory.TypeSystem.ITypeResolveContext context)  Unknown
[... : Removed for brevity; repeat the previous three stack frames about 1000 times]
  The maximum number of stack frames supported by Visual Studio has been exceeded.  
Was it helpful?

Solution

Thanks to this reply on the Xamarin forums and this Nuget known issues document, I've finally managed to resolve this to my satisfaction. Basic steps:

  1. Remove the Nuget packages added for HTTPClient and Async support (including the BCL compatibility packages). Also, remove their references, if necessary (Xamarin Studio's Nuget plugin didn't do this for me, leaving broken references after removing the packages).

  2. Switch over to Profile7 instead of Profile158 (the default in Xamarin Studio for Mac's PCL project template).

This leaves me with a PCL project that builds successfully, and the Profile7 profile should support Xamarin.iOS and Xamarin.Android (as well as the WinRT .NET subset and the full .NET framework). No Windows Phone support (I'd need Profile78 for that, and Profile78 doesn't include HttpClient or async/await support), but that's not a dealbreaker in my case (we're not even close to considering a Windows Phone version of our software).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top