Bug 14630 - NullReferenceException when casting null to interface
Summary: NullReferenceException when casting null to interface
Status: RESOLVED DUPLICATE of bug 14552
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.4.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-11 02:39 UTC by matt.m.jacobsen
Modified: 2013-09-11 08:31 UTC (History)
2 users (show)

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

Test Solution (1.41 MB, application/zip)
2013-09-11 02:39 UTC, matt.m.jacobsen

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 or GitHub 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:

Description matt.m.jacobsen 2013-09-11 02:39:42 UTC
Created attachment 4832 [details]
Test Solution

Hi, in the Simulator under Debug mode in I get a NullReferenceException when executing the following code:

            ICollection c = null;
            Hashtable t = new Hashtable();

            c = (ICollection) t["a"];

When running this snippet in a Console Project no exception is thrown.

The temporary workaround is:

            ICollection c = null;
            Hashtable t = new Hashtable();

               c = (ICollection) t["a"];

I've attached a project to reproduce the bug.

If you need any more info, just ask ;-)
Comment 1 matt.m.jacobsen 2013-09-11 02:53:28 UTC
Another example, illustrating that it's not related to the Hashtable, but rather to interfaces:

            object a = null;
            Array x = null;
            x = (Array) a; //works

            object b = (IEnumerable) null; //works
            IEnumerable y = null;
            y = (IEnumerable) b; //exception
Comment 2 Sebastien Pouliot 2013-09-11 08:09:31 UTC
This was fixed in 6.4.5.

*** This bug has been marked as a duplicate of bug 14552 ***
Comment 3 matt.m.jacobsen 2013-09-11 08:12:51 UTC
Is Xamarin.iOS 6.4.5 included with the Xamarin Studio 4.0.12 update?
Comment 4 Sebastien Pouliot 2013-09-11 08:16:53 UTC
They are separate products/downloads but you can update them (and al Xamarin products) from Xamarin Studio.

You should be notified when starting up Xamarin Studio. Alternatively you can click on "Xmarin Studio" menu and then on "Check for Updates"

To confirm what you have the easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button.
Comment 5 matt.m.jacobsen 2013-09-11 08:21:57 UTC
I only ever update via "Check for updates" or by clicking the notification in Xamarin Studio, in the hope that doing so keeps all the components congruent. 

The problem with this however is that I never know which version is included with the update, as the version numbers aren't given in the release notes.

Is there a quick way to find out what's changed across all components in a release?

Comment 6 Sebastien Pouliot 2013-09-11 08:31:00 UTC
You should see links to release notes before updating (you can expand each product cell for more information).

After updating you'll need to get the version number (see end of comment #4) and then go the xamarin.com web site to view each product release notes.