Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

PlatformNotSupportedException After Upgrading to 2022.1.a13

Discussion in '2022.1 Beta' started by Cartographer, Nov 12, 2021.

  1. Cartographer

    Cartographer

    Joined:
    Mar 19, 2013
    Posts:
    78
    Recently I upgraded my project from 2019 -> 2022 without many issues, however I am hitting a problem when using System.Security.Cryptography.ProtectedData.Unprotect()

    It's throwing a PlatformNotSupportedException stating Operation is not supported on this platform. This should not be the case, as my platform is set to Win64, with the scripting API compat level set to.NET Framework.
     
  2. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
  3. Cartographer

    Cartographer

    Joined:
    Mar 19, 2013
    Posts:
    78
    That package depends on System.Security to provide the ProtectedData class, and does not actually contain it.
    I have references System.Security previously on 2019 using the csc.rsp file, but since upgrading to 2022 I get the PlatformNotSupportedException despite being on the same platform

    I think that support for it has just been removed from the engine somehow. I may need to investigate other solutions as my project currently requires this functionality
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,065
    You're seeing this in the Editor on Windows? Did you try it in a build?

    Unity has upgraded mono in 2021.2 and this has changed a lot in how the class libraries are implemented. In case of ProtectedData, the old mono Unity used contained both Windows and Unix implementations in the same dll. But with the effort to merge .Net class library sources, mono now only contains the Unix implementation and uses the CoreFX implementation for Windows.

    Which means there are now two different builds of
    System.Security.dll
    , one that works only on Unix and one that works only on Windows – before the same dll would work on both.

    I don't think the platform you select in the Unity editor has an influence on which dll is chosen, the editor has to use the dll for the platform it's running on. But if you're getting a PlatformNotSupportedException, it appears Unity is using the mono code and not the code from CoreFX.

    Checking the dlls at
    MonoBleedingEdge/lib/mono
    , Unity 2021.2 (I don't have 2022.1 installed to check right now) does contain different versions for Windows, Linux and macOS. But the dll at
    unityjit-win32/System.Security.dll
    contains the Unix and not the Windows code, while the dlls at
    unityaot-win32/System.Security.dll
    and
    net_4_x-win32/System.Security.dll
    do contain the Windows code.

    Unity ships 29 different
    System.Security.dll
    and I'm not sure which one is used when. Switching API Compatibility Level or doing a build could get you a different dll and make ProtectedData work. But it's probably good to submit a bug either way.
     
  5. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    224
    I was able to get it working in both Editor and a dedicated server build.
    I had to grab a System.Security.dll from
    "C:\Program Files\Unity\Hub\Editor\2022.2.14f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32\System.Security.dll"

    and place it in the Assets folder, and set my build target to 32bit

    I dn't know if this is a good one to use, or what problems might occur in t he future, but it does let me Unprotect() data.