affederaffe / Tmds.DBus.SourceGenerator

A roslyn source generator for creating proxies targeting the Tmds.DBus.Protocol API
MIT License
7 stars 5 forks source link

Issues when reading individual properties from generated proxy class #3

Closed Ace4896 closed 1 year ago

Ace4896 commented 1 year ago

Hi, I've been using this source generator to write a wrapper over the D-Bus Secret Service API. I've run into an issue where reading individual properties (i.e. GetSomePropertyAsync) appears to be broken, but reading all properties at once (i.e. GetAllPropertiesAsync) works fine.

I've created a minimal repro here: https://github.com/Ace4896/SecretsTest

Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Tmds.DBus.Protocol.ThrowHelper.ThrowIndexOutOfRange()
   at Tmds.DBus.Protocol.Reader.ReadSpan(Int32 length)
   at Tmds.DBus.Protocol.Reader.ReadSpan()
   at Tmds.DBus.Protocol.Reader.ReadString()
   at Tmds.DBus.SourceGenerator.ReaderExtensions.ReadMessage_s(Message message, Object _) in /home/jpacheco/Documents/Repositories/Local/C#/SecretsTest/SecretsTest.Generated/Tmds.DBus.SourceGenerator/Tmds.DBus.SourceGenerator.DBusSourceGenerator/Tmds.DBus.SourceGenerator.ReaderExtensions.cs:line 111
   at Tmds.DBus.Protocol.DBusConnection.<>c__41`1.<CallMethodAsync>b__41_0(Exception exception, Message message, Object state1, Object state2, Object state3)
--- End of stack trace from previous location ---
   at Tmds.DBus.Protocol.DBusConnection.MyValueTaskSource`1.System.Threading.Tasks.Sources.IValueTaskSource<T>.GetResult(Int16 token)
   at Tmds.DBus.Protocol.DBusConnection.CallMethodAsync[T](MessageBuffer message, MessageValueReader`1 valueReader, Object state)
   at Tmds.DBus.Protocol.Connection.CallMethodAsync[T](MessageBuffer message, MessageValueReader`1 reader, Object readerState)
   at SecretsTest.Generated.Program.Main(String[] args) in /home/jpacheco/Documents/Repositories/Local/C#/SecretsTest/SecretsTest.Generated/Program.cs:line 35
   at SecretsTest.Generated.Program.<Main>(String[] args)
Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'count')
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument)
   at System.Buffers.SequenceReader`1.AdvanceToNextSpan(Int64 count)
   at Tmds.DBus.Protocol.Reader.ReadSpan(Int32 length)
   at Tmds.DBus.Protocol.Reader.ReadSpan()
   at Tmds.DBus.Protocol.Reader.ReadString()
   at Tmds.DBus.Protocol.Reader.ReadObjectPath()
   at Tmds.DBus.SourceGenerator.ReaderExtensions.ReadArray_ao(Reader& reader) in /home/jpacheco/Documents/Repositories/Local/C#/SecretsTest/SecretsTest.Generated/Tmds.DBus.SourceGenerator/Tmds.DBus.SourceGenerator.DBusSourceGenerator/Tmds.DBus.SourceGenerator.ReaderExtensions.cs:line 37
   at Tmds.DBus.SourceGenerator.ReaderExtensions.ReadMessage_ao(Message message, Object _) in /home/jpacheco/Documents/Repositories/Local/C#/SecretsTest/SecretsTest.Generated/Tmds.DBus.SourceGenerator/Tmds.DBus.SourceGenerator.DBusSourceGenerator/Tmds.DBus.SourceGenerator.ReaderExtensions.cs:line 96
   at Tmds.DBus.Protocol.DBusConnection.<>c__41`1.<CallMethodAsync>b__41_0(Exception exception, Message message, Object state1, Object state2, Object state3)
--- End of stack trace from previous location ---
   at Tmds.DBus.Protocol.DBusConnection.MyValueTaskSource`1.System.Threading.Tasks.Sources.IValueTaskSource<T>.GetResult(Int16 token)
   at Tmds.DBus.Protocol.DBusConnection.CallMethodAsync[T](MessageBuffer message, MessageValueReader`1 valueReader, Object state)
   at Tmds.DBus.Protocol.Connection.CallMethodAsync[T](MessageBuffer message, MessageValueReader`1 reader, Object readerState)
   at SecretsTest.Generated.Program.Main(String[] args) in /home/jpacheco/Documents/Repositories/Local/C#/SecretsTest/SecretsTest.Generated/Program.cs:line 38
   at SecretsTest.Generated.Program.<Main>(String[] args)

Based on the stack traces, I'm not sure if it's the protocol library or generated code that's causing the issue...

If it helps, I'm running Fedora 38, kernel 6.4.14-200, KDE 5.27.7.

affederaffe commented 1 year ago

Should be fixed with https://github.com/affederaffe/Tmds.DBus.SourceGenerator/commit/7258a96676c96375075657aae8c68a8d0ca6ebce and 0.0.11. Properties were read as the actual type instead of as a variant.

Ace4896 commented 1 year ago

Thanks for pushing a fix! Just tried 0.0.11 and everything seems to be working now :+1: