BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
694 stars 284 forks source link

IlcDisableReflection = Connection Error #138

Open JackHarckness opened 2 months ago

JackHarckness commented 2 months ago

When compiling with MSBuild attribute <IlcDisableReflection>true</IlcDisableReflection>, RtspClient cannot connect to a stream. Otherwise it works great. I'm attaching a relevant portion of the stack trace but you know, it is very much crippled since IlcDisableReflection is true.

RtspClientSharp's version: 1.3.3

Stack trace ``` Unhandled Exception: MT140699988240528: Connection error ---> MT140699988350928: End of rtsp stream at RtspClientSharp.Rtsp.RtspTransportClient.d__16.MoveNext() + 0xfd --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b at RtspClientSharp.Rtsp.RtspTransportClient.d__15.MoveNext() + 0xda --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b at RtspClientSharp.Rtsp.RtspTransportClient.d__9.MoveNext() + 0x20c --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b at RtspClientSharp.Rtsp.RtspClientInternal.d__18.MoveNext() + 0x21f --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b at RtspClientSharp.RtspClient.<>c__DisplayClass13_0.<b__0>d.MoveNext() + 0x479 Exception_EndOfInnerExceptionStack at RtspClientSharp.RtspClient.<>c__DisplayClass13_0.<b__0>d.MoveNext() + 0x6c5 --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b at RtspClientSharp.RtspClient.d__13.MoveNext() + 0x127 ```

To Reproduce If you want a repro, create a console application, add <IlcDisableReflection>true</IlcDisableReflection> to your .csproj file, make an async call to RtspClientSharp.ConnectAsync. Compile it then to native code (<PublishAot>true</PublishAot> and dotnet publish on .NET 8.0+ will do the trick) and run. Otherwise you won't be able to see this error.

hez2010 commented 2 months ago

IlcDisableReflection is not supported and it can cause many components not working as expected.

JackHarckness commented 2 months ago

@hez2010 why do you think the reflection use is required within this library? Note that type checks like

if (e is RawH264IFrame intraFrame)
{
    //...
}

are still allowed in reflection-free mode. I would suggest a minor research and refactoring that will find and remove any reflection use. This can also lead to a minor performance increase.