2
votes

I'm writing a Windows Phone framework with Windows 8 in mind. That means I'm creating a Portable Class Library (PCL) to be used in both platforms.

Right now my PCL is targeting .NET 4.5, Windows Phone 8 and Windows Store apps, as you can see in the project properties.

PCL Target Frameworks

In that project I need to use Path.DirectorySeparatorChar but I get the following error from the compiler:
System.IO.Path' does not contain a definition for 'DirectorySeparatorChar'

I understand that that particular char might be different in the different targeted OS (I really don't know if they are) but why is the compiler complaining about it? I mean, the property help doc says it is supported by .net framework 4.5, am I targeting the right framework? Is the PCL really targeting the full .net framework 4.5?

2
Agreed that it is a mystery why Path.DirectorySeparatorChar is not included in PCL,since it is available in all the platforms you are targeting, and several Path methods are PCL. But, what do you need the property for? Maybe you can circumvent it by using Path.Combine(string[]) directly, which is available in PCL.Anders Gustafsson
I know, I was just wondering why wasn't it there? I feel I'm walking on air here :(sebagomez
Probably the reason was to discourage developers from writing their own functions that manipulate paths, and encourage them to use Path class instead?Soonts
@AndersGustafsson, because we've deprecated it and thus didn't include it in newer platforms, such as .NET For Windows Store apps.Immo Landwerth
Unfortunately, we don't have the ability to filter the list of members on a per platform basis. Have a look at the documentation for Path. As you can see, some members have the green suitcase indicating support for store and some don't. Furthermore, the page you linked doesn't show Windows Store in the list of supported platforms at the bottom, which means it's not supported. We'd love to change the way our documentation infrastructure works but this hasn't happened yet.Immo Landwerth

2 Answers

4
votes

With respect to Path.DirectorySeparatorChar:

As far as I remember we've removed it from Windows Store in order to discourage manual parsing of paths. In general you should use Path.Combine() for assembling paths and Path.GetDirectoryName() for splitting them up. In order to check for invalid chars, there is another method that allows retrieving those.

So practically speaking, what do you need the property for?

Update: To answer your original question around understanding profiles: The profiles represent API intersections between the platforms you've selected in the PCL dialog. Generally speaking, the fewer platforms you target and the more recent the versions, the more APIs you get. Checking all platforms in the oldest version basically gives you the lowest common denominator.

Since you've targeted .NET 4.5 and .NET Windows Store, you can't access Path.DirectorySeparatorChar because that property isn't included in Windows Store.

1
votes

So, here's the actual answer to this question taken from the MSDN forum.

When you are creating a PCL, you can only have a subset of API-s that are defined in that particular profile. A profile is a list of API-s visible in all platforms.

Now, even if some API exists in both individiual platforms, this doesn't mean that it will automatically be in the PCL profile. Why is it missing is anyone's guess, but you cannot infer those reasons yourself.

If you take a look at the official documentation on MSDN (Cross-Platform Development with the .NET Framework), you'll notice that there are several constraints on what can be shared. I guess that that particular property doesn't satisfy those constraints.

And a good way of knowing is a particular method is supported relies on the icons of the documentation

Your PCL can use .NET methods which are available to all of its targets. Since PathDirectorySeparator isn't available to Windows Store apps it isn't available in PCLs targeting Windows Store apps. You can see that it doesn't have the green shopping bag marker for store support at http://msdn.microsoft.com/en-us/library/system.io.path.aspx