dbus-sharp icon indicating copy to clipboard operation
dbus-sharp copied to clipboard

Better exception when serialized class lacks default constructor

Open oskarb opened this issue 15 years ago • 2 comments

Over DBus I call a method that takes a parameter of type MyClass. This class has no default constructor. I get a NullReferenceException which is not helpful at all!

System.: Object reference not set to an instance of an object at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode, System.Reflection.ConstructorInfo con) [0x0001b] in /home/oskar/mono24/mono-2.6.7/mono-2.6.7/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs:536 at DBus.TypeImplementer.GenStructReader (System.Reflection.Emit.ILGenerator ilg, System.Type type) [0x00014] in /home/oskar/mono24/mono-2.6.7/dbus-sharp-0.7.0/src/TypeImplementer.cs:298 [... snipped lots of stack frames ...]

I think TypeImplementer.GenStructReader() should check for null return value from GetConstructor() and throw a proper exception with a more helpful error message.

Also, this problem does not show until actually trying to receive a message containing the offending type. It would perhaps be better to check for this already when the object is registered with the connection, to become aware of the problem earlier. Perhaps this is a bit more complex to achieve though.

oskarb avatar Dec 28 '10 21:12 oskarb

Issues go stale after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

/lifecycle stale

bnbot avatar Jun 09 '21 10:06 bnbot

thank

minkhantaunh avatar Nov 11 '21 21:11 minkhantaunh