PCL cannot retrieve Environment.SpecialFolder

Hi all,
I am trying to write a cross platform application with PCL. to read and write database I want to retrieve db path with
private static string _dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DB_NAME)

But when I compile it I got errors , says that
Data\Database.cs(20,24,20,37): error CS0117: 'System.Environment' does not contain a definition for 'SpecialFolder'

I checked mscorlib.dll is included in the profile78 directory but I cannot see it included in project references. I also unchecked exclude mscorlib.dll from project options.

Can you please explain the error ?

Answers

  • AleksandrBAleksandrB RUMember

    Hi, Ertan!
    Have you solved this problem?

  • GrantCauseGrantCause AUMember

    I have the same problem:

    if !SILVERLIGHT

        readonly string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); 
    

    endif

    Get an error saying System.Environment does not contain a definition for GetFolderPath

    Anyone solve this issue yet?

  • GrantCauseGrantCause AUMember

    Im getting it before I even compile. Its like I am missing a reference or something. Im using profile49 and have tried profile78 as above but no luck either.

    Any assistance would be greatly appreciated.

  • ErtanErgunErtanErgun USMember

    hi WilliamWoe ,
    Yes I solve my problem, I was trying to access the special folder inside the PCL but after that I understand that it is just core. I gave necessary parameter with an interface. In i run a unit test it uses different config and if i run it on a mobile device it is different.

    Thanks

  • GrantCauseGrantCause AUMember

    Thanks for that Sean I will go check out the links.

  • AndyKazmaierAndyKazmaier USMember
    edited August 2015

    @thedigitalsean - thanks for the links! Makes perfect sense now that you explained it...

  • Thanks for the info Sean. It helped a-lot.

  • BeXamarinBeXamarin INMember

    @ErtanErgun said:
    Hi all,
    I am trying to write a cross platform application with PCL. to read and write database I want to retrieve db path with
    private static string _dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DB_NAME)

    But when I compile it I got errors , says that
    Data\Database.cs(20,24,20,37): error CS0117: 'System.Environment' does not contain a definition for 'SpecialFolder'

    I checked mscorlib.dll is included in the profile78 directory but I cannot see it included in project references. I also unchecked exclude mscorlib.dll from project options.

    Can you please explain the error ?

  • BeXamarinBeXamarin INMember

    Hi ErtanErgun,

    I am facing same problem and unable to get solution, can you please show me your code how you made it work? i am looking some hint or solutions since last two days, but nothing is working. Please help!

  • WalidHAFIDWalidHAFID USMember

    For people who did not solve the problem :
    Instead of using Environment.GetFolderPath use System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    because you have an ambiguity between System.Environment & Android.OS.Environment

  • NateSchererNateScherer USMember

    @WalidHAFID said:
    For people who did not solve the problem :
    Instead of using Environment.GetFolderPath use System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    because you have an ambiguity between System.Environment & Android.OS.Environment

    Thank you, this was my problem as well.

  • ST.7899ST.7899 USMember
    edited November 2

    Please someone share how he solve this issue with some sample code . I try with PCLStorage library no luck , I try Enviroment.GetFolderPath and is missing. am struggle in this a few days now.

    System.Enviroment.GetFolderPath is not listed . something missing.

  • seanydaseanyda GBMember ✭✭✭✭✭

    @ST.7899 said:
    Please someone share how he solve this issue with some sample code . I try with PCLStorage library no luck , I try Enviroment.GetFolderPath and is missing. am struggle in this a few days now.

    System.Enviroment.GetFolderPath is not listed . something missing.

    It's accessible from the platform specific projects, Not the PCL. So if you create a class in your iOS or Android project this will compile .

    public string PersonalFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

    You then will need to use the DependencyService to use that information within the PCL.

Sign In or Register to comment.