Relative Path

Relative path is used a lot in Win32, and it makes sense. When I say relative path, I mean relative to the current directory. After all, there is no other directory that I can relative to.

But in .Net, we do have another one! And it is called ApplicationBase! Remember when we probe, we probe GAC, and ApplicationBase.

So we have current directory, and ApplicationBase. Now when I use a relative path, what exactly is the path relative to? Current directory, or ApplicationBase?

There is no possible way that .Net framework can know in every situation. But it has to figure something out for you. And it tries its best to guess what exactly do you mean.

So in some cases, it uses ApplicationBase. In some other cases, it uses current directory.

For example, if you call Assembly.LoadFrom(”foo.dll”), it will look in ApplicationBase. If you have a config file,  and with a relative path in codebase hint, it will look in ApplicationBase.

Now what about AppDomain.SetCachePath()?

It uses the current directory as the parent directory. Surprise!

The thing is, relative path is ambiguous at best. Avoid them whenever possible.