Skip to content

[ECS] Dialog optional button2 throws exception when left null #376

@CiprianN23

Description

@CiprianN23

If you build either a list dialog or message box dialog and just specify button1 server crash due to Value cannot be null on button2 even if this button its actually optional and does not need to be specified as it has default valeu

Repo:

public class DialogTestSystem : ISystem
    {
        [Event]
        public void OnPlayerConnect(Player player, IDialogService dialogService)
        {
            var testDialog = new MessageDialog("Test dialog", "Test content", "Button 1");

            void TestDialogHandler(MessageDialogResponse r)
            {

            }

            dialogService.Show(player.Entity, testDialog, TestDialogHandler);
        }
    }

Stack trace:
[SampSharp:ERROR] Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'chars')
   at System.Text.ASCIIEncoding.GetByteCount(String chars)
   at SampSharp.Core.Natives.NativeObjects.FastNatives.NativeUtils.GetByteCount(String input) in D:\SourceCode\SampSharp\src\SampSharp.Core\Natives\NativeObjects\FastNatives\NativeUtils.cs:line 41
   at NativePlayerProxyClass_3.ShowPlayerDialog(Int32 , Int32 , String , String , String , String )
   at SampSharp.Entities.SAMP.DialogService.Show[TResponse](EntityId player, IDialog`1 dialog, Action`1 responseHandler) in D:\SourceCode\SampSharp\src\SampSharp.Entities\SAMP\Dialogs\DialogService.cs:line 59
   at PrisonRP.GameMode.Features.Players.DialogTestSystem.OnPlayerConnect(Player player, IDialogService dialogService) in D:\SourceCode\PrisonRP\src\PrisonRP\PrisonRP.GameMode\Features\Players\DialogTestSystem.cs:line 25
   at lambda_method3(Closure , Object , Object[] , IServiceProvider , IEntityManager )
   at SampSharp.Entities.EventService.<>c__DisplayClass11_0.<CreateInvoker>b__0(Object instance, EventContext eventContext) in D:\SourceCode\SampSharp\src\SampSharp.Entities\Events\EventService.cs:line 178
   at SampSharp.Entities.EventService.Invoke(EventContext context) in D:\SourceCode\SampSharp\src\SampSharp.Entities\Events\EventService.cs:line 108
   at SampSharp.Entities.SAMP.PlayerConnectMiddleware.Invoke(EventContext context, IEntityManager entityManager) in D:\SourceCode\SampSharp\src\SampSharp.Entities\SAMP\Middleware\PlayerConnectMiddleware.cs:line 38
   at lambda_method14(Closure , Object , EventContext , IServiceProvider )
   at SampSharp.Entities.EcsBuilderUseMiddlewareExtensions.<>c__DisplayClass3_1.<UseMiddleware>b__2(EventContext context) in D:\SourceCode\SampSharp\src\SampSharp.Entities\EcsBuilderUseMiddlewareExtensions.cs:line 115
   at SampSharp.Entities.EventService.<>c__DisplayClass12_0.<BuildInvoke>b__0(Object[] args) in D:\SourceCode\SampSharp\src\SampSharp.Entities\Events\EventService.cs:line 200
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at SampSharp.Core.Callbacks.Callback.Invoke(Byte[] buffer, Int32 startIndex) in D:\SourceCode\SampSharp\src\SampSharp.Core\Callbacks\Callback.cs:line 201
   at SampSharp.Core.HostedGameModeClient.PublicCall(String name, IntPtr data, Int32 length) in D:\SourceCode\SampSharp\src\SampSharp.Core\HostedGameModeClient.cs:line 117```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions