visual studio pair to mac stuck on connecting

Patrick Hume 0 Reputation points
2023-03-31T02:28:59.3033333+00:00

I was able to connect Microsoft Visual Studio 2022 ver (17.5.3) to Ventura ver 13.3 Mac OSX running in 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 iOS 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 iOS 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 in-depth, 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)

thanks in advance

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,425 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,943 questions
Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,560 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,307 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 43,971 Reputation points
    2023-03-31T10:28:55.7133333+00:00

    Hello there,

    Could you please try to delete the cache file stored under %LOCALAPPDATA%\Xamarin\iOS

    Then reopen your VS and Pair to Mac again to see if this issue still exists.

    1. Open VS ->Tools -> iOS -> Pair to mac
    2. Right click exist Mac name -> Forget this Mac
    3. Click Add Mac -> Enter Mac name or IP address -> add -> Enter username and password -> Login

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--


  2. Patrick Hume 0 Reputation points
    2023-04-01T04:59:56.5166667+00:00

    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 set up my docker mac VM to run or port 22 like so (note: -p 22:10022)

    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

    0 comments No comments