Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IL2CPP NotSupportedException SerialPort::GetPortNames

Discussion in 'Windows' started by Malveka, Mar 28, 2022.

  1. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    I'm attempting to use the method SerialPort.GetPortNames from System.IO.Ports and getting the following message from the Windows 64-bit standalone player:

    NotSupportedException: System.IO.Ports.SerialPort::GetPortNames
    at System.IO.Ports.SerialPort.GetPortNames () [0x00000] in <00000000000000000000000000000000>:0
    at SerialTest.Start () [0x00000] in <00000000000000000000000000000000>:0

    The code is as follows:

    Code (CSharp):
    1. void Start()
    2.     {
    3.         // Get a list of serial port names.
    4.         string[] ports = { "" };
    5.         try {
    6.  
    7.             ports = SerialPort.GetPortNames();
    8.  
    9.         } catch (Win32Exception w) {
    10.             Debug.Log(w.Message);
    11.             Debug.Log(w.ErrorCode.ToString());
    12.             Debug.Log(w.NativeErrorCode.ToString());
    13.             Debug.Log(w.StackTrace);
    14.             Debug.Log(w.Source);
    15.             System.Exception e = w.GetBaseException();
    16.             Debug.Log(e.Message);
    17.         }
    18.  
    19.         Debug.Log("The following serial ports were found:");
    20.  
    21.         // Display each port name to the console.
    22.         foreach (string port in ports) {
    23.             Debug.Log(port);
    24.         }
    25.         // end Debug
    26.  
    27.     }
    It works fine in the editor and when using Mono as the backend. I know there are some scenarios that are not supported when using IL2CPP. Is SerialPort.GetPortNames known to be one of them?

    I've tried this with Unity 2021.1 and 2021.2. The result is the same for both.

    Thanks for any insights!
     
  2. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    395
    Hey,

    I found this (somewhat old) thread, and it sounds like SerialPort still isn't supported in IL2CPP. The recommendation is to use a native library or just use Mono.

    I don't know the reasoning for not supporting SerialPort in IL2CPP, and I suggest cross-posting this to Scripting forums if you'd like more info.
     
    Malveka likes this.
  3. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    Hey Timke - thanks for that link. Somehow I missed that in my search. I'll see if everything else works with Mono for my project and use that if so.