1

I already changed the folder to my project folder. F# interactive:how to display/change current working directory

However, it got the following error when I sent let xml = XmlProvider<"./DbToken.xml">.GetSample() to interactive window.

DbShared.fs(66,11): error FS3033: The type provider 'ProviderImplementation.XmlProvider' reported an error: Cannot read sample XML from './DbToken.xml': Could not find file 'C:\Users\a\AppData\Local\Temp\DbToken.xml'.

Community
  • 1
  • 1
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • 2
    I guess the file is not in the local\temp folder, try `Environment.CurrentDirectory <- __SOURCE_DIRECTORY__`. I start all my scripts with that statement. P.s. not the double underscores at start and beginning of source directory. – halcwb Jul 09 '16 at 00:06

1 Answers1

1

You can set Environment.CurrentDirectory as in the comment but you can also specify the path to the xml file:

[<Literal>]                                     
let xmlpath = __SOURCE_DIRECTORY__ + "/test.xml"

And then say: let xml = XmlProvider<xmlpath>.GetSample()

s952163
  • 6,276
  • 4
  • 23
  • 47
  • 1
    Or equivalently using the `const` keyword to put an expression directly in the provider invocation: `let xml = XmlProvider.GetSample()` – Tarmil Jul 11 '16 at 09:30
  • This is a good solution for interactive windows only. However, a lot of time I send the code from the edit window, which don't have `__SOURCE_DIRECTORY__`. – ca9163d9 Jul 11 '16 at 16:00
  • @dc7a9163d9 Oh, can you be more specific about your environment? Maybe with a screenshot? `__SOURCE_DIRECTORY__` does work in VS's editor. Maybe I misunderstand what you are trying to do. – s952163 Jul 11 '16 at 23:01
  • @s952163 Good to know that `__SOURCE_DIRECTORY__` works in VS's editor. So it's OK to use it in the file because the compiled exe doesn't need the file more? – ca9163d9 Jul 12 '16 at 03:46
  • @dc7a9163d9 if it's OK to use it or not will depend on your use case. So you should test if it does what you want without any errors. It's generally used in fsx files. You can wrap it with #If INTERACTIVE and use other .Net methods to identify the directory the .exe is running from, if necessary. – s952163 Jul 12 '16 at 03:57