belltric belltric - 1 year ago 132 Question

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

In web service Gloval.asax, i put log4net.Config.XmlConfigurator.Configure(New FileInfo(Server.MapPath("~/Web.config"))) in Application_Start.
Now, I have a console application. I'm try to put log4net.Config.XmlConfigurator.Configure(New FileInfo(AppDomain.CurrentDomain.BaseDirectory("~/app.config")))
and i get Conversion from string "~/app.config" to type 'Integer' is not valid. Whats causes this?

Answer Source

Turn option strict on and you'll see the error at compile time.

AppDomain.CurrentDomain.BaseDirectory is a string. When you reference something in brackets after that it's expecting a character index, which obviously "~/app.config" isn't.

Try AppDomain.CurrentDomain.BaseDirectory & "/app.config" instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download