Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialPort is not supported on Mac Catalyst #75120

Closed
rolfbjarne opened this issue Sep 6, 2022 · 30 comments · Fixed by #96492
Closed

SerialPort is not supported on Mac Catalyst #75120

rolfbjarne opened this issue Sep 6, 2022 · 30 comments · Fixed by #96492
Assignees
Milestone

Comments

@rolfbjarne
Copy link
Member

From @trantamcdt92 on Tue, 06 Sep 2022 09:07:49 GMT

Steps to Reproduce

  1. Create a SerialPort class
  2. Configure the serial port settings
  3. Open the serial port

Expected Behavior

Can connect to device

Actual Behavior

Exception "System.DllNotFoundException: libSystem.IO.Ports.Native" occurred

Environment

Monterey, Visual Studio Preview

Version information

Build Logs

Example Project (If Possible)

Archive.zip

Copied from original issue xamarin/xamarin-macios#15874

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Tue, 06 Sep 2022 09:48:57 GMT

The SerialPort class is currently not supported on Mac Catalyst:

/Users/rolf/Downloads/Archive/MainPage.xaml.cs(16,9): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.PortName' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(14,9): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.DataBits' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(19,13): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.Open()' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(15,9): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.StopBits' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(13,9): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.Parity' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(12,9): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort.BaudRate' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(13,23): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'Parity.None' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(15,25): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'StopBits.One' is unsupported on: 'maccatalyst' all versions.
/Users/rolf/Downloads/Archive/MainPage.xaml.cs(11,27): warning CA1416: This call site is reachable on: 'MacCatalyst' 14.0 and later. 'SerialPort' is unsupported on: 'maccatalyst' all versions.

Since this works for macOS apps, it seems to me that it just needs to be implemented for Mac Catalyst, so I'm moving this to dotnet/runtime where that code lives.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 6, 2022
@rolfbjarne rolfbjarne changed the title MacOS libSystem.IO.Ports.Native.dylib is not copied to MonoBundle of application SerialPort is not supported on Mac Catalyst Sep 6, 2022
@trantamcdt92
Copy link

@rolfbjarne
Are you planning to support SerialPort on MacOS? if you are, when it will be officially released?
I copied libSystem.IO.Ports.Native.dylib from Visual Studio (Preview) to my application and could communicate with my device.
Is this safe to use it now?

@ghost
Copy link

ghost commented Sep 6, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

From @trantamcdt92 on Tue, 06 Sep 2022 09:07:49 GMT

Steps to Reproduce

  1. Create a SerialPort class
  2. Configure the serial port settings
  3. Open the serial port

Expected Behavior

Can connect to device

Actual Behavior

Exception "System.DllNotFoundException: libSystem.IO.Ports.Native" occurred

Environment

Monterey, Visual Studio Preview

Version information

Build Logs

Example Project (If Possible)

Archive.zip

Copied from original issue xamarin/xamarin-macios#15874

Author: rolfbjarne
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@Therzok
Copy link
Contributor

Therzok commented Sep 6, 2022

I copied libSystem.IO.Ports.Native.dylib from Visual Studio (Preview)

VSMac pulls that from the System.IO.Ports nuget: https://www.nuget.org/packages/System.IO.Ports

@trantamcdt92
Copy link

@Therzok yes, I know. I'd like to confirm whether using System.IO.Ports on MacOS is OK?

@jeffhandley jeffhandley added this to the Future milestone Sep 16, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 16, 2022
@liulunjnu
Copy link

@rolfbjarne
Are you planning to support SerialPort on MacOS? if you are, when it will be officially released?
I copied libSystem.IO.Ports.Native.dylib from Visual Studio (Preview) to my application and could communicate with my device.
Is this safe to use it now?

where the "libSystem.IO.Ports.Native.dylib" Copy to debug/release directory? why when I copied to my Macbook Pro M2 can't run?

@newt0ns
Copy link

newt0ns commented Feb 22, 2023

@rolfbjarne Are you planning to support SerialPort on MacOS? if you are, when it will be officially released? I copied libSystem.IO.Ports.Native.dylib from Visual Studio (Preview) to my application and could communicate with my device. Is this safe to use it now?

Where did you copy this from and to? I have copied it over from other working MacOS projects (from the runtime folders) and into the same folder as my Mac Catalyst app, but am met with the same System.DllNotFoundException error.

@trantamcdt92
Copy link

When you have installed Visual Studio Preview app in your Mac PC, the Visual Studio.app appears in the Desktop folder. You can see libSystem.IO.Ports.Native.dylib in the framework folder inside Visual Studio.app. Then copy this file to your executable folder.

@newt0ns
Copy link

newt0ns commented Feb 22, 2023

We're currently on the normal installation of VS 2022 v17.5. No Preview versions here, just a normal up to date install. I do not know where I would go looking for the equivalent file you are using.

I have libSystem.IO.Ports.Native.dylib from the same version of a MacOS app of our libraries that works fine, compiled just minutes ago. If I copy and place that in the same folder as our Mac Catalyst maui app it isn't loaded/found

@bxdint
Copy link

bxdint commented Apr 4, 2023

Hi, We are developing MAUI multi platform desktop focused app, app needs to connect to a serial port to read UART data, we are able to achieve this on Win but Mac side is not working. It becomes major blocker for our project. How soon are you going to support mac and android platforms? For any update regarding this issue please let us know, thanks.

@jenswet
Copy link

jenswet commented Apr 18, 2023

Hi

I am wondering if there is any progress with this issue?

I've included

<PackageReference Include="System.IO.Ports" Version="7.0.0" />

in my dependencies.

This has a dependency to https://www.nuget.org/packages/runtime.osx-arm64.runtime.native.System.IO.Ports/
This package contains libSystem.IO.Ports.Native.dylib.

If I copy the libSystem.IO.Ports.Native.dylib file into my debug/release directory everything works. But the build process doesn't copy it automatically.

So the whole ticket is not really about supporting MacCatalyst, but about fixing the build process to copy the required libraries, no?

Is this related to the efforts made in #63187? I tried 8.0.0-preview.2.23128.3 without success.

Thanks

@krwq
Copy link
Member

krwq commented May 30, 2023

cc: @carlossanlop can you help us get this fixed?

@filipnavara
Copy link
Member

FWIW the native lib would compile just fine on iOS/tvOS/MacCatalyst if it was enabled (

if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID)
add_subdirectory(System.IO.Ports.Native)
endif ()
). Then the NuGet packaging would need to be sorted out since it's OOB but that's relatively trivial copy & paste.

@nterreaux
Copy link

Any updates? It still doesn't work on my mac (Ventura 13.4) ... (Windows works perfectly)

@asi-evin
Copy link

asi-evin commented Jul 7, 2023

I am also very interested in getting Serial Port working in MacCatalyst.

@jenswet

Hi

I am wondering if there is any progress with this issue?

I've included

<PackageReference Include="System.IO.Ports" Version="7.0.0" />

in my dependencies.

This has a dependency to https://www.nuget.org/packages/runtime.osx-arm64.runtime.native.System.IO.Ports/ This package contains libSystem.IO.Ports.Native.dylib.

If I copy the libSystem.IO.Ports.Native.dylib file into my debug/release directory everything works. But the build process doesn't copy it automatically.

So the whole ticket is not really about supporting MacCatalyst, but about fixing the build process to copy the required libraries, no?

Is this related to the efforts made in #63187? I tried 8.0.0-preview.2.23128.3 without success.

Thanks

I attempted your work around, copying both the SerialPort DLL and the native DYLIB files into the bin/debug. However, I get a "System.DllNotFoundException: libSystem.IO.Ports.Native" error. I tried with both the OSX-x64 and OSX-Arm64 native libraries to no avail. Are there any other steps I need to do?

@nterreaux
Copy link

Hi @asi-evin,
I found a solution by putting the libSystem.IO.Ports.Native.dylib file in my project and going into its properties. Just click on "Always copy" as in the attached screenshot and it works for me...
macos_auto_output

@asi-evin
Copy link

asi-evin commented Jul 7, 2023

@nterreaux No dice unfortunately. Still get the following message:

Error while opening port: libSystem.IO.Ports.Native
System.DllNotFoundException: libSystem.IO.Ports.Native
at Interop.Serial.SerialPortOpen(String name)
at System.IO.Ports.SafeSerialDeviceHandle.Open(String portName)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()

@nterreaux
Copy link

nterreaux commented Jul 7, 2023

@asi-evin Are your maccatalyst dependencies like mine?

Screenshot 2023-07-07 at 18 41 18

If not, I had to delete the output folder and restart the application... it didn't work the first time either, but now it does.

This solution is by far not optimal, but in my case it does the job.

@asi-evin
Copy link

asi-evin commented Jul 7, 2023

Yeah, everything described is the same, but it still doesn't work. Thanks for the help, I'm just going to abandon this for now.

@scottkdavis
Copy link

Has anyone found a work around to the issue? It appears the DLL packaging been resolved, however now I am getting an explicit "Platform not supported" error message. It appears support is intentionally blocked.

I have tried using SerialPortNet and SerialPortLibNetCore nuget packages, I couldn't get either to work on Maui Mac. I have an ORSSerialPort binding library from a Xamarin project that works fine in Xamarin, but have been unable to figure out how to get it ported to Maui. There is virtually no documentation or samples on binding libraries for Maui, let along Mac Maui. I've tried to get some native calls to work and only see Mac hard crashes with nothing helpful in the Apple crash report.

Anyone have any solutions? This is holding up our port from Xamarin to Maui. It is a project that communicates over USB Serial to control heavy equipment via modbus protocol.

@scottkdavis
Copy link

The documentation on the Nuget package needs to be updated to remove Mac. Should that be a separate bug?
https://www.nuget.org/packages/System.IO.Ports/8.0.0-preview.7.23375.6#supportedframeworks-body-tab

It also lists support for Xamarin.Mac which is also not true.

@ronimizy
Copy link

ronimizy commented Nov 2, 2023

@jeffhandley hi, any updates on this issue? it became a blocker for our project as well

would be down to contribute to resolve this issue. and would highly appreciate if you give me some direction on what's the most suitable way of doing it.

@wfurt
Copy link
Member

wfurt commented Nov 3, 2023

It should be similar to #63187 + change @filipnavara suggested. I can take a look next week.

@scottkdavis
Copy link

@wfurt @akoeplinger does the merged pull request for #86619, which fixes the serial port issues for Android and Linux include a fix for Mac Catalyst?

@akoeplinger
Copy link
Member

No, Catalyst is a different story but as far as I know @wfurt is working on it.

@00000vish
Copy link

00000vish commented Dec 20, 2023

Hi

I am wondering if there is any progress with this issue?

I've included

<PackageReference Include="System.IO.Ports" Version="7.0.0" />

in my dependencies.

This has a dependency to https://www.nuget.org/packages/runtime.osx-arm64.runtime.native.System.IO.Ports/ This package contains libSystem.IO.Ports.Native.dylib.

If I copy the libSystem.IO.Ports.Native.dylib file into my debug/release directory everything works. But the build process doesn't copy it automatically.

So the whole ticket is not really about supporting MacCatalyst, but about fixing the build process to copy the required libraries, no?

Is this related to the efforts made in #63187? I tried 8.0.0-preview.2.23128.3 without success.

Thanks

@asi-evin @ronimizy

This did not work for me either.

Instead i got it working by copying the libSystem.IO.Ports.Native.dylib into /bin/debug/*/*/MyApp.app/Content/MonoBundle folder.

And make sure you have com.apple.security.device.serial set to true in the app entitlements.

@wfurt wfurt self-assigned this Jan 3, 2024
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 4, 2024
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 8, 2024
@akoeplinger
Copy link
Member

If anyone wants to try the fix from #96492 then you can add the following nuget feed to nuget.config:

<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />

and use version 9.0.0-alpha.1.24058.11 or higher of the package:

<PackageReference Include="System.IO.Ports" Version="9.0.0-alpha.1.24058.11" />

@wfurt
Copy link
Member

wfurt commented Jan 16, 2024

Any luck with the updated package @00000vish?

@00000vish
Copy link

Any luck with the updated package @00000vish?

Yes, its working as expected!

Tested on Apple M1, Sonoma 14.1.1

@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.