FileUtilities.GetCurrentDirectory reflection fix
Fix for "The path is not of a legal form" exception when calling FileUtilities.GetCurrentDirectory using reflection
This was caused by an empty string being passed to System.IO.Path.GetDirectoryName
Fixes
@@ -158,7 +158,14 @@ public static string FindFile(string fileName)
public static string GetCurrentDirectory()
{
Assembly executingAssembly = typeof(FileUtilities).Assembly;
- string location = Path.GetDirectoryName(executingAssembly.Location);
+ string location = null;
+
+ // Make sure not to call Path.GetDirectoryName if assembly location is null or empty
+ if (!string.IsNullOrEmpty(executingAssembly.Location))
+ {
+ location = Path.GetDirectoryName(executingAssembly.Location);
+ }
+
if (string.IsNullOrEmpty(location))
{
// If there is no location information from the executing
