none
Windows Service CAS: Need FileIOPermission RRS feed

  • Question

  • I developed a windows service that needs file io permission but by default it's in the "Local Intranet" zone which doesn't include file io permission.  It's a full trust application and it works fine except for the part that needs file io permission.  I only need to use it on my local workstation, and I installed it using installutil.  If I install it with a setup project instead, will it be put in a different (My Computer) zone and solve my problem?  If not, what would be the easiest way to add FileIOPermission to this windows service?

    Thanks! 
    Tuesday, November 25, 2008 6:48 PM

Answers

  • You can check this thread:

    http://bytes.com/groups/net-vb/377278-windows-service-cannot-create-text-files



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhi-Xin Ye Monday, December 8, 2008 9:14 AM
    Tuesday, December 2, 2008 8:02 AM
  • Thanks for the suggestion/link-it led me to a satisfactory workaround.  I did some further testing and found that it was not really a FileIOPermission problem, but some sort of weird COM exception because the file I was trying to save was an Excel file (I say weird because the exact same code works fine when I run it in a console app, where in the windows service I was able to write the data to the Excel file without issue but it always failed on the Workbook.SaveAs() method).  I'm now working around it by writing the data to a .csv file using a streamwriter. 
    • Marked as answer by Zhi-Xin Ye Monday, December 8, 2008 9:14 AM
    Thursday, December 4, 2008 1:13 AM

All replies

  • I'm trying to make sense of the fact that you'd load a service assembly from a network share.  Is this actually a Windows permission problem?  Tinker with the service login account.  If it is actually a network share, use Caspol.exe or .NET V3.5 SP1 to assign trust.
    Hans Passant.
    Wednesday, November 26, 2008 1:24 AM
    Moderator
  • Hi Hans,

    Thanks for your reply.  I'm not loading the assembly from a network share, but if I look at the project properties I can see that it's installed from the local intranet zone.  I'm using .NET framework 2.0.

    Thanks
    Wednesday, November 26, 2008 5:54 PM
  • You can check this thread:

    http://bytes.com/groups/net-vb/377278-windows-service-cannot-create-text-files



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhi-Xin Ye Monday, December 8, 2008 9:14 AM
    Tuesday, December 2, 2008 8:02 AM
  • Thanks for the suggestion/link-it led me to a satisfactory workaround.  I did some further testing and found that it was not really a FileIOPermission problem, but some sort of weird COM exception because the file I was trying to save was an Excel file (I say weird because the exact same code works fine when I run it in a console app, where in the windows service I was able to write the data to the Excel file without issue but it always failed on the Workbook.SaveAs() method).  I'm now working around it by writing the data to a .csv file using a streamwriter. 
    • Marked as answer by Zhi-Xin Ye Monday, December 8, 2008 9:14 AM
    Thursday, December 4, 2008 1:13 AM