File IO Permission when legacyCasModel="true"

Last post 09-02-2011, 9:58 AM by AndreyN. 8 replies.
Sort Posts: Previous Next
  •  08-30-2011, 10:06 AM 325302

    File IO Permission when legacyCasModel="true" .NET

    We need to have the following in our web.config system.web section so that Microsoft reports localreport processing works correctly in our web app:
    <trust legacyCasModel="true" level="Full"/>

    However, having this line is cause Aspose Words 10.3 to fail with a FileIOPermission violation on any IO including reading it's own license file. If I remove the trust property from the web.config then the Aspose code works correctly and renders a DocX to PDF as desired.

    Problem is I can't remove the trust setting to fix Aspose Words as that will break the Microsoft localreport processing. I'm pursuing trying to find a better work around for the localreport processing problem other than adding the trust element -- but why is Aspose Words hung up on that parameter being there? Is there a work around for Aspose including deliberately using an older version?
     
  •  08-31-2011, 1:06 AM 325388 in reply to 325302

    Re: File IO Permission when legacyCasModel="true"

    Hi

     

    Thanks for your request. I do not think the problem is related to Aspose.Words. If the problem occurs when you try to set the license, then you can try reading the license into a stream (for testing purposes). If the exception will occur upon reading the license file to stream you can guess the problem is causes by permissions issues, but not by Aspose.Words.

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-31-2011, 10:06 AM 325585 in reply to 325388

    Re: File IO Permission when legacyCasModel="true"

    I disagree - there is a problem with Aspose Words!

    If the following appears in the ASP.NET Framework 4.0 web app's web.config system.web section:
    <trust legacyCasModel="true" level="Full"/>

    Aspose Words 10.3 fails with a FileIOPermission violations on any IO, period. If you remove that trust code, then Aspose Words works correctly.

    Easy to reproduce problem - try it, create a simple template ASP.NET web app in VS2010 and run with /without the trust attribute.

    This problem and your response is a show stopper for us due to legacy stuff we must support via the legacyCasModel trust attribute so we are going to have to consider other alternatives to Aspose Words for saving Word to PDF programmatically in C#.
     
  •  08-31-2011, 11:27 AM 325592 in reply to 325585

    Re: File IO Permission when legacyCasModel="true"

    Hi

     

    Thank you for additional information. But unfortunately, I cannot reproduce the problem on my side. Could you please create a simple application that will allow me to reproduce the problem?

    Also, have you tried reading the license file into stream as I suggested? Does the exception occur in this case?

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-01-2011, 1:12 AM 325659 in reply to 325592

    Re: File IO Permission when legacyCasModel="true"

    Hi

     

    Thank you for additional information. I received the test application. But unfortunately, I still cannot reproduce the problem on my side. The document is converted to PDF without any problems on my side.

    Could you please show me a full stack trace of the exception and specify in which line of code it occurs?

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-01-2011, 12:49 PM 325825 in reply to 325659

    Re: File IO Permission when legacyCasModel="true"

    Other information - this problem is only happening with VS2010 Pro on Windows 7 Enterprise development PC. Same problem does not happen on with VS2010 on Windows XP Pro development PC. Untested on WinSvr 2008 as yet which is ultimate deploy target.

    Full trace follows:

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
       at System.Security.CodeAccessPermission.Demand()
       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)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
       at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
       at Aspose.Words.Document..ctor(String fileName, LoadOptions loadOptions)
       at Aspose.Words.Document..ctor(String fileName)
       at WebAsposeTest._Default.Button1_Click(Object sender, EventArgs e) in C:\fark2\WebAsposeTest\Default.aspx.cs:line 26
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.FileIOPermission
    The first permission that failed was:
    <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Read="c:\H41-IN\SBS\sbs-new-baseline-1.docx"/>

    The demand was for:
    <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Read="c:\H41-IN\SBS\sbs-new-baseline-1.docx"/>

    The granted set of the failing assembly was:
    <PermissionSet class="System.Security.PermissionSet"
    version="1">
    <IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Access="Open"/>
    <IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Allowed="ApplicationIsolationByUser"
    UserQuota="1024000"/>
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="Execution"/>
    <IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Window="SafeTopLevelWindows"
    Clipboard="OwnClipboard"/>
    <IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    PublicKeyBlob="00240000048000009400000006020000002400005253413100040000010001005542E99CECD28842DAD186257B2C7B6AE9B5947E51E0B17B4AC6D8CECD3E01C4D20658C5E4EA1B9A6C8F854B2D796C4FDE740DAC65E834167758CFF283EED1BE5C9A812022B015A902E0B97D4E95569EB8C0971834744E633D9CB4C4A6D8EDA03C12F486E13A1A0CB1AA101AD94943236384CBBF5C679944B994DE9546E493BF"
    Name="Aspose.Words"
    AssemblyVersion="10.3.0.0"/>
    <IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Url="file:///C:/fark2/WebAsposeTest/bin/Aspose.Words.DLL"/>
    <IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Zone="Internet"/>
    <IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    version="1"
    Level="SafePrinting"/>
    <IPermission class="System.Security.Permissions.MediaPermission, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    version="1"
    Audio="SafeAudio"
    Video="SafeVideo"
    Image="SafeImage"/>
    <IPermission class="System.Security.Permissions.WebBrowserPermission, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    version="1"
    Level="Safe"/>
    </PermissionSet>

    The assembly or AppDomain that failed was:
    Aspose.Words, Version=10.3.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
    The Zone of the assembly that failed was:
    Internet
    The Url of the assembly that failed was:
    file:///C:/fark2/WebAsposeTest/bin/Aspose.Words.DLL

     
  •  09-01-2011, 2:14 PM 325858 in reply to 325825

    Re: File IO Permission when legacyCasModel="true"

    Hi

     

    Thank you for additional information. As I can see the exception occurs when you attempt to open the document. Have you tried to read the document into stream as I suggested earlier? Just to make sure that you can read these documents from your application.

    Have you tried to put the documents into your application folder and open them from there?

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-02-2011, 7:40 AM 326101 in reply to 325858

    Re: File IO Permission when legacyCasModel="true"

    Yes. Using streams for both the license file and the input/output files was the first thing tried even before posting here to support - we had seen the stream idea and the permission.Assert code block idea recommended in other blog threads on your support site. Normal .NET file streams work correctly regardless of the indicated 'trust' setting is in the web.config. We tried putting the license file and inpuut/output files and locations all over the place including the root of the ASP.NET web app, in the /bin folder, root of c:\, a network share... all places that the worker process has IO permission to and that work with the trust setting is removed from the web.config. We weren't too concerned about the license file since the product seemed to work in evaluation mode even without a license file - but we did try to stream it per an example in another of your blog.
     
  •  09-02-2011, 9:58 AM 326138 in reply to 326101

    Re: File IO Permission when legacyCasModel="true"

    Hello

     

    Thank you for additional information. I also have tested on my side (Windows 7, VS-2010), all works fine. As I understand, you are able to load a document to memory stream, than why don’t you use this stream to create Aspose.Words document?

     

    Best regards,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML