Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document.Save() throws NullReferenceException on OSX #22

Open
svantreeck opened this issue Apr 23, 2019 · 22 comments
Open

Document.Save() throws NullReferenceException on OSX #22

svantreeck opened this issue Apr 23, 2019 · 22 comments
Assignees

Comments

@svantreeck
Copy link

I am running into a NullReferenceException using Aspose.PDF 19.4 in my own application and narrowed it down to the Save method on a Document. To make sure it wasn't my code causing the issue, I tried running the hello world example in this repo but tweaked to save to a stream to match how my app was working, and got the below error. Any ideas how to fix this?

            // Initialize document object
            Document document = new Document();
            // Add page
            Page page = document.Pages.Add();
            // Add text to new page
            page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World!"));
	   // Save updated PDF
			using (var stream = new MemoryStream())
			{
				document.Save(stream);
			}
            // ExEnd:1  
System.NullReferenceException: Object reference not set to an instance of an object
  at #=zrfrUImb7jZrPxl6ucZ5zNV9DARLP.#=zrIGtZ6o= (#=z7yZ2j1uLuKOW3Mjv7iBPtwH3Y3ZT #=zvgUMzhxilvJ$) [0x00014] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=zf5Xplt8SxpLmjY2gnjKga9k=.#=zCHp0IXk= (#=z7yZ2j1uLuKOW3Mjv7iBPtwH3Y3ZT #=zvgUMzhxilvJ$) [0x00035] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zs919QWqrlYGtp0d8HnE2iVs= (System.Object #=znOmGh_c=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zbuTtbUQf9v4z9CLlfpkWc5NONpP1NH61Xg== (System.Object #=znOmGh_c=) [0x00025] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zD1z8jhB_bImTFA1KQH_CXh8= (System.Reflection.MethodBase #=znOmGh_c=, System.Boolean #=zKJQ1vAs=) [0x0020c] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zr1qAW2dJZU56Fifz$DRtrJQ= (#=qA0cVKYayviYAiKvxD3jKmFCvKBcZO1cuNkLywGPCX4s= #=znOmGh_c=) [0x00029] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zjQ2kpb7QJHXuCFyqDIfbc6bxeif3Guj2t5kRHFY= () [0x0006f] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zoZhjcbxKCu1OlfqNiZQyhtBOhMag () [0x00005] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zs919QWqrlYGtp0d8HnE2iVs= (System.Object #=znOmGh_c=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zbuTtbUQf9v4z9CLlfpkWc5NONpP1NH61Xg== (System.Object #=znOmGh_c=) [0x00025] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zeDxoLlmnn6sLuiwJZ3kySdEqr9Qm () [0x00021] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zQuJefDFFUH6arI2RL7Xny4w= (#=qA0cVKYayviYAiKvxD3jKmFCvKBcZO1cuNkLywGPCX4s= #=znOmGh_c=) [0x00005] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zjQ2kpb7QJHXuCFyqDIfbc6bxeif3Guj2t5kRHFY= () [0x0006f] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zoZhjcbxKCu1OlfqNiZQyhtBOhMag () [0x00005] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zs919QWqrlYGtp0d8HnE2iVs= (System.Object #=znOmGh_c=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zbuTtbUQf9v4z9CLlfpkWc5NONpP1NH61Xg== (System.Object #=znOmGh_c=) [0x00025] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zeDxoLlmnn6sLuiwJZ3kySdEqr9Qm () [0x00021] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zyEPA4nnEbHwoj0a0kw== (System.Object #=znOmGh_c=, System.UInt32 #=zKJQ1vAs=) [0x0016f] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zoZhjcbxKCu1OlfqNiZQyhtBOhMag () [0x0001e] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zXiHq1JqAXT1nVsgy7_u_4Co= () [0x00066] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=z5$W8JnZoxMUxFZCZ9nBeVsRX25Eiv12nKg== () [0x00005] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zs919QWqrlYGtp0d8HnE2iVs= (System.Object #=znOmGh_c=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zbuTtbUQf9v4z9CLlfpkWc5NONpP1NH61Xg== (System.Object #=znOmGh_c=) [0x00025] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zeDxoLlmnn6sLuiwJZ3kySdEqr9Qm () [0x00021] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zyEPA4nnEbHwoj0a0kw== (System.Object #=znOmGh_c=, System.UInt32 #=zKJQ1vAs=) [0x0016f] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=z5$W8JnZoxMUxFZCZ9nBeVsRX25Eiv12nKg== () [0x00024] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zQ5pdWvrfMJWQpyweT_AkOQA= (System.Object[] #=znOmGh_c=, System.Type[] #=zKJQ1vAs=, System.Type[] #=zLQM$Grw=, System.Object[] #=zkxlc94Q=) [0x000b0] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zmDDIFHbuPCYW5n5B6w== (System.IO.Stream #=znOmGh_c=, System.String #=zKJQ1vAs=, System.Object[] #=zLQM$Grw=, System.Type[] #=zkxlc94Q=, System.Type[] #=zx3KnP8k=, System.Object[] #=zmd0rShU=) [0x00010] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zvzW4XjAI4ieAQmFs5zIGtvMzO0v6ctZBpel8OF4= (System.IO.Stream #=znOmGh_c=, System.String #=zKJQ1vAs=, System.Object[] #=zLQM$Grw=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at #=qBVcPFVNsk1VCnIglM9dyb854eZvi1sYdOocJizgIlOs=.#=zTrgnC51gLkD5hJWbJTysEN5HzUSZa6TI3j8OR_8= (System.IO.Stream #=znOmGh_c=, System.String #=zKJQ1vAs=, System.Object[] #=zLQM$Grw=) [0x00000] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at Aspose.Pdf.Document.#=zaQMY1WxSvSde (System.IO.Stream #=z_scZQvM=, Aspose.Pdf.SaveOptions #=zVOKmEcCtwEbL) [0x00141] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at Aspose.Pdf.Document.Save (System.IO.Stream output) [0x00009] in <6cf8ce1e23124d98df6de66c2a643c37>:0
  at Aspose.Pdf.Examples.CSharp.AsposePDF.QuickStart.HelloWorld.Run () [0x00036] in /Aspose.PDF-for-.NET/Examples/CSharp/AsposePDF/QuickStart/HelloWorld.cs:26
  at Aspose.Pdf.Examples.CSharp.RunExamples.Main () [0x00017] in /GitHub/Aspose.PDF-for-.NET/Examples/CSharp/RunExamples.cs:69

@svantreeck
Copy link
Author

Also, this happens on netstandard 2.0/NetCoreApp 2.2 with a different stack trace using the 19.4 nuget package:

Exception thrown: 'System.NullReferenceException' in Aspose.Pdf.dll: 'Object reference not set to an instance of an object.'
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=zXBtwSBLzda2_G9a41IF5YQs=(Object #=zqRDmNVM=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=znGTCst0AWNesiDvV6Eq4rllDm2ulZ$3xQh5Vh_objbuj()
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=zSR2Tpot4nMtwQdYXI3xLlt0EJytNe6busA==(Object #=zqRDmNVM=, UInt32 #=zX$ZZP8I=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=z_qrD3AVS0GsHKyOIoWKkNiwWfmfYeA23UA==(Boolean #=zqRDmNVM=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=z_qrD3AVS0GsHKyOIoWKkNiwWfmfYeA23UA==(Boolean #=zqRDmNVM=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=z$SpgjR37J_YbwNc_D3_giTaCbBCxqRCyjw==()
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=zvNKzj4lUeqJEMgAPlxiCz6I0fscgSFlqd5oY2M0=(Object[] #=zqRDmNVM=, Type[] #=zX$ZZP8I=, Type[] #=zCq$X$PI=, Object[] #=zC1Gb71M=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=zYtbayufKcJpqUGOACug$yR9fosEe2J6jT85tdurYPYqE(Stream #=zqRDmNVM=, String #=zX$ZZP8I=, Object[] #=zCq$X$PI=, Type[] #=zC1Gb71M=, Type[] #=zAFl0CXU=, Object[] #=ziTWLoW8=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=zXHZm77uSJ3f9Vt8P$wEQoQTEwPFe(Stream #=zqRDmNVM=, String #=zX$ZZP8I=, Object[] #=zCq$X$PI=)
   at #=qiU5gKTVK86AarXYAnvaBOxQOA0XVDuZru00A9_AYga4=.#=z6YuiouYDF8q3F6vgeUpLxyDEk5_9(Stream #=zqRDmNVM=, String #=zX$ZZP8I=, Object[] #=zCq$X$PI=)
   at Aspose.Pdf.Document.#=zc987sPODI9gV(Stream #=zUBYR2bw=, SaveOptions #=zalZVzje3NyLF)
   at Aspose.Pdf.Document.Save(Stream output)

@farhan-raza
Copy link
Member

@svantreeck

Thank you for contacting support.

We are investigating it in our environment and will get back to you with our findings soon.

PS: I work with Aspose as Developer Evangelist.

@farhan-raza
Copy link
Member

farhan-raza commented May 16, 2019

@svantreeck

Thank you for being patient.

We have tested the scenario with Aspose.PDF for .NET 19.5 in MacOS version 10.14.4 Mojave, but the problem did not reproduce. Would you please share a sample application with us so that we may investigate further and help you out.

@farhan-raza farhan-raza self-assigned this May 16, 2019
@SergeySagan
Copy link

I am also having this issue. It works when I run locally, but when deployed to our kubernates Debian environment, getting the same error as described in the original post.

@brianjbeach
Copy link

I am seeing the same on OSX. This is the simplest example I could dream up to repro.

var file = new Aspose.Pdf.Document("origianl.pdf");
file.Save("new.pdf");

@asadalikhan90
Copy link
Collaborator

@brianjbeach
@serjster
@svantreeck

In order to use the API in a non-Windows environment, please make sure to install the following packages:

  • libgdiplus package
  • Microsoft Core Fonts (msttcorefonts package)

Please note that such exceptions are usually caused due to the absence of required fonts. Please try to install the suggested packages in your system and in case you still face the issue, please let us know.

@abdul-kurtosys
Copy link

abdul-kurtosys commented Nov 5, 2020

Having this same issue with the Aspose.PDF 20.10 on MacOS version 10.15.7 Catalina

I attempted to install libgdiplus via brew https://formulae.brew.sh/formula/mono-libgdiplus

I also have office installed so I should have the Microsoft Core Fonts installed

@asadalikhan90
Copy link
Collaborator

@abdul-kurtosys

Are you facing this issue while processing an existing PDF document or creating a new one from scratch? Please share some more details of the scenario along with the sample code snippet that you are using. Also, please try using Aspose.PDF for .NET 20.12 and let us know if an issue still persists.

PS: It is recommended to post such issues in our official forum where they can be addressed and tracked appropriately.

@xopxop
Copy link

xopxop commented Apr 21, 2021

https://docs.aspose.com/pdf/net/hello-world-example/
I came across the same problem with this example. It crashed right at the document.save() method
I am using macOs Big Sur v11.2.3

@mudassirfayyaz
Copy link

@xopxop
I have recently configured libgdiplus on macOs Big Sur v11.2.3. You need to use the Mac Terminal and with sudo please execute following two commands in order. I hope this will resolve all the dependencies on your end and will install the package.

xcode-select --install
brew install mono-libgdiplus

@danielgran
Copy link

Same on here, any updates?
Offical Thread gets no updates, too.
https://forum.aspose.com/t/null-reference-error-while-saving-the-document/15342

@asadalikhan90
Copy link
Collaborator

@danielgran

We regret to inform you that the earlier logged ticket is not yet resolved. The issue is currently under the phase of the investigation. We have also posted an update in the original official thread. You may please follow up there about progress on issue resolution.

We apologize for the inconvenience caused due to this bug.

@danielgran
Copy link

@asadalikhan90

This issue is open since 4 years now.

I found a rather messy workaround checking if every page is saveable.
You guys dont mind fixing this asap? :D

Greeting

@asadalikhan90
Copy link
Collaborator

asadalikhan90 commented Apr 27, 2021

@danielgran

Please accept our humble apology for the inconvenience you have been facing. Sometimes, the resolution of an issue takes more time due to the nature of the issue's complexity. Some issues are dependant upon various internal components of the API and in order to fix them, a lot of work is required. These are some factors that cause a delay in issue resolution. Nevertheless, we have recorded your concerns and escalated the issue to the next level of priority. We will surely inform you as soon as it is rectified.

We again apologize for the trouble caused.

@prasad-varade
Copy link

@asadalikhan90

Any updates on this?

At least mention in the documentation it's not supported on mac os.

@asadalikhan90
Copy link
Collaborator

@danielgran , @prasad-varade ,

We would like to share with you that the earlier logged issue has been resolved in Aspose.PDF for .NET 21.6. The bug fix notification has already been sent in the official thread as well. Please use the latest version of the API and let us know in case you face any issues.

@Stepos36
Copy link

@asadalikhan90 The update does not appear to have fixed the issue for me.

@asadalikhan90
Copy link
Collaborator

@Stepos36

Can you please confirm if you have installed msttcorefonts and libgdiplus packages in your environment? Please check if these packages are correctly installed and let us know about OS Name and Version in which you are facing this issue. Are you experiencing the same exception that is mentioned in this thread?

@Stepos36
Copy link

Stepos36 commented Jun 23, 2021

@asadalikhan90 I was able to resolve the issue by installing all the Latin fonts I have on my local machine into the container. The container runs on Windows. The exception and symptoms were more less the same. I updated the Aspose.Pdf version to 21.6.0 but it didn't resolve the issue. It was really confusing and took me about a full day of investigation. If, instead of a NullReferenceException, it gave a clear message, something like "Your local environments is missing fonts required for saving the document", it would save me (and anyone who runs into the issue) a plenty of time.

@asadalikhan90
Copy link
Collaborator

@Stepos36

We apologize for the inconvenience being faced. We have recorded your concerns and generated another ticket i.e. PDFNET-50116 in our issue management system to implement proper Exception Message in such cases. We will surely look into its details and let you know as soon as the ticket is resolved.

@pdxuan
Copy link

pdxuan commented Oct 24, 2021

@asadalikhan90 any update for this err, I got this error too

@asadalikhan90
Copy link
Collaborator

@Xuan-Spider

Can you please explain which error you are you getting? The Original issue in this thread was already resolved in 21.6 version of the API. The reason behind the issue was absence of the required font(s). Please go through the above discussion and comments and try to install the required fonts in your system. In case issue still persists, please let us know by creating a new topic in Aspose.PDF official support forum where we will further proceed to assist you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests