Bug 16076 - Cannot create an instance of the abstract class or interface `MonoTouch.CoreData.NSFetchedResultsSectionInfo'
Summary: Cannot create an instance of the abstract class or interface `MonoTouch.CoreD...
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-11-09 12:50 UTC by Neal
Modified: 2013-11-12 19:20 UTC (History)
2 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 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:
Status:
RESOLVED FEATURE

Description Neal 2013-11-09 12:50:58 UTC
Hello,

Checked out the BETA channel today, versions as listed below, it breaks my application with the exception as in the summary above.

Error CS0144: Cannot create an instance of the abstract class or interface `MonoTouch.CoreData.NSFetchedResultsSectionInfo' (CS0144)


=== Xamarin Studio ===

Version 4.2 (build 7)
Installation UUID: 99b05837-84cf-4971-a1b4-a52835a6ed01
Runtime:
	Mono 3.2.4 ((no/294f999)
	GTK+ 2.24.20 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302040000

=== Xamarin.Android ===

Version: 4.10.1 (Business Edition)
Android SDK: /Users/Neal/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.3   (API level 18)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.0.1 (3335.23)
Build 5A2053

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 7.0.4.193 (Business Edition)
Hash: 15aedc2
Branch: 
Build date: 2013-07-11 20:23:29-0500

=== Build Information ===

Release ID: 402000007
Git revision: 182e2b4208be889fc7a8302595664d349ab83fe2
Build date: 2013-11-08 00:29:22+0000
Xamarin addins: 1a874f4b5729f704e57bfb37f4cb5d7e3002c1ad

=== Operating System ===

Mac OS X 10.9.0
Darwin neals-mbp.home 13.0.0 Darwin Kernel Version 13.0.0
    Thu Sep 19 22:22:27 PDT 2013
    root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-11-11 04:46:49 UTC
Why are you creating an NSFetchedResultsSectionInfo in the first place? Can you show us that part of your code?
Comment 2 Neal 2013-11-12 18:03:31 UTC
	public static class NSFetchedResultsControllerExtensions
	{
        /// <summary>
        /// causes the fetch result controller to flush the cache and refetch
        /// all data from the persistent store
        /// </summary>
        /// <returns>true if refetch worked</returns>
        /// <param name="controller">Controller.</param>
        /// <param name = "mergeChanges">false: all local changes are flushed, true: local changes are preserved</param>
        public static bool Refetch(this NSFetchedResultsController controller, bool mergeChanges = false)
        {
            try
            {
                if (!string.IsNullOrEmpty(controller.CacheName))
                    NSFetchedResultsController.DeleteCache(controller.CacheName);
                controller.ManagedObjectContext.Refresh(mergeChanges);
                NSError error;
                bool result = controller.PerformFetch(out error);
                if (error != null)
                    return false;
                return result;
            }
            catch
            {
                return false;
            }
        }

		public static int GetItemsCount(this NSFetchedResultsController controller, int section)
		{
			try
			{
				NSArray sections = (NSArray)controller.ValueForKeyPath(new NSString("sections"));
				NSFetchedResultsSectionInfo sectionInfo = new NSFetchedResultsSectionInfo(sections.ValueAt((uint)section));
				NSNumber numberOfObjects = (NSNumber)sectionInfo.ValueForKeyPath(new NSString("numberOfObjects"));
				return numberOfObjects.IntValue;
			}
			catch
			{
				return 0;
			}
		}

		public static int NumberOfSections(this NSFetchedResultsController controller)
		{
			try
			{
				NSArray sections = (NSArray)controller.ValueForKeyPath(new NSString("sections"));
				return (int)sections.Count;
			}
			catch
			{
				return 0;
			}
		}
	}
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-11-12 19:02:19 UTC
Instead of this:

  NSFetchedResultsSectionInfo sectionInfo = new
NSFetchedResultsSectionInfo(sections.ValueAt((uint)section));

do this:

  NSObject sectionInfo = MonoTouch.ObjCRuntime.Runtime.GetNSObject (sections.ValueAt ((uint) section));

NSFetchedResultsSectionInfo is a protocol in ObjC, which we map to an abstract class in this case, so it's not really possible to create an instance of it (the fact that we allowed it earlier was a bug in our bindings).
Comment 4 Neal 2013-11-12 19:20:28 UTC
Thanks Rolf, I'll give it a try.