Xamarin.iOS - Error processing Custom Renderer method

Jamie Colclough 1 Reputation point
2021-03-25T15:39:30.367+00:00

I've been trying to get a build archived for IOS by using Visual studio and the "Pair to mac" functionality.
However, when I try and do a release build, I get this error:

Error processing the method 'System.Void ProjectName.iOS.Renderers.IOSWebViewRenderer::.ctor()' in the assembly 'TextFlowMobile.iOS.exe': Object reference not set to an instance of an object TextFlowMobile.iOS

My code for this renderer, that is for WKWebView is as follows:

`[assembly: ExportRenderer(typeof(WebView), typeof(IOSWebViewRenderer))]  
namespace TextFlowMobile.iOS.Renderers  
{  
    public class IOSWebViewRenderer : WkWebViewRenderer  
    {  
        public override WKNavigation LoadHtmlString(NSString htmlString, NSUrl baseUrl)  
        {  
            try  
            {  
                if(htmlString != null && baseUrl != null)  
                {  
                    // Add additional HTML to ensure fonts scale correctly and don't appear extremely small and almost unreadable  
                    var iOSHtmlWithScaling = htmlString.ToString().Insert(0, "<meta name='viewport' content='width=device-width,initial-scale=1,maximum-scale=1' />");  
                    return base.LoadHtmlString((NSString)iOSHtmlWithScaling, baseUrl);  
                }  
                else  
                {  
                    return base.LoadHtmlString(htmlString, baseUrl);  
                }  
            }  
            catch (Exception)  
            {  
                //System.Diagnostics.Debug.WriteLine(ex);  
                return base.LoadHtmlString(htmlString, baseUrl);  
            }  
        }  
    }  
}`  

As you can see, I don't override the constructor at all. I really don't see why this happens, especially since it builds (and deploys on a simulator on the connected mac) perfectly fine for debug.

My current config is Release | iPhone | ProjectName.iOS | Remote Device

I really appreciate any help!81631-screenshot-2021-03-25-153805.png

Developer technologies | .NET | Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Jamie Colclough 1 Reputation point
    2021-03-29T16:12:03.697+00:00

    This error occurred because I had an Obfuscator running on the release version of the code. When I tried to archive this, I imagine it couldn't properly compile this renderer because it was obfuscated.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.