Bug 2000 - CoreData AddPersistentStoreWithType raises InvalidCastException on Device only
Summary: CoreData AddPersistentStoreWithType raises InvalidCastException on Device only
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-11-10 23:08 UTC by Paul Auman
Modified: 2013-12-05 18:36 UTC (History)
2 users (show)

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:

Description Paul Auman 2011-11-10 23:08:29 UTC
model = this.CreateModel();
store = new NSPersistentStoreCoordinator (model);
string [] configurations = model.Configurations;
NSDictionary migrationDict = new NSDictionary();
store.AddPersistentStoreWithType( new NSString("SQLite"), String.Empty, sqlURL,migrationDict,out error);

above code block runs on iOS5 simulator with out a problem. On device :

store.AddPersistentStoreWithType( new NSString("SQLite"), String.Empty, sqlURL,migrationDict,out error);

Throws :

System.InvalidCastException (Cannot cast from source type to destination type)

ideas ?
Comment 1 Sebastien Pouliot 2011-11-11 11:29:51 UTC
I could not create a working model that gave me your error. Could you attach a small, self-contained, test case so I can duplicate the issue ? thanks!

p.s. I had a look at the documentation and made a few fixes to allow easier use of the API, i.e. using null for non-required parameters. That will let you use:

store.AddPersistentStoreWithType (NSPersistentStoreCoordinator.SQLiteStoreType, null, sqlURL, null, out error);
Comment 2 Sebastien Pouliot 2011-11-11 17:28:06 UTC
Please ensure that your "iPhone" builds also includes the:

--gcc_flags "-weak_framework CoreData"

that your "IPhoneSimulator" must have to build the application correctly. I did not see an InvalidCastException but our initialization code is likely very different.
Comment 3 Sebastien Pouliot 2011-11-11 18:57:50 UTC
Actually your simulator might not have this if you're using the default "Don't link" setting. In such case the prebuilt 'simlauncher-4' is used and it's linked with CoreData (so no issue there). 

I'll make sure the (weak) reference to CoreData is made by default (like other frameworks) in future releases of MonoTouch.

note: you can simply close the bug report if the previous command fixes your issue (otherwise I'll still need a test case). thanks!
Comment 4 PJ 2013-11-19 17:05:36 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 5 PJ 2013-12-05 18:36:03 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.