strange InvalidCastExceptions from NSObject to NSBundle/NSUserDefaults with mono runtime 2.10.12 - xamarin.ios

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).

Related

Does MtouchSdkVersion setting affect what version of iOS we can run on?

When deploying an existing Xamarin forms proj from Visual Studio I was getting errors like "Failed to load AOT module ‘System.Net.Http’ while running in aot-only mode". This had worked in the past, it seemed Xcode had recently updated before I hit the problem. I found I was able to get the project deploying by changing the csproj entry 10.0 to 10.3. It looks like I could change this setting and everyone would be ok if they also had updated xcode.
My concern is: Does this change what versions of iOS the application can support? Would it have any other surprises when deployed to the apple store?
One thing I don't understand is I am the only person seeing this issue. Another developer is able to deploy to an iOS device (iPad instead of an iPhone) that also has the latest version of iOS without problems. Running “xcodebuild -version” shows we have the same version of xcode installed (8.3.1) and running “xcodebuild -showsdks” shows we have the same iOS sdk available (iOS 10.3).
There is some good documentation on the iOS SDK version: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/cross_development/Overview/overview.html#//apple_ref/doc/uid/20002001-BABEBGCF
You can build against a higher version of the SDK and run against lower versions of iOS.
Building against different versions of the iOS SDK can cause differences in behavior, these may show as regressions in your application.

Compilation of Release configuration fails (ILT0005)

I've updated Visual Studio 2015 to Update 2 recently. Since then, I'm not able to compile my already published app anymore. Even a new blank UWP project does not compile. I get the following error message:
ILT0005: "C:\Program Files (x86)\MSBuild\Microsoft.NetNative\x86\ilc\Tools\nutc_driver.exe #"C:\Users\locked\documents\visual studio 2015\Projects\App1\App1\obj\x86\Release\ilc\intermediate\MDIL\App1.rsp"" Exitcode -1073740791
I completely uninstalled all Visual Studio relevant components and reinstalled them, which didn't solve the problem. Unfortunately, I'm not able to update my app at the moment.
I'm running Windows 10 Build 10586.218
It is a bug in .NET Native compiler, affecting German localization only (based on our current knowledge). We are looking into solutions (a fix with reasonable shipping vehicle, or better workaround). Stay tuned.
[Update] The fix shipped on 6th May as "Universal Windows App Development Tools - Tools (1.3.2)". Go to Control Panel - Programs - Programs and Features - Visual Studio ... - Modify, check Tools (1.3.2), then click Update. All languages now work (German, French, Italian, etc.).
-Karel Zikmund
(.NET Native team)
i had exactly this issue on french platform and found this solution : https://social.msdn.microsoft.com/Forums/en-US/9d590372-d82c-4075-9ea9-504a22c9502f/cant-compile-in-net-native-ilt005-error?forum=wpdevelop
compilation is ok after moved all ressources files nutcui.dll

How to add Storage reference?

This should be pretty straightforward, but can't work this out for myself I'm afraid!
The following line of code triggers the error:
using Microsoft.Xna.Framework.Storage;
Error: The type or namespace name 'Storage' does not exist in the
namespace 'Microsoft.Xna.Framework' (are you missing an assembly
reference?)
But as far as I can tell, I have added the reference: (Solution explorer -> right click References -> Add reference -> .NET tab -> scroll down to Microsoft.Xna.Framework.Storage -> select it -> click OK).
Microsoft.Xna.Framework.Storage shows up when I expand "references" in the solution explorer.
What am I missing?
EDIT
Okay on second look this might be to do with how I'm adding the references. When I search in the object browser Microsoft.Xna.Framework.Storage doesn't show up (but when I search, for example, for audio, Microsoft.Xna.Framework.Audio does show up). Is there anyway to check that when I click "OK" on the add reference pop-up that it is actually working?
I see two likely possibilities.
You have a mismatch of XNA 4.0 and XNA 3.1 (or previous) references in your project. If the Storage reference you added is from 3.1, you'll get this message. You can try removing it, and then looking specifically for the 4.0 version during add.
The device you are building for may not support the Storage mechanism. In particular, Windows Phone apparently uses a different storage mechanism (System.IO.IsolatedStorage http://msdn.microsoft.com/en-us/library/ff604992.aspx).
Hope one of these helps.
This question was asked a long time ago, but if anyone else is still looking for an answer, here is how i fixed it.
If you installed the Microsoft.Xna.Framework references by using the installer from Microsoft, then it installs in C:\Windows\Microsoft.NET\assembly. I found all of the Xna libraries in GAC_32 and Microsoft.Xna.Framework.Storage in GAC_MSIL.
You can also use the GAC to find libraries that aren't in Visual Studio's reference list. For .NET Framework versions before 4.0, the libraries are in C:\Windows\assembly, and the libraries for versions after 4.0 are in C:\Windows\Microsoft.NET\assembly.
It's actually been removed from Monogame by Microsoft.
Running: Windows 10, with integrated graphics card (Intel G45/G43), Visual Studio 19, Monogame 3.7.1
Project Structure: Solution > Game.Shared, Game.Android, Game.OpenGL (followed this guide on creating a Cross-Platform project, method number 3).
I changed the Target Framework in my OpenGL project from .NET 4.5 to .NET 4.7.x (the newest version), and I was able to build and deploy the app to an Android device. Do this by clicking the project and selecting Properties.
I simply commented out the line. App will successfully deploy to an Android device this way. The game will then deploy, but I can't get any content to load.
Have yet to see if I can deploy to an iOS device, I will update this post when I figure out if I can.
No nuGet's installed.

Unable to load Json.NET dll Xamarin Studio

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

How to get MvvmCross vNext to compile on Mac using MonoDevelop

I am trying to compile the vNext branch of MvvmCross on a Mac to try & start doing some iOS development using PCL's & MvvMCross.
I have spent a couple of days on this now but appear to be going in circles... being somewhat new to both C# & the Mac.
I have installed MonoDevelop 3.1.1 as recently referred to on #slodge's blog.
I have updated the targets file as per this reference https://files.xamarin.com/~jeff/Microsoft.Portable.CSharp.targets
I have downloaded the vNext branch from GitHub.
I have loaded the mvvmcross_all.sln in MonoDevelop however building it using the Debug|iPhone Simulator profile gives me 3 errors.
I have not been able to work out how to fix the references errors as for example appear in CrossUI.Core, ie references to
System
System.Core
System.Net
etc
Each of these lines has an error of Assembly not available for .NetPortable 4.0 Profile1 Profile (in Mono 2.10.9)
I realise its all a moving target but its obviously possible to get it to compile.
Any suggestions as to what I may have missed would be appreciated.
TIA,
Andreas
Thanks Andreas
In the version referenced in the blog at http://slodge.blogspot.co.uk/2013/02/a-patched-monodevelop-for-pcls.html, it appears that MonoDevelop reports that CrossUI is missing its references - but it still compiles. See this screenshot from my Mac - solution explorer reports problems but 'rebuild all' on CrossUI succeeds.
If you get problems with building, please do report the build output and I'll try to help.
Note that the patched version of MonoDevelop also still has other problems - e.g. syntax highlighting and intellisense issues- MonoTouch: creating multiplatform apps using Portable Class Libraries
Alternatively, there are some iOS/Mac friendly binaries on SkyDrive - http://slodge.blogspot.co.uk/p/mvvmcross-binaries_7.html
The schedule for 'proper' support of Portable Class Libraries is aiming for a demonstrable version before Evolve (so less than 2 months away). Until then I'll personally continue to do most of my PCL work in VS, with the platform specific steps in MonoDevelop.

Resources