【问题标题】:Conversion from string "~/app.config" to type 'Integer' is not valid从字符串“~/app.config”到类型“Integer”的转换无效
【发布时间】:2016-12-14 00:38:06
【问题描述】:

在网络服务 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”到类型“整数”的转换无效。这是什么原因造成的?

【问题讨论】:

    标签: asp.net vb.net app-config


    【解决方案1】:

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

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

    改用AppDomain.CurrentDomain.BaseDirectory & "/app.config"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2018-02-14
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多