Fix: Path.Combine throws Argument Exception “Uri formats are not supported”

The following code will throw an Argument Exception stating "Uri formats are not supported".
 
Path.Combine(Assembly.GetExecutingAssembly().CodeBase, @"..MyFile.txt");
 
A fix for this is the following:
 
Path.Combine(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath, @"..MyFile.txt");
 
Advertisements

One thought on “Fix: Path.Combine throws Argument Exception “Uri formats are not supported”

  1. Instead of Assembly.GetExecutingAssembly().CodeBase one can use Assembly.GetExecutingAssembly().Location – same data but normal file path format, instead of Uri format.

    Konstantin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s