Hi there! I have recently developed a software where a session is started using the NuGet package Microsoft.Diagnostics.Tracing.Session to retrieve information about the internet traffic of a single process. Having always tested it on Windows 8 and 10, I never noticed that there were problems with Windows 7, where the following exception is thrown:
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.InternalGetDirectoryName(String path)
at NativeDlls.LoadNative(String simpleName)
at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.StartKernelTrace(UInt64& TraceHandle, EVENT_TRACE_PROPERTIES* properties, STACK_TRACING_EVENT_ID* stackTracingEventIds, Int32 cStackTracingEventIds)
at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableKernelProvider(Keywords flags, Keywords stackCapture)
at MyBackgroundWorker_DoWork(Object sender, DoWorkEventArgs e) in D:\MyFolder\MySoft\MySoft\Forms\MyClass.cs:line 994
I tried to read up on it, but couldn't find much except documents stating that on Windows 7 the session must be named "NT Kernel Session". I hope someone can help me.
Code:
private void MyBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
var etwSession = new TraceEventSession(EtwSessionName);
etwSession.EnableKernelProvider(KernelTraceEventParser.Keywords
.NetworkTCPIP);
etwSession.Source.Kernel.UdpIpRecv += data =>
{
if (data.ProcessID == processId &&
data.saddr.ToString() == serverIp)
rData = data.size;
};
etwSession.Source.Process();
}