Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jan 07, 2015 12:50 pm

I have an odd problem running spire.pdf on asp.net web application. I have read the forums and apparently the spire.pdf is PartiallyTrustedCallers ready. However, I have just download the free version of the product and I am impressed how quickly it generates a single page PDF from a HTML string.

The site is hosted with fasthosts and while they are the biggest in the UK they are also the most restrictive in app development. The app was developed using VS2008 and .Net3.5. There are no intentions to upgrade to .Net4 but the site has been compiled in VS2013 for testing purposes.

The web runs and creates the pdf in the dev environment but when I upload it to the hosted if get a Required Permissions Cannot Be Acquired error. I don't know if this is because of the hosting company or the DLL itself but when I remove the DLL from the bin directory the site starts to work. The error returned is below and shows that the DLL that is trying to acquire the security policy is the spire.pdf. I have also logged this with fasthosts.

thanks for your help.

Mario
===============================================================================
Server Error in '/' Application.

Required permissions cannot be acquired.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Policy.PolicyException: Required permissions cannot be acquired.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[PolicyException: Required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7612419
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57

[FileLoadException: Could not load file or assembly 'Spire.Pdf, Version=3.0.26.56035, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'Spire.Pdf, Version=3.0.26.56035, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600
System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
System.Web.Compilation.BuildManager.CompileResourcesDirectory() +31
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +304

[HttpException (0x80004005): Could not load file or assembly 'Spire.Pdf, Version=3.0.26.56035, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Could not load file or assembly 'Spire.Pdf, Version=3.0.26.56035, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8993635
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333

Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Thu Jan 08, 2015 6:14 am

Dear MSetubal,

Thanks for your inquiry.

After some investigation, I guess this is an issue with the .NET Framework's trust level settings. Please refer to links below to get more information and have a try:
http://support.softartisans.com/kbview_1273.aspx
https://social.msdn.microsoft.com/Forum ... m=netfxbcl
http://blogs.msdn.com/b/shawnfa/archive ... 76066.aspx
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Jan 12, 2015 8:10 am

Hello MSetubal,

Have you tried the solution I provided to resolve this problem? Did it work?

Looking forward to your response.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Jan 12, 2015 9:58 am

Hi,

the problem is that I don't have access to the hosting providers .net framework security settings. I have passed your comments to fasthosts and I am waiting for their reply.

The spire.pdf works perfectly in my test environment or even in my dedicated server with fasthosts, however, as soon as I move it to a hosted environment it fails.

Also, are there any other dependencies or all I need to upload is the two spire files, the .net and the licence file?

regards,

Mario

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Tue Jan 13, 2015 2:05 am

Hello MSetubal,

Yes, you should upload Spire.Pdf.dll and Spire.License.dll to your server. If you have purchased our product, you should upload your license file (eg:license.elic.xml) too.

BTW: can you provide us your hosted environment detailed information? Thank you.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Tue Jan 13, 2015 9:17 pm

I am taling to fasthosts to try and address the issue. The application was built using VS2008 and .Net3.5 framework. There is a third party DLL, Daypilot which is used as a calendar/scheduler. The application runs fine if I remove the spire dlls from the bin directory, but of course will not create PDFs.

The hosting environment runs on one of the shared hosting and you can see the package by following the url - can't post urls :( but got to
www fasthosts co uk
and hosting business-gold

This application uses MySQL and the MySQL .NET Connector version 6.9.3.0

I never had any problems running the application on a dedicated virtual server, but now it needs to run on a shared hosted environment and at the moment Fasthosts have not been very helpful, however, they are showing a bit more interest.

you can see the error at
www activejersey com


if you need more info, please do come back to me.

kind regards,

Mario

oh, and apparently your forum does not let me post URLs :)

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Wed Jan 14, 2015 2:53 am

Hello MSetubal,

Thanks for sharing your information.

From our dev team message, Free Spire.Pdf did have some limitations, but we're not sure what the situation you met. Did this problem occurs when you load the dll or just make the conversion (you mentioned that you want to convert html string to pdf)?
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Thu Jan 15, 2015 8:35 am

Hello MSetubal,

How is it going with this problem? You website works well now?

Looking forward to your response.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Sat Jan 17, 2015 12:44 am

Hi,

sorry for the late reply. The problem occurs only when the site is published to the shared hosting environment. In Dev everything work really well but in the live environment the site doesn't even load, it crashes at the home url.

The Fasthosts team have gone quiet, I guess that they may have drawn a blank as well. The problem here is why would the DLLs be loading without any call being made to them? The site url is www-activejersey.com (replace the - with a .) and the dll only gets called at www-activejersey.com/admin/view/giftvoucher.aspx - otherwise it doesn't get called at all.

I am going to test this on another server and see how I get along, maybe it will provide me with some other error or it even may just work :)

will keep you posted.

Mario

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Sat Jan 17, 2015 12:47 am

Also, the code that generates the PDF is below.
Maybe it's because it needs to run in its own thread???

Private Sub GeneratePDF()
Dim thread As Thread = Nothing
thread = New Thread(New ThreadStart(AddressOf GeneratePDF))
thread.SetApartmentState(Threading.ApartmentState.STA)
thread.Start()
thread.Join()
System.Diagnostics.Process.Start("giftvoucher.pdf")
End Sub

Private Sub GeneratePDF()
'spire pdf creator
Dim pdfDocument As New PdfDocument

Dim pdfHTMLLayout As New HtmlConverter.PdfHtmlLayoutFormat
pdfHTMLLayout.IsWaiting = False
Dim pdfPageSettings As New PdfPageSettings
pdfPageSettings.Size = PdfPageSize.A4
pdfDocument.LoadFromHTML(mVoucherPreview, True, pdfPageSettings, pdfHTMLLayout)

pdfDocument.SaveToFile("giftvoucher.pdf")
pdfDocument.Close()

End Sub

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Sat Jan 17, 2015 9:21 am

Right, here is an update on my testing on a windows 2008 r2 server with .Net 3.5.1 Framework.

I uploaded the site to the server and initially I got errors with the trust levels for my crystal report DLLs, i removed any references to these and re-uploaded the web.config file. the site started and all looked fine. The framework levels are set to full trust for that website, however, when I go to the url that calls the PDF creation, the application pool where the site is running crashes, initially I get 4 5011 errors then -
A process serving application pool '%1' suffered a fatal communication error with the Windows Process Activation Service. The process id was '267''. The data field contains the error number.
and 1 error shutting down the application pool - [code]Application pool '%1' is being automatically disabled due to a series of failures in the process(es) serving that application pool.[/code.

The above happens with the .net framework being set to full trust. however, as soon as I set the application .net framework trust level to medium, the application fails with the
Required permissions cannot be acquired.
error, which suggests that the DLL is not Partially Trusted Callers ready. However, I have just checked and the assembly is partially Trusted Callers ready, but the License.dll is not and I wonder if the error is generated by that file instead of the spire.pdf.dll?

I removed all traces of the license dll from the bin and the application pool still crashes :( but this time with 509 errors -
A process serving application pool '%1' terminated unexpectedly. The process id was '2260'. The process exit code was '0xe0434f4d'.


if i remove the section that calls the dll then the site runs fine, but i still have to ask the question, why does it run in dev???? without any problems?????

regards and thank you for your assistance,

Mario

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Mon Jan 19, 2015 6:24 am

Hello MSetubal,

Thanks for sharing your information.

We'll do some investigation about this problem and let you know ASAP.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Tue Jan 20, 2015 9:22 am

Hello MSetubal,

Please try the commercial version to see if this problem happen again.
And the new version of Free Spire.PDF is Free Spire.PDF v3.2, please try that.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Sat Jan 31, 2015 9:03 am

Thanks, I have downloaded the newer version but i still get the error. I have also tried it it the commercial version but still the same. neither version works with Fasthosts hosting provider.

oh, well better find some other solution.

thanks for your help.

Mario

MSetubal
 
Posts: 7
Joined: Wed Jan 07, 2015 11:54 am

Mon Feb 02, 2015 3:47 am

Hello MSetubal,

Please feel free to contact us if you have any questions.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.PDF