locked
PCL Profile151 (.NET 4.6): Is it possible on Mac? RRS feed

  • Question

  • User117070 posted

    Hi

    Is it possible to use PCLs with .NET 4.6 target on Mac? Recently, one of our PCL's target profile was changed to 151, and I get a warning by the references saying "Framework not installed: .NETPortable,Version=v4.6,Profile=Profile151". Have checked the /Library/Frameworks/Mono.framework/Versions/4.0.3/lib/mono/xbuild-frameworks/.NETPortable folder (so my Mono version is 4.0.3), and it really does not contain v4.6 folder, only v4.0 and v4.5 So I suppose Mono 4.0.3 does not support PCLs with .NET 4.6 target yet. If so, I could not find any future plans for this. Do anyone has information about this? Is there a way to hack this? Eg is it possible to install Profile151 into /Library/Frameworks/Mono.framework/External? Would copying the Microsoft dll-s from a Windows machine's PCL Profile folder do the trick?

    Thanks and regards, Norbert Virth

    Tuesday, September 1, 2015 2:44 PM

Answers

  • User131778 posted

    Mono doesn't support .NET 4.6 API yet. What API do you use in 4.6? Can't you just revert to 4.5?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 1, 2015 9:03 PM

All replies

  • User131778 posted

    Mono doesn't support .NET 4.6 API yet. What API do you use in 4.6? Can't you just revert to 4.5?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 1, 2015 9:03 PM
  • User117070 posted

    I can revert if I must; but the upgrade happened from 4.0, not from 4.5; and strange, but the latter contains less: lot of classes and methods missing (eg Timer; the code is full with errors). As I know they've just forgotten these classes from 4.5 PCLs as a mistake :) So, before downgrade to 4.5 (must not downgrade to 4.0 anymore), I just wanted to know if any stable workaround exists.

    Thanks for the fast answer!

    Wednesday, September 2, 2015 5:30 AM
  • User131778 posted

    Oh, I see what's the problem. I see several workarounds: 1) if you target only iOS, Mac and Android - then you can use full 4.5 class library instead of portable class libraries. 2) if the reason for upgrade was async functionality to your portable project then install Microsoft.Bcl.Async package to your portable library from the NuGet. It contains some Task's API extensions and async/await support. 3) use shared project

    Wednesday, September 2, 2015 9:08 AM
  • User117070 posted

    Thanks for the tips, but no one of the 3 works now. A strange idea, but I think we will patch the holes in the .NET 4.5 PCL (Profile111 if I remember well) projects with referencing a .NET 4.0 PCL (Profile92). P92 contains the remaining classes (P92 was the original pcl profile anyway); so we will delegate them through a common P92 project.

    Wednesday, September 2, 2015 1:04 PM
  • User131778 posted

    Just faced with similar problem recently. So to make an answer more complete there is another option that is based on The bait and switch pcl trick with Type Forwarding.

    So you have legacy 4.0 PCL. Migration path consist following steps: 1. Straight upgrade your assembly from 4.0 to 4.5. From this point you'll have compile errors. 2. Create new 4.5 PCL assembly named, for example, Missing45.PCL where you will place Microsoft's forgotten types. 2.1 Define missing types in this assembly. It will be just stubs with Microsoft namespaces: ```

    namespace System.Threading { public delegate void TimerCallback(object state);

    public sealed class Timer : IDisposable
    {
        public Timer(TimerCallback callback)
        {
            throw new NotSupportedException("Should be implemented in platform-specific assembly");
        }
    
        public bool Change(int dueTime, int period)
        {
            throw new NotSupportedException("Should be implemented in platform-specific assembly");
        }
    
        public void Dispose()
        {
            throw new NotSupportedException("Should be implemented in platform-specific assembly");
        }
    }
    

    }

    ```

    1. Create platform-specific assembly project, named, for example Missing45.Windows. You don't need implement any functionality here. It can contain just AssemblyInfo.cs. But make sure it has name and version as Missing45.PCL assembly (but don't reference Missing45.PCL here) 3.1 In AssemblyInfo.cs define type forwarding for missing 4.5 types: [assembly: TypeForwardedTo(typeof(System.Threading.Timer))] [assembly: TypeForwardedTo(typeof(System.Threading.TimerCallback))]
    2. Reference your upgraded 4.5 PCL to Missing45.PCL. Compile errors are gone now.
    3. Reference you platform project to Missing45.Windows (don't reference Missing45.PCL here)

    Done. Now you have upgraded 4.5 PCL assembly with untouched code. From this point you can gradually upgrade your codebase.

    Sunday, November 1, 2015 8:42 PM