1

When my Windows Service(WCF service in selfhost) is starting up(ServiceBase.Main) I got some code that needs to know the ApplicationPhysicalPath.

The problem is that System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath is always null?

Why? And is there any workaround?

Soner Gönül
  • 94,086
  • 102
  • 195
  • 339
Banshee
  • 15,436
  • 37
  • 114
  • 205

2 Answers2

4

Its null because a Windows Service has nothing to do with Web hosting (unless you create a WCF ServiceHost inside it that's configured with an http binding).

How about just falling back to System.Environment.CurrentDirectory?

ErnieL
  • 5,745
  • 1
  • 21
  • 27
1

Have you tried Assembly.CodeBase or Assembly.Location instead?

        Assembly.GetExecutingAssembly().CodeBase
        Assembly.GetExecutingAssembly().Location
Simon
  • 32,406
  • 17
  • 127
  • 196