System.Uri fails to give correct AbsolutePath and LocalPath if the Path contains “#”

前端 未结 3 720
太阳男子
太阳男子 2021-01-06 06:02

I have C# code that is trying to get the LocalPath for a executing assembly using the following line of code:

Uri uri = new Uri(Assembly.GetExecut

3条回答
  •  庸人自扰
    2021-01-06 06:45

    System.IO.FileInfo logger = new System.IO.FileInfo(Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath), "settings.config"));
    

    Using EscapedCodeBase instead of CodeBase solves the problem. I dint realize that this was already handled until I stumbled on it.:)

提交回复
热议问题