We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Error when saving PDF file, not captured with Try/Catch

I've taken a close look at the processing and noted that the line of code:
Xamarin.Forms.DependencyService.Get().SaveAndView("Output.pdf", "application/pdf", stream);

Generates the error:
"One or more errors occurred. (/storage/emulated/0/Syncfusion/Output.pdf (No such file or directory))"

This error is not being captured by a Try/Catch  so instead of sample code I just need assistance if figuring out this error.


6 Replies

SK Surya Kumar Syncfusion Team July 8, 2019 04:28 AM

Hi John, 

Greetings from Syncfusion. 

We have created a simple sample to create and save PDF in Xamarin and it can be downloaded from below link: 
You can also find the step by step procedure for creating PDF in Xamarin below: 

Kindly refer the same and let us know if you need any further information. 


Regards, 
Surya Kumar 



JW john warns July 9, 2019 04:38 AM

I've gone completely around the problem by pushing the memory stream directly to the PDF viewer and skipping the save step.  but in doing so I noticed something strange, even though I have a community license a header appears indicating that my instance of PDF is a trial version, what gives??????




so your application on my system (VS 2019 with all of the latest updates applied) failed with these 3 errors:  also Forms.Context is obsolete, not sure what that's doing to the app and   public async Task SaveAndView(string fileName, String contentType, MemoryStream stream) throws and error as there is no await.  Does this really save to the root (  Xamarin.Forms.DependencyService.Get().SaveAndView("Output.pdf", "application/pdf", stream);)  And then attempt to read from the Assets folder.  shouldn't it be something like Xamarin.Forms.DependencyService.Get().SaveAndView("/Assets/Output.pdf", "application/pdf", stream);?



Severity Code Description Project File Line Suppression State
Error CS1566 Error reading resource 'GettingStarted.Assets.sample.pdf' -- 'Could not find file 'C:\Users\johnw\Downloads\Sample_xamarin-1505448411\Sample_xamarin\GettingStarted\GettingStarted\GettingStarted\Assets\sample.pdf'.' GettingStarted C:\Users\johnw\Downloads\Sample_xamarin-1505448411\Sample_xamarin\GettingStarted\GettingStarted\GettingStarted\CSC 1 Active

Severity Code Description Project File Line Suppression State
Error  The "LinkAssemblies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'GettingStarted.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'GettingStarted.Android.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() GettingStarted.Android   

Severity Code Description Project File Line Suppression State
Error  The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'C:\Users\johnw\Downloads\Sample_xamarin-1505448411\Sample_xamarin\GettingStarted\GettingStarted\GettingStarted\bin\Debugetstandard2.0\GettingStarted.dll'.
File name: 'C:\Users\johnw\Downloads\Sample_xamarin-1505448411\Sample_xamarin\GettingStarted\GettingStarted\GettingStarted\bin\Debugetstandard2.0\GettingStarted.dll'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at Xamarin.Android.Tools.Files.HashFile(String filename, HashAlgorithm hashAlg)
   at Xamarin.Android.Tools.Files.HashFile(String filename)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() GettingStarted.Android   



JW john warns July 10, 2019 02:56 AM

I've gone completely around the problem by pushing the memory stream directly to the PDF viewer and skipping the save step.  but in doing so I noticed something strange, even though I have a community license a header appears indicating that my instance of PDF is a trial version, what gives??????


SL Sowmiya Loganathan Syncfusion Team July 10, 2019 05:04 AM

Hi John, 

I've gone completely around the problem by pushing the memory stream directly to the PDF viewer and skipping the save step.  but in doing so I noticed something strange, even though I have a community license a header appears indicating that my instance of PDF is a trial version, what gives?????? 
We would like to let you know that Syncfusion introduced the licensing system from v16.2.0.41 only for Syncfusion NuGet packages and evaluation setup. You have to generate the license key (not unlock key) and register it when the launch of your application as specified in the below help documents if you referring the assemblies from Syncfusion NuGet packages or from the evaluation setup.       
       
 
As Syncfusion license keys are version and platform specific, kindly generate and register the corresponding platform license key for the required version in your application by following the below KB article.        
Also, please refer to this blog post for understanding the licensing changes introduced in Essential Studio.      

so your application on my system (VS 2019 with all of the latest updates applied) failed with these 3 errors:   
We have analysed the provided stack trace and modified the sample to overcome the issue. Please find the sample for the same from below link, 


Kindly try the above sample in your end and let us know if it solves the issue. 



Regards, 
Sowmiya L 



JW john warns July 11, 2019 03:11 AM

Key generation does not seem to function.  I've 17.2.0.34 installed, all platforms.  Pressing the "Get License Key" does nothing.




VN Vadivel Natarajan Syncfusion Team July 11, 2019 03:59 AM

Hi John, 
 
We have posted the response for the reported ‘license key generation not working’ issue in incident # 241596. Hence, please follow up the incident #241596 for further updates.  
 
Regards, 
Vadivel Natarajan  


Loader.
Live Chat Icon For mobile
Up arrow icon