locked
IO Exception under partial trust RRS feed

  • Question

  • When my program runs under partial trust, it will throw an IO exception. 

    I know the partial trust denies FileIO, but if there is a way to give FileIO permission?

    Friday, August 20, 2010 7:26 AM

Answers

  • Hi,

    If you really want to save a file on you VM instance, use LocalStorage. You can find an explanation here: http://nmackenzie.spaces.live.com/blog/cns!B863FF075995D18A!265.entry?sa=408547744

    But you must realize that your VM can be brought down at any moment en your data in LocalStorage will be lost because it is not replicated. You could make some caching implementation with LocalStorage like the AzureDirectory for Lucene.NET.


    Regards, Patriek
    Friday, August 20, 2010 8:19 AM
  • You should read the licensing file from the app directory, that must be obtained at execution because it would change from development to deployment.

    You can get the app directory using:

    Path.GetDirectoryName(Assembly.GetAssembly(typeof(ClassName)).CodeBase); 

    When executed from local development environment this should return something like "file:\C:\....\WebRole1\approot\bin".

    When deployed on Azure something like "file:\E:\approot\bin".

    Friday, August 20, 2010 11:13 AM

All replies

  • Hi,

    If you really want to save a file on you VM instance, use LocalStorage. You can find an explanation here: http://nmackenzie.spaces.live.com/blog/cns!B863FF075995D18A!265.entry?sa=408547744

    But you must realize that your VM can be brought down at any moment en your data in LocalStorage will be lost because it is not replicated. You could make some caching implementation with LocalStorage like the AzureDirectory for Lucene.NET.


    Regards, Patriek
    Friday, August 20, 2010 8:19 AM
  • Setting Windows Azure partial trust in your role will permit some FileIO:

    • Read: app directory, any named local store
    • Write: any named local store

    If you need something more, then you need to go to Full Trust, the default Role property setting.

    As far as I know the use of partial trust is convenient when hosting the application in a shared environment, protecting the app from the insight of other apps running on the same instance.

    I think this has not sense if you host your app in the Windows Azure platform because every role runs isolated in its own VM.

    Why do you need Windows Azure partial trust in your app?

    Friday, August 20, 2010 9:00 AM
  • Thank you very much.

    I just want to read a file. My program runs with a license verifying, it wil read an xml file. So the issue happened.

    Friday, August 20, 2010 9:30 AM
  • You should read the licensing file from the app directory, that must be obtained at execution because it would change from development to deployment.

    You can get the app directory using:

    Path.GetDirectoryName(Assembly.GetAssembly(typeof(ClassName)).CodeBase); 

    When executed from local development environment this should return something like "file:\C:\....\WebRole1\approot\bin".

    When deployed on Azure something like "file:\E:\approot\bin".

    Friday, August 20, 2010 11:13 AM
  • Thanks for the answer.

    Is there any configuration file make the FileIO work like asp.net medium trust module? In asp.net medium trust, we can set the file 'web_mediumtrust.config' to make a customize sercurity policy.)?

    Monday, August 23, 2010 1:00 AM
  • Thanks for the answer.

    Is there any configuration file make the FileIO work like asp.net medium trust module? In asp.net medium trust, we can set the file 'web_mediumtrust.config' to make a customize sercurity policy.)?


    No you cannot do this because you have no write access to files in that directory. Could you tell me why you have to use partial trust?
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Windows Azure Platform China Blog: http://blogs.msdn.com/azchina/default.aspx
    Monday, August 23, 2010 8:58 AM