How do I set MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false? - ios

I'm using Xamarin and trying to run one of my apps in the iOS simulator but I am getting this error:
2015-10-07 12:38:02.715 MolinaCoding1iOS[1550:54337] Unhandled managed exception:
Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil.
It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false. (System.Exception)
How do I actually ignore this condition? If I should not ignore this...then what should I do?
Thanks

I got this problem solved by running "Clean" on my project (using Visual Studio). Right Click your project and select "Clean". Run the application afterwards.

You can ignore by adding the below statement just before you use that class/ method.
ObjCRuntime.Class.ThrowOnInitFailure = false;

Related

MvxRecyclerView NotSupportedException

I want to implement list of different types using MvxRecyclerView and ItemTemplateSelector but I get not supported exception when I only try to show activity with MvxRecyclerView.
System.NotSupportedException has been thrown.
Could not activate JNI Handle 0x7ffc627020 (key_handle 0xc743032) of Java type 'mvvmcross/droid/support/v7/recyclerview/MvxRecyclerView' as managed type 'MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView'.
The same when I add binding to ItemsSource, MvxTemplateSelector or MvxItemTemplate. Nothing helps. What am I missing?
I decided to post my answer as I had the same issue in MvvmCross 8.0.2 despite using the MvvmCross.DroidX.RecyclerView.MvxRecyclerView.
The solution in my case was to add MvvmCross.Plugin.FieldBinding package to the Droid project.

iText7 null reference exception on PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN) VS2019

Hi All: I have a VS2019 console app project that generates PDFs. Everything was working fine a month ago. When I re-opened the project and tried to run it, I am receiving a nullreferenceexception error when trying to create the first font in the PdfDocument.
PdfFont bfTimes = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
throws:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=itext.io
StackTrace:
at iText.IO.Font.FontCache..cctor()
I've confirmed the PdfDocument exists, and the font above returns "true" for "isRegistered".
Nothing changed in the project, but I did update VSCommunity to 16.11.2 at some point in the past couple of weeks. Is there any way to get a better error description for what's happening?
i searched for that specific exception error and found this other post from a few weeks ago:
https://csharpforums.net/threads/using-a-winform-to-create-a-pdf-using-itext7.6406/
The suggestion to turn on "just my code" in the debugging options made the error go away like magic :o

EXC_BAD_ACCESS code=1 because of #{}

I got a EXC_BAD_ACCESS code=1 because of a line like this:
NSDictionary* params = #{};
I didnt create the project, but i notice that have link to a c++ library, and have build setting that is not default (the setting generated by XCode). If i change this line by
NSDictionary* params = [NSDictionary new];
The issue is gone. Can it be something to do with the compiler's setting in project's build setting?
As a comment said this error is likely to be deep in your code. If the culprit is a zombie, the easiest way to find it is to run it (preferably in the latest Xcode, currently Xcode 8, as it has been improved) in profiler and choose "Zombies". When it fails, you can see the history of everything that has happened to the object.
Also, set an exception breakpoint. You may get a break when the error happens instead of in main, where the exception gets passed up.

Show debug messages if argument is set

In my project i'm showing debug messages with global variable:
struct GVariables {
static let debug = false
}
if GVariables.debug {
print("Debug mode enabled")
}
But is it possible to set argument here:
and check debug argument in code. How can i do this ? And is this a correct way ?
You can get access to those launch arguments and environment variables via NSProcessInfo
if NSProcessInfo.processInfo.arguments["DEBUGRPM"] ...
That's not unreasonable and allows you to change the behavior of a compiled app which can be useful in some cases. It does however have some overhead since you're always performing this check. If you would only ever enable debug logging in a debug build then setting a value in "Swift Compiler - Custom Flags" (as shown in the question #Larme linked) and using an #if DEBUGRPM expression will give you conditionally compiled code, saving the app the work of performing a runtime if test.
Which approach is more reasonable for you will depend on how you plan to use and when you plan to toggle this behavior.

Xamarin iOS Binding: Could not initialise an instance of the type, returned nil

I've bound an iOS library, SVGKit, to C# using Xamarin/Monotouch. After some issues I've managed to get the library to build ok.
My code can be found here: https://github.com/jamesmundy/SVGKit.Xamarin
Unfortunately, when I try to initialise a type from the class I receive the following error:
Could not initialize an instance of the type
'SVGKitBindings.SVGKFastImageView': the native 'init' method returned
nil. It is possible to ignore this condition by setting
MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.
The full stack trace is can be seen here.
Any idea as to what is causing this problem and what I can do to rectify it?
Update: Here is the full Build Output of my project. http://pastebin.com/f60wFm52
Update 2: Tried setting SmartLink to false and rebuilding, same error though a slightly different build output. http://pastebin.com/ApCAz2BP
Look at the source code for SVGKFastImageView init [1]:
- (id)init
{
NSAssert(false, #"init not supported, use initWithSVGKImage:");
return nil;
}
The managed exception is correct: you can't call this constructor.
[1] https://github.com/SVGKit/SVGKit/blob/cd47ae95e57c9490a9238173855ecbe83d4aaf44/Source/UIKit%20additions/SVGKFastImageView.m#L53

Resources