Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# client-side error when Action<...>.Invoke() #37

Open
1 task done
axeok opened this issue Dec 10, 2024 · 0 comments
Open
1 task done

C# client-side error when Action<...>.Invoke() #37

axeok opened this issue Dec 10, 2024 · 0 comments

Comments

@axeok
Copy link

axeok commented Dec 10, 2024

Description of the problem

Up to recently everything was okay until something happened with Actions in C#.

I've met trouble invoking action with primitive types, while I never encountered this issue before (I was using it succesfully before).

Invoke action with primitive type (maybe any structure) - Object reference not set to an instance of an object.
Invoke action with string (and custom classes) - OK.
Dynamic invoke with primitive type - OK.
Foreach invoke action.GetInvocationList() - OK.

Error happens only with .Invoke() method with primitive(structure) types.

With client config disableRestrictedSandbox = true error was gone and .Invoke() works perfectly.

image
image
image

Reproduction steps

using AltV.Net.Client;
using AltV.Net.Client.Elements.Data;

namespace TestProject.Client;

public class TestResource : Resource
{
    private delegate void TestDelegate(int value);
    
    private Action<int>? _test1;
    private Action<ConsoleColor>? _test2;
    private Action<string>? _test3;
    private TestDelegate? _test4;

    public override void OnStart()
    {
        Alt.Logger.LogInfo("Started TestResource");

        _test1 += value => Alt.Logger.LogInfo($"Test1: {value}");
        _test2 += value => Alt.Logger.LogInfo($"Test2: {value}");
        _test3 += value => Alt.Logger.LogInfo($"Test3: {value}");
        _test4 += value => Alt.Logger.LogInfo($"Test4: {value}");

        Alt.OnKeyDown += AltOnOnKeyDown;
    }

    private void AltOnOnKeyDown(Key key)
    {
        if (key != Key.J)
        {
            return;
        }

        try
        {
            _test1?.Invoke(5);
        }
        catch (Exception e)
        {
            Alt.Logger.LogError($"_test1: {e}");
        }

        try
        {
            _test2?.Invoke(ConsoleColor.Green);
        }
        catch (Exception e)
        {
            Alt.Logger.LogError($"_test2: {e}");
        }

        try
        {
            _test3?.Invoke("Invoke");
        }
        catch (Exception e)
        {
            Alt.Logger.LogError($"_test3: {e}");
        }
        
        _test4?.Invoke(11111);

        _test1?.DynamicInvoke(123);
        _test2?.DynamicInvoke(ConsoleColor.Red);
        _test3?.DynamicInvoke("Dynamic invoke");
    }

    public override void OnStop()
    {
        Alt.Logger.LogInfo("Stopped TestResource");
    }
}

Expected behaviour

.Invoke() method works as well

Additional context

No response

Operating system

Windows 11

Version

16.2.26

Crashdump ID

No response

Confirmation of issue's presence

  • By submitting this ticket, I affirm that I have verified the presence of this issue on the latest RC (Release Candidate) version available at the time of writing this ticket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant