0

I am working with a C# WPF application, which uses some DLLs. Those DLLs are put in a subdirectory, called "Modules". Both directories (the normal runtime and the "Modules" one) have a directory "Resources", containing the file "agv.png", as you can see:

Prompt> dir /S /B agv.png
C:\<Runtime_Dir>\Modules\Resources\agv.png
C:\<Runtime_Dir>\Resources\agv.png

The DLL I'm working on, has in its runtime environment a "Resources" folder, containing that same file agv.png.

Nevertheless, while trying to run the DLL, via the application, I get a System.Windows.Markup.XamlParseException, with the following InnerException:

IOException: Cannot locate resource 'resources/agv.png'.

I have checked the entire "Locals" window, in order to understand the IOException, but the only "interesting" information is the _message, mentioning the same error (without mentioning the absolute path).

Is there a way to get the absolute path of a C# System.IO.IOException, in order to know for sure where I need to put that agv.png file?

Thanks in advance

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • What are you asking for, _detecting_ if a path is absolute or not, or _generating_ an absolute path from a given path and some base location (such as the current working directory)? – gunr2171 Mar 03 '22 at 15:31
  • I would like to know the absolute path. I realise that it's not possible to generate an absolute path from a relative one, I just wonder if it's possible to get absolute path from that exception. – Dominique Mar 03 '22 at 15:38
  • Yes you can generate an absolute path from a relative path. Most likely it's using the current working directory as the base for that calculation. Use [Environment.CurrentDirectory](https://learn.microsoft.com/en-us/dotnet/api/system.environment.currentdirectory?view=net-6.0) to see what that value is. – gunr2171 Mar 03 '22 at 15:46
  • Unfortunately that doesn't work: I have shown `Environment.CurrentDirectory` in the immediate window, and I have the subdirectory `Resources` with the mentioned file exists. I have tried renaming the directory name from `Resources` to `resources` but that didn't solve the issue. – Dominique Mar 03 '22 at 15:58
  • When your program runs it might have a different CurrentDirectory than what is shown in the Immediate Window. Also if you're on Windows then capitalization in folder names does not matter. – gunr2171 Mar 03 '22 at 15:59
  • Weird: I tried `? System.IO.Directory.GetCurrentDirectory()` and I get the same directory. It should be correct. But then why doesn't the XAML parser find it? – Dominique Mar 03 '22 at 16:03

0 Answers0