Unable to read config file using FileStream

Created at 31 Aug 2017, 23:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid362975

Joined 31.08.2017

Unable to read config file using FileStream
31 Aug 2017, 23:14


Hey Guys,
I am trying to read a csv file for purposes of config.  

The code I am using is: 

Using System.io;
private void loadConfig(string instrument, TimeFrame barSize)
        {
            string path = "C:\\configs\\FX_Trader_TP.csv";

            FileStream takeProfitsFS = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(takeProfitsFS);
            string[] sLine = sr.ReadLine().Split();

            if (sLine[0] == instrument)
            {
                if (sLine[1] == barSize.ToString())
                {
                    asiaBuy = Convert.ToDouble(sLine[2]);
                    asiaSell = Convert.ToDouble(sLine[3]);
                    ldnAMBuy = Convert.ToDouble(sLine[4]);
                    ldnAMSell = Convert.ToDouble(sLine[5]);
                    ldnPMBuy = Convert.ToDouble(sLine[6]);
                    ldnPMSell = Convert.ToDouble(sLine[7]);
                    nycPMBuy = Convert.ToDouble(sLine[8]);
                    nycPMSell = Convert.ToDouble(sLine[9]);
                }
            }
        }

I am using the following version of Visual Studio to debug remotely

Visual Studio Pro 2013 Version 12.0.40629.00 Update 5

The framework version is 4.6.01586

The error that I receive is

An exception of type 'System.Security.SecurityException' occurred in mscorlib.dll but was not handled in user code

Additional information: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Stacktrace::
  at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, AccessControlActions control, String[] fullPathList, Boolean checkForDuplicates, Boolean needFullPath)
   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 cAlgo.FX_Trader1.loadConfig(String instrument, TimeFrame barSize)
   at cAlgo.FX_Trader1.initialise()
   at cAlgo.FX_Trader1.OnStart()
   at Frontend.CrossDomain.Wrapper.cBot.CBotWrapper.SafeExecute(String methodName, Action actionToExecute, Boolean isStopNeededAfterException)

 

I would really appreciate some help on this exception.

Thanks,
 


@ctid362975
Replies

Spotware
01 Sep 2017, 09:35

Dear Trader,

Thanks for posting in our forum. Your issue is related with your cBot's access rights which are declared in the cBot's attributes. You can find the guide for the access rights here.

More specifically, you need to change your cBot's access rights from AccessRights.None to AccessRights.FileSystem like the example below

 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]

Best Regards,

cTrader Team


@Spotware

ctid362975
01 Sep 2017, 13:55

RE:

Spotware said:

Dear Trader,

Thanks for posting in our forum. Your issue is related with your cBot's access rights which are declared in the cBot's attributes. You can find the guide for the access rights here.

More specifically, you need to change your cBot's access rights from AccessRights.None to AccessRights.FileSystem like the example below

 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]

Best Regards,

cTrader Team

Thanks Guys - I did as you suggested and problem solved.

Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]

Cheers


@ctid362975