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.
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:
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).
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).
Related
unfortunately this question was closed however it is spot on. Let me go through the steps as I am reproducing a legacy app issue that uses httpclient so switching is not an option YET (6 months out maybe).
create android studio app
try to use Httpclient and as he shows in the post above it is in red
I try to add this line in build.gradle to bring it in as a work around(even though core android also brings it in)
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
Then I get this error in android studio
`httpclient` defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for `httpclient` use `HttpUrlConnection` or `okhttp` instead), or repackaging the library using something like `jarjar`.
Ok, so I am using the wrong version so I run build scan and I see this so I bring this one in instead of the other version (android studio now sees HttpClient and can import it at this point)
I still get the same error though about conflicting android libs.
QUESTION: How do I fix the red in my legacy project and not have this error either?
My best bet seems to ignore the error. Will I have issues that I am not seeing though in the future?
I have an Indie license for Xamarin so that I can develop apps for iPhone/iPad in my most proficient programming language, C#. With this license I can't use the Visual Studio plugin from Xamarin. I still prefer Visual Studio to Xamarin Studio, so I still develop on Visual Studio whatever code that does not need MonoTouch references and then just manually copy the dll into Xamarin Studio.
I have one assembly, .Net framework 4.5, that gets the following error message when I try to debug my app:
Loaded assembly: /Users/EdGriMac/Dropbox/Quiz/Newtonsoft.Json.dll
[External]
2013-09-23 20:30:38.021 Exam936[2228:c07] Could not load 'Newtonsoft.Json' for registration:
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes
(System.Reflection.Assembly,bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in
/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/Assembly.cs:351
at MonoTouch.Registrar.OldDynamicRegistrar.RegisterAssembly
(System.Reflection.Assembly a) [0x00000] in
/Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/OldDynamicRegistrar.cs:67
2013-09-23 20:30:38.023 Exam936[2228:c07] This could be due to an outdated assembly kept by the simulator, location:
/Users/EdGriMac/Dropbox/Quiz/Newtonsoft.Json.dll
My tries:
The first thing that springs to mind is that NewtonSoft.Json can't be used with MonoTouch, but I don't know how to find out. Is there a way to find out for sure if a 3rd party dll can be used?
My second idea was that an older or newer version of NewtonSoft.Json could be used by another assembly. This is not a large project, however, and the only other assembly I have that uses Json is RestSharp, but I don't think that uses NewtonSoft.Json. I looked at the web pages for their GitHub page, but was unable to find a reference.
I googled a bit and found this post saying that (a bit down) MonoTouch.Registrar.OldDynamicRegistrar.RegisterAssembly indicates that (quote:) I can't build the app using the build flags --registrar:olddynamic. If I remove that, it now works, I can now link and it appears to be working.. This is probably a setting in Visual Studio you can adjust when you have a Business license. I don't know how to build without these flags.
Is what I am trying to do possible? If yes, what should I do?
Thanks in advance!
The Json.NET version from Xamarin component store (http://components.xamarin.com/view/json.net/) works fine. And it installs directly from within Xamarin Studio
I seem to be having some problems after updating Xamarin/Monotouch this morning.
I updated MonoDevelop to 3.06 from whatever version was current and stable 10 days ago (sorry I can't be more specific), and Xamarin Studio to 4.0.2. I've been using MonoDevelop exclusively and have opened Xamarin Studio only now, wondering whether or not I was encountering a MonoDevelop bug.
My current MonoTouch version is:
Xamarin.iOS
Version: 6.2.1.201 (Enterprise Edition)
Hash: ed9807c
Branch:
Build date: 2013-19-03 13:42:59-0400
In either IDE, when running my app in either release or debug mode in the Simulator my app crashes with following InvalidCastExceptions:
System.InvalidCastException: Unable to cast object of type 'MonoTouch.Foundation.NSObject' to type 'MonoTouch.Foundation.NSUserDefaults'.
System.InvalidCastException: Unable to cast object of type 'MonoTouch.Foundation.NSObject' to type 'MonoTouch.Foundation.NSBundle'
These aren't the sort of casts that I'd expect to have fail on me :-)
In any case, the app compiles, transfers and runs correctly on an iPhone 4 with iOS 6.1.2 when built and installed from either Xamarin Studio or MonoDevelop
I've set the runtime target to 2.10.12, 2.10.11 and 2.10.9 (via this new Runtime Target menu option in the menus, even though it's meant to have no effect), and each time the app crashes in the same way.
This is all on code that was working correctly before the update (last week, before I went off to Iceland for a holiday and nobody touched anything while I was gone)
We don't use any third party assemblies; I've cleaned and rebuilt all assemblies but that hasn't helped. I'm about to try to narrow the problem down in a small test solution.
UPDATE 1:
Looking at the assemblies' version numbers in MonoDevelop, I see:
Assembly Version 2.0.5.0, found in /Developer/MonoTouch/usr/lib/mono/2.1
Monotouch has an Assemlby Version of 0.0.0.0.
I created a new MonoTouch project and added the first offending line to its main method:
public class Application
{
static void Main (string[] args)
{
// My real App crashes on this line with an InvalidCastException:
string s = NSUserDefaults.StandardUserDefaults.StringForKey("Login");
UIApplication.Main (args, null, "AppDelegate");
}
}
This ran fine.
UPDATE 2:
After changing the Build Options of the test app to match what we have in our real app, I get the same crash. The build options we have are:
iPhone Build -> General -> Linker Options -> Link All Assemblies
iPhone Build -> Advanced -> Use SGen generational garbage collector
iPhone Build -> Advanced -> Use SGen generational garbage collector -> Use reference counting extension.
Disabling ("Use reference counting extension") allows both the test app and my real app to run without crashing. So the problem seems to lie there.
I've updated to Xamarin Studio 4.0.2 and MonoDevelop 3.0.6
So you updated MonoDevelop 3.0.6 to Xamarin Studio 4.0.2, right ? Sadly that does not tell us exactly which version of MonoTouch/Xamarin.iOS was used before/now.
The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Could you edit your question to add this ?
my app crashes with following InvalidCastExceptions:
Do you use pre-built assemblies ? If some were against MonoTouch 6.0.x (or earlier) then the strongname change (in 6.2.x) could result in two different monotouch.dll being loaded - and you won't be able to cast instances between them.
If everything is rebuilt from source (no 3rd party .dll that can't be re-compiled) could you try to make a small sample (e.g. by reducing/commenting parts of your app) to show exactly where this happens ? (if possible edit your question with the source or file a bug report).
I've set the runtime target to 2.10.12, 2.10.11 and 2.10.9
The installed system mono is a requirement to run Xamarin Studio and some tools. However application built by Xamarin.iOS does not depend on the system installed Mono. IOW Xamarin.iOS ships with it's own runtime and SDK libraries (e.g. assemblies).
I have a legacy codebase that has binary-library dependencies on Visual C++ 6.0 and I cannot obtain source code for those binary libraries. So I am stuck debugging crashes on a Visual C++ 6.0 application. I notice that CrashRpt would be really handy if I could use at least Visual C++ 2005 or later, but since I can't, are there any other choices with at least some kind of global ability to catch faults, and generate a stack trace, if the application terminates via some abnormal fault, or throws an unhandled exception?
I've found some articles on Structured Exception Handling and the MS Debug Helper dll, but no cooked up working system, that I could simply drop into a VC++6 app.
I've started testing VS11 beta for building Ocean 2011 plugins. It seems to work very well, and has enough advantages that I'm considering using it for daily work. (We will, of course, not make production builds with VS11 before Schlumberger recommends it.)
However, there is one blocking issue:
Projects which depend on InventorNet.dll fail to build, with the following messages:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1546,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "InventorNet", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
CSC : fatal error CS0008: Unexpected error reading metadata from file 'c:\Program Files\Schlumberger\Petrel 2011\InventorNet.dll' -- 'Index not found.'*
I think the first warning is harmless, as similar warnings are emitted from other dependencies, but I can't get past the error message (in bold). Both probably originate from stricter assembly verification in .NET 4.5 (also in beta) used by MSBuild. Our projects target .NET 3.5.
Does anyone know if the error can be fixed with some setting or other trick, or do we need updated assemblies from Schlumberger? (A Google search yields a few similar cases relating to VS2010, and indicates that the assembly provider does, indeed, need to rebuild the assembly to correct the issue.)
Alternatively, can someone indicate whether the issue will be remedied by Ocean 2012?
I just simply test your case for petre/ocean 2012 D9 snapshot version with OIV 9.0.0.0(for 2011, it is 8.1.2.2), it seems that it works fine(passed building with some warnings in visual studio 2011, and running OK in Petrel 2012 D9)。
Deng Feng
Just about warnings for Ocean 2012 in VS11beta: it can be "CPU mismatch" warning if your solution has "Any CPU" target and based on top of Petrel 64 (Because Inventor's DLLs are CPU dependent). And it will be no warnings if you select 64 bit CPU target for your project.
Alex
first warning can be eliminated by adding the following string to your .csproj file:
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x86</PlatformTarget>
I added it inside node, after node