从字符串“~/app.config”到类型 'Integer' 的转换无效

Conversion from string "~/app.config" to type 'Integer' is not valid

在网络服务 Gloval.asax 中,我将 log4net.Config.XmlConfigurator.Configure(New FileInfo(Server.MapPath("~/Web.config"))) 放入 Application_Start。 现在,我有一个控制台应用程序。我试着把 log4net.Config.XmlConfigurator.Configure(New FileInfo(AppDomain.CurrentDomain.BaseDirectory("~/app.config"))) 我得到从字符串“~/app.config”到类型 'Integer' 的转换无效。这是什么原因造成的?

打开严格选项,您将在编译时看到错误。

AppDomain.CurrentDomain.BaseDirectory 是一个字符串。当您在括号中引用某些内容时,它需要一个字符索引,显然“~/app.config”不是。

试试 AppDomain.CurrentDomain.BaseDirectory & "/app.config"