Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The using directives could be within #if/#else

using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;

namespace Microsoft.Diagnostics.NETCore.Client
{
Expand Down Expand Up @@ -69,7 +67,7 @@ private static Stream GetTransport(int processId)
throw new ServerNotAvailableException($"Process {processId} not running compatible .NET Core runtime.");
}
string path = Path.Combine(IpcRootPath, ipcPort);
var remoteEP = new UnixDomainSocketEndPoint(path);
var remoteEP = CreateUnixDomainSocketEndPoint(path);

var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
socket.Connect(remoteEP);
Expand Down Expand Up @@ -122,5 +120,17 @@ private static IpcMessage Read(Stream stream)
{
return IpcMessage.Parse(stream);
}

private static EndPoint CreateUnixDomainSocketEndPoint(string path)
{
#if NETCOREAPP
return new UnixDomainSocketEndPoint(path);
#elif NETSTANDARD2_0
// UnixDomainSocketEndPoint is not part of .NET Standard 2.0
var type = typeof(Socket).Assembly.GetType("System.Net.Sockets.UnixDomainSocketEndPoint");
var ctor = type.GetConstructor(new[] { typeof(string) });
return (EndPoint)ctor.Invoke(new object[] { path });
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add an #else statement and with a descriptive #error directive.

}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Microsoft.Diagnostics.NETCore.Client</RootNamespace>
<Description>.NET Core Diagnostics Client Library</Description>
<VersionPrefix>0.1.0</VersionPrefix>
Expand Down