title: FileProvider.GetUriForFile crashes with null reference exception in Xamarin-Android
body: <p>I have a Xamarin application in which I want to open files attached to a data row with the default application for that type (doc, pdf, txt, jpg, etc.) So when the user taps on an ListItem containing the names of the attached files I want to open that file.</p>
  
  <p>I am testing the Android part of it and when it gets to</p>
  
  <pre><code>FileProvider.GetUriForFile(blablabla see below
  </code></pre>
  
  <p>it crashes with:</p>
  
  <p>Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference</p>
  
  <p>I get the attached files from the application server and write it to </p>
  
  <pre><code>Environment.SpecialFolder.Personal
  </code></pre>
  
  <p>I have checked if it is really written there and it is there.</p>
  
  <p>The code is from here: <a href="https://forums.xamarin.com/discussion/124361/unable-to-open-pdf-into-the-third-party-app" rel="nofollow noreferrer">https://forums.xamarin.com/discussion/124361/unable-to-open-pdf-into-the-third-party-app</a></p>
  
  <p>and it is:</p>
  
  <pre><code>public void OpenFileByName(string filenameWithPath)
  {
      try
      {
          string application = "";
          string filename = Path.GetFileName(filenameWithPath);
          string extension = Path.GetExtension(filename);
  
          // get mimeType
          if (extension != null)
              switch (extension.ToLower())
              {
                  case ".txt":
                      application = "text/plain";
                      break;
                  case ".doc":
                  case ".docx":
                      application = "application/msword";
                      break;
                  case ".pdf":
                      application = "application/pdf";
                      break;
                  case ".xls":
                  case ".xlsx":
                      application = "application/vnd.ms-excel";
                      break;
                  case ".jpg":
                  case ".jpeg":
                  case ".png":
                      application = "image/jpeg";
                      break;
                  default:
                      application = "*/*";
                      break;
              }
          Java.IO.File file = new Java.IO.File(filenameWithPath);
  
          file.SetReadable(true);
          Android.Net.Uri uri = Android.Support.V4.Content.FileProvider.GetUriForFile(Android.App.Application.Context, "com.example.asd.fileprovider", file);
  
          Intent intent = new Intent(Intent.ActionView);
          intent.SetDataAndType(uri, application);
          intent.AddFlags(ActivityFlags.GrantReadUriPermission);
          intent.AddFlags(ActivityFlags.NoHistory);
          intent.AddFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
  
          try
          {
              Android.App.Application.Context.StartActivity(intent);
          }
          catch (Exception)
          {
              Toast.MakeText(Android.App.Application.Context, "No Application Available to View this file.", ToastLength.Short).Show();
          }
      }
      catch (Exception ex)
      {
          Toast.MakeText(Android.App.Application.Context, ex.Message, ToastLength.Short).Show();
      }
  }
  </code></pre>
  
  <p>AndroidManifest.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
            android:versionCode="1"
            android:versionName="1.0"
            package="com.example.asd"
            android:installLocation="auto"&gt;
    &lt;provider
      android:name="android.support.v4.content.fileProvider"
      android:authorities="com.example.asd.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true"&gt;
      &lt;meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/filepaths" /&gt;
    &lt;/provider&gt;
    &lt;uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Android/Resource/xml/filepaths.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;paths xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;external-path name="external_files" path="."/&gt;
    &lt;files-path name="media"/&gt;
    &lt;files-path name="images"/&gt;
    &lt;files-path name="docs"/&gt;
    &lt;files-path name="download"/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>Android/Resources/drawable/file_provider_path.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;paths&gt;
      &lt;external-path name="download" path="download/"/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>What is wrong here?</p>