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
  • 97,193
  • 102
  • 206
  • 364
Banshee
  • 15,376
  • 38
  • 128
  • 219

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,773
  • 1
  • 23
  • 27
1

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

        Assembly.GetExecutingAssembly().CodeBase
        Assembly.GetExecutingAssembly().Location
Simon
  • 33,714
  • 21
  • 133
  • 202