0

I have a dotnet core project that I'm important sample data into from an XML.

XDocument sampleData = XDocument.Load(@"seed/Import_sampleData.xml");

In the terminal when I execute it with the command dotnet run it loads the data just fine as expected but in Visual Studio Code I get different results when I try to run the debugger:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file '/Users/Chris/Google Drive/Repos/project/project.api/seed/Import_sampleData.xml'.

I'm not sure what the issue is being that I thought that the debugger also uses dotnet run so why would it behave differently?

As suggested here's my copyToOutput settings in my project.json. The xml file now is copied to the bin folder on build but still returns a file not found exception:

"copyToOutput": {
  "include": [
    "config.json",
    "Certificate.pfx",
    "seed\\"        
  ]
}
chris
  • 1,152
  • 1
  • 15
  • 37
  • I think when you run it from visual studio it uses the binary folder as base folder, when you run it from console it uses the project folder. Did you try to copy the file over to the build directory (using project.json `copyToOutput`? – Tseng Nov 10 '16 at 17:42
  • I added the directory to copyToOutput and when the project builds I can now see the xml files in a subfolder of bin called but I still get the same behavior. It can't find the file – chris Nov 10 '16 at 21:32

1 Answers1

0

I figured it out... basically I have 2 library projects and then my api project all under one subfolder. So the debugger was starting at the root workspace folder that holds the three projects. I changed cwd to start in my api project since the other projects are pulled into it via dependencies and then it immediately found the xml files in my project.

chris
  • 1,152
  • 1
  • 15
  • 37