0

I'm trying to add a network security config file to an Android app built with Xamarin tools. (Xamarin forms version 2.5.1.527436).

I followed the steps in this article: https://devblogs.microsoft.com/xamarin/cleartext-http-android-network-security/

My network_security.config.xml file just contain two TLS overrides for sites accessed by an in-app browser, and where https/tls can't be enabled server-side at this point:

<?xml version="1.0" encoding="utf-8" ?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">xxx.somedomain.com</domain> <domain includeSubdomains="true">yyy.somedomain.com</domain> </domain-config> </network-security-config> 

In the AndroidManifest.xml file I just added android:networkSecurityConfig="@xml/network_security_config":

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.somecompany.someapp" android:versionName="1.2.3 (October 2019)" android:versionCode="3" android:installLocation="auto"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" /> ... <application android:largeHeap="true" android:label="Some App Name" android:icon="@drawable/icon" android:theme="@style/AppTheme" android:networkSecurityConfig="@xml/network_security_config"> ... </application> </manifest> 

However, on startup, the call to Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication throws a null reference exception without any further details.

[0:] System.NullReferenceException: Object reference not set to an instance of an object. at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0005e] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:315 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:343 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0025c] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:139 at SomeApp.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x001db] in D:\work\xxx\MainActivity.cs:173 

I'm not sure if I am missing something, or if there is some Xamarin version dependency involved when adding a network security config file..? Any ideas?

3
  • I suggest that you can firstly update the version of Xamarin.Forms to 4.2.x . Such an old version maybe will have some unknown issue . Commented Oct 15, 2019 at 7:58
  • Thanks @LucasZhang-MSFT - you are correct. After upgrading to XF 4.2.x it works. If you add that as an answer to this question instead of as a comment, I'll mark it as the correct answer for this issue. Commented Oct 15, 2019 at 10:05
  • I have posted it :) Commented Oct 15, 2019 at 13:29

1 Answer 1

1

It seems that the version of xamarin.forms in your app is still 2.5.x ,and the newest version is 4.2.x . So firstly I suggest you can update it .Otherwise ,there will maybe have some unknown issue because of compatibility .

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.