xamarin-docs icon indicating copy to clipboard operation
xamarin-docs copied to clipboard

iOS Multi-page PhoneWord sample -TargetInvocationException with NSInvalidArgumentException in ViewController.cs constructor.

Open IanBUK opened this issue 2 years ago • 0 comments

Environment M1 MacBook Air 2020, 8GB, macOS Monterey 12.1. Visual Studio 2022 for Mac Xcode 13.4

Problem Building the multi-page version of the PhoneWord HelloWorld app builds and runs, but crashes with a TargetInvocationException in the ViewController.cs constructor.

The line that throws the exception is: TableView.RegisterClassForCellReuse(typeof(UITableViewCell), callHistoryCellId);

The InnerException is: InnerException {Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[CallHistoryController _cachedTraitCollectionIsValid]: unrecognized selector sent to instance 0x7fe948c66a40 Native stack trace: 0 CoreFoundation …} Foundation.MonoTouchException

The instructions for the sample are outdated. They refer to earlier versions of VS for Mac, before the UI builder was removed. I've cloned the repo, and it refers to a minimum Mac OS version of 9.0. The .storyboard file structure is different, so it's hard to compare/contrast and see what's causing the problem.

As someone with 25+ years professional dev experience, I am only too willing to believe that it's something I've missed. However, all my experience has been on the Windows platform, using .Net since v1.0, so I'm not at all clear about what I might be missing here.

I've attached my source ... any clues as to what I've got wrong? The only notable changes I made to the sample where in the single page solution - I added something to LaunchScreen.storyboard and I moved the translator code to a different project. I did the latter as I wanted to prove to myself that I can easily do that abstraction so that when building my real project, the architecture will work as planned.

Thanks in advance.

Ian.

Phoneword_iOS 2.zip

IanBUK avatar Jul 03 '22 17:07 IanBUK