Summary 

Due to a bug in .NET 6, an exception is thrown after reading a whole file, if the file is not a multiple of read buffer size. The file is System.IO.IOException:'The parameter is incorrect.'

To read more about this bug, see .NET Runtime Issue 50858 and .NET Runtime Issue 6285

Affected Software

This bug is known to impact .NET MSI APM Agents (agents installed through MSI package) running on Windows, specifically when instrumenting .NET 6 applications.

Impact

.NET MSI APM Agents running on Windows, instrumenting .NET 6 applications will provide the following error, while attempting to read agent configuration. The effect of this exception is that the .NET 6 application will not be instrumented.

System.IO.IOException: The parameter is incorrect. at 
System.IO.Strategies.BufferedFileStreamStrategy.ReadFromNonSeekableAsync(Memory`1 destination, CancellationToken cancellationToken) at 
System.Threading.Tasks.TaskToApm.End[TResult](IAsyncResult asyncResult) at 
System.IO.Strategies.BufferedFileStreamStrategy.EndRead(IAsyncResult asyncResult) at System.IO.FileStream.EndRead(IAsyncResult asyncResult) at AppDynamics.Agent.Communication.IPC.NamedPipeClient.DeserializeResponse(FileStream strm, Int32 timeout, CommandStatus& status).
CODE

Resolution

To resolve the issue:

Option 1: This issue is addressed by Microsoft in .NET 6.0.1, see .NET Runtime Pull 61410. Upgrading to .NET 6.0.1 will resolve the issue.

Option 2: Set the environment variable at the system scope or application scope:

  • NameDOTNET_SYSTEM_IO_USENET5COMPATFILESTREAM
  • Value1

Option 3: Use .NET Microservice Agents to instrument the .NET 6 application.

Since the .NET Microservice Agent doesn’t depend on IPC communication to coordinator service, it is not impacted.