runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[Bug] Portable Class Library compilation gets broken when a target is _removed_

Open tzwlai opened this issue 10 years ago • 10 comments

Filing on behalf of @dsaf from https://github.com/dotnet/coreclr/issues/2651:

Steps to reproduce:

  1. Create a new PCL project targeting .NET 4.5, Win 8 and SL 5 (Profile47)
  2. Change Class1.cs to following code (notice it compiles):
    public class Class1
    {
        private void Test()
        {
            IConvertible test;
        }
    }
  1. Disable SL 5 target in project settings, notice a message "The following will be automatically targeted because they support the same set of portable APIs: ASP.NET Core 5.0". Project changes to Profile7

  2. Compilation is now broken: "CS0246 The type or namespace name 'IConvertible' could not be found (are you missing a using directive or an assembly reference?)"

The code could be relying on value types inheriting IConvertible as well, so it needs the interface. There are likely to be other similar breaking changes around Reflection APIs.

Effectively there seems to be a bug in some piece of code that tells that a set of portable APIs is common when in fact it is not. I don't know where it is: in PCL profile configuration, Visual Studio or .NET Framework.

Removing a target should not be a breaking change.

tzwlai avatar Jan 14 '16 17:01 tzwlai

@Pilchie This is a PCL VS experience issue. Essentially switching from old-style portable to new-style portable which does cause some APIs to be removed.

weshaggard avatar Jan 14 '16 18:01 weshaggard

Tag @ericstj - I believe the metapackage was set up to exclude some libraries deliberately.

Pilchie avatar Jan 14 '16 19:01 Pilchie

Wait, I take that back - this is from mscorlib portable -> system runtime portable, not system runtime portable -> nuget portable.

@davkean says this is by design. We had to keep IConvertible in mscorlib based portable due to dependencies from the VB compiler, but didn't carry it forward into system runtime.

Pilchie avatar Jan 14 '16 19:01 Pilchie

FWIW we did add IConvertible to a later version of System.Runtime but that doesn't help this particular scenario.

@dsaf it is unfortunate but this is a result of some of the forking of the platforms where in some cases changing platforms can actually give you less APIs.

weshaggard avatar Jan 14 '16 19:01 weshaggard

@Pilchie

...didn't carry it forward into system runtime.

Is IConvertible being deprecated due to a better design or it's simply a matter of time until it gets propagated everywhere?

dsaf avatar Jan 14 '16 20:01 dsaf

It is a matter of time before it gets to the newer versions. We have already added it in our latest version of System.Runtime (https://github.com/dotnet/corefx/blob/master/src/System.Runtime/ref/System.Runtime.cs#L964).

weshaggard avatar Jan 14 '16 20:01 weshaggard

@weshaggard

Thank you, last question if you don't mind: is it a matter of few months or might be a Visual Studio vNext kind of thing?

dsaf avatar Jan 14 '16 20:01 dsaf

Actually I just tried this out locally and the the API does exist already in VS 2015 but you have to choose higher versions of platforms you are targeting. You will not be able target .NET 4.5 and Win8, but if you target .NET 4.6 and Windows Unversal 10, IConvertible is available. So it is already available in the newer versions of the targets. So depending on your scenario you may be good today.

weshaggard avatar Jan 14 '16 20:01 weshaggard

Ideally would like to target Windows Phone 8 until my Lumia 920 gets upgraded over the air :).

dsaf avatar Jan 14 '16 21:01 dsaf

Sorry we cannot go back in time and add support for that on Windows Phone 8. :)

weshaggard avatar Jan 14 '16 21:01 weshaggard