I was able to connect Microsoft Visual Studio 2022 ver (17.5.3) to Ventura ver 13.3 Mac OSX running in sickcodes docker image and I never used to have any issues until I had to reformat my pc, since then I have hit a bit of a wall.
The ISO simulator launches in windows but is stuck saying "connecting to mac...."
If in VS I de-select the "remote simulator to windows" option is VS, then the ISO simulator launches on the mac VM and loads up the VS app fine, but I do not want to have to work on the mac as means I have to flip back and forth which when doing dev work its a nightmare of a hassle
When I examine the Xamarin.Simulator logs I notice this:
Startup:
arguments: --device=EBAB483F-D9AF-XXX-XXXX--mlaunch=/Users/XXX/Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/16.2.1040/tools/bin/mlaunch --launchsim=//Users/XXX/Library/Caches/Xamarin/mtbs/builds/MauiApp1/e42ad46171c3031dfcf0c05e01b82061b90e7c77273501****/bin/Debug/net7.0-ios/iossimulator-x64/MauiApp1.app -argument=-monodevelop-port -argument=56435 -setenv=__XAMARIN_DEBUG_PORT__=56435 --sdkroot=/Applications/Xcode.app -h=172.31.**.** -ssh=XXX
version: 17.5.0.518 (430be4c76fa1617d1af209951047a425c391d38e)
Connection state changed:
State: Connecting
SSH Connect:
target: 172.XX.XXX.XX
Using SSH pass phrase
Warning: Error during connecting
System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it
at Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout)
at Renci.SshNet.Session.SocketConnect(String host, Int32 port)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
at Xamarin.Simulator.Core.Protocol.SshNetworkClientConnection.ConnectSsh(Target target)
at Xamarin.Simulator.Core.Protocol.SshNetworkClientConnection.ConnectAsync(Target target, MessageTypes messageTypes)
at Xamarin.Simulator.Core.Protocol.SimulatorClient.ConnectAsync()
at Xamarin.Simulator.Windows.App.<ConnectAsync>d__16.MoveNext()
Connection state changed:
State: Disconnected
Exit:
Exit Code: 0
So the issue appears to be with the ssh connection, but I can use ssh to connect to the mac from windows with no issue using powershell
PS C:\Users\x> ssh-add -l
The agent has no identities.
PS C:\Users\x> ssh -p 50922 patrickhume@172.31.***
The authenticity of host '[172.31.***]:50922 ([172.31.***]:50922)' can't be established.
ED25519 key fingerprint is SHA256:+6********************.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[172.31.***]:50922' (ED25519) to the list of known hosts.
(patrickhume@172.31.*** Password:
Last login:
XXX@Patricks-iMac-Pro ~ % ls
Desktop Downloads Movies Pictures
Documents Library Music Public
I can also connect from the mac vm to windows using:
ssh -p 22 patrickhume@outlook.com@192.XXX
looking at the logs indepth, I was wondered if the port was not been set properly by Xamarin
//Users/patrickhume/Library/Caches/Xamarin/mtbs/builds/MauiApp1/e42ad46171c3031dfcf0c05e01b82061b90e7c772735013ee3a8aae95dea2dbe/bin/Debug/net7.0-ios/iossimulator-x64/MauiApp1.app -argument=-monodevelop-port -argument=52260 -setenv=XAMARIN_DEBUG_PORT=52260 --sdkroot=/Applications/Xcode.app -h=172.31.XXX -ssh=patrick hume
however, the ssh port is being set when connecting to the vm as seen in VS's terminal window log:
1>------ Build started: Project: MauiApp1, Configuration: Debug Any CPU ------
1>Executing SayHello Task to establish a connection to a Remote Server.
1> Properties:
1> SessionId=e42ad46171c3031dfcf0c05e01b82061b90e7c772735013ee3a8aae95dea2dbe,
1> Addresss=172.XXXX,
1> SshPort=50922,
1> TcpPort=52443,
1> User=****,
1> AppName=MauiApp1,
1> VisualStudioProcessId=38828,
1> ContinueOnDisconnected=False
1>Detected signing identity:
1> Bundle Id: com.companyname.mauiapp1
1> App Id: com.companyname.mauiapp1
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>MauiApp1 -> D:\GitHub\MauiApp1\bin\Debug\net7.0-ios\iossimulator-x64\MauiApp1.dll
1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
......
I ruled out the firewall because I have it disabled on the mac and in windows, I added the ssh as an exception:
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Even if I disable windows firewall completely and my anti-virus that made no difference.
using an answer from stackoverflow
I even added DOCKER_HOST to environments and Expose daemon on tcp://localhost:2375 without TLS and used netstat -anb to verify that it is running and listening on the expected port
other suggestions involve updating VS or Xcode-(or even downgrading it) but I had Xcode version 14.2 working before and I'm using the latest version of VS
I tried playing around with some of the .wslconfig config settings like:
# Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1).
[network]
hostname = DemoHost
generateHosts = false
generateResolvConf = false
# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true
but this felt like a red herring, so I reverted back to my original config settings:
[wsl2]
nestedVirtualization=true
I looked at sshd_config file but given I didn't have to change these before and this is a little outside of my expertise I left this alone
so now I'm out of ideas, I am confident this is not an issue with using a VM, Docker or Sickcodes because I have had this working before. So if anyone has any let me know please?
notes: docker has Ubuntu integration set as default and wsl is using Ubuntu as its default distro & I am using WSL 2.
VS is able to pair to the mac with no issues ( I use "172.***:50922" as the address when pairing)
Finally, I found a workaround, it was as simple as changing the port to port 22, I was able to work this out when I looked at the Xamarin log for VMware which works, I noticed that used port 22, so when I setup my docker mac VM to run or port 22 like so
docker run -it \
--device /dev/kvm \
-e RAM=8 \
-p 22:10022 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=${DISPLAY:-:0.0}" \
-e GENERATE_UNIQUE=true \
-e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \
sickcodes/docker-osx:ventura
the ISO simulator works in windows fine, not sure why using a different port causes an issue, I'd understand if it were a firewall issue but I ruled that out so maybe ssh connection from mac to windows needs to be on port 22 which seems unlikely. Given I didn't have this issue before, I can only surmise that perhaps there is some config on my machine that is different post format vs pre-format, perhaps as a result of a Windows, VS, Xcode or MAC update. I'd like to work out someday as using port 22 is ok but still limiting if that's the only port I can use. In any case it works so I hope this helps someone one day