1

When trying to generate a pdfHtml report in Xamarin.Forms using a .netStandard2 project, the exception System.ArgumentNullException: 'Value cannot be null. Prameter name: assembly.

enter image description here

This is the code that is run:

var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Data.test.html";

using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
using (FileStream pdfDest = File.Open(targetPath, FileMode.Create))
{
    string result = reader.ReadToEnd();
    ConverterProperties converterProperties = new ConverterProperties();
    HtmlConverter.ConvertToPdf(result, pdfDest, converterProperties);
}

The code works, when run in a .net6 console application.

rherzog
  • 51
  • 9

1 Answers1

0

You could check the resourceName. Please refer to Xamarin.Forms Can not Read Text file from Resources Returned Null. One way to get the resourceName of all the project is using:

assembly.GetManifestResourceNames() //get all resource

var resourcePath = assembly.GetManifestResourceNames()
        .Single(str => str.EndsWith("filename.html"));  // get your html resource 

Also remember to set the build action of the file to EmbeddedResource.

Hope it works for you.

Liqun Shen-MSFT
  • 3,490
  • 2
  • 3
  • 11