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

FiveM : Unable to use Exports when using LemonUI #157

Open
Etuldan opened this issue Jan 29, 2024 · 5 comments
Open

FiveM : Unable to use Exports when using LemonUI #157

Etuldan opened this issue Jan 29, 2024 · 5 comments
Labels
priority: p2 medium A bug that makes things unstable or a feature that has been requested for a while status: acknowledged We are aware of the bug or feature request type: question A simple question

Comments

@Etuldan
Copy link

Etuldan commented Jan 29, 2024

When I add LemonUI as nuget package in order to use it, my exports inside my C# FiveM addon won't work and crash my Client plugin.

Here is my stacktrack inside FiveM Client

[     32719] [b3095_GTAProce]             MainThrd/ trying to get export of user
[     44641] [b3095_GTAProce]             MainThrd/ Trying to get UserData
[     44781] [b3095_GTAProce]             MainThrd/ Error invoking callback for event login:ready: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not resolve type with token 0100000e
[     44797] [b3095_GTAProce]             MainThrd/   at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesDataInternal (System.Reflection.ICustomAttributeProvider)
[     44797] [b3095_GTAProce]             MainThrd/   at System.MonoCustomAttrs.GetCustomAttributesData (System.Reflection.ICustomAttributeProvider obj) [0x0000e] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Reflection.CustomAttributeData.GetCustomAttributes (System.Reflection.Assembly target) [0x00000] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in /mnt/idfk/meow/mono/mcs/mcs/import.cs:1719 
[     44797] [b3095_GTAProce]             MainThrd/   at Mono.CSharp.MetadataImporter.GetAssemblyDefinition (System.Reflection.Assembly assembly) [0x00027] in /mnt/idfk/meow/mono/mcs/mcs/import.cs:972 
[     44797] [b3095_GTAProce]             MainThrd/   at Mono.CSharp.ReflectionImporter.ImportAssembly (System.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00000] in /mnt/idfk/meow/mono/mcs/mcs/reflection.cs:86 
[     44797] [b3095_GTAProce]             MainThrd/   at Microsoft.CSharp.RuntimeBinder.DynamicContext.Create () [0x000c6] in /mnt/idfk/meow/mono/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/DynamicContext.cs:104 
[     44797] [b3095_GTAProce]             MainThrd/   at Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion) [0x00006] in /mnt/idfk/meow/mono/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeMemberBinder.cs:156 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Dynamic.DynamicObject+MetaDynamic.BindInvokeMember (System.Dynamic.InvokeMemberBinder binder, System.Dynamic.DynamicMetaObject[] args) [0x0003c] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Dynamic.InvokeMemberBinder.Bind (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args) [0x00016] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Dynamic.DynamicMetaObjectBinder.Bind (System.Object[] args, System.Collections.ObjectModel.ReadOnlyCollection`1[T] parameters, System.Linq.Expressions.LabelTarget returnLabel) [0x000c6] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T] (System.Runtime.CompilerServices.CallSite`1[T] site, System.Object[] args) [0x00019] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.CallSiteOps.Bind[T] (System.Runtime.CompilerServices.CallSiteBinder binder, System.Runtime.CompilerServices.CallSite`1[T] site, System.Object[] args) [0x00000] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
[     44797] [b3095_GTAProce]             MainThrd/   at TestResourceDotNet.Client.ClientMain.Onlogin (System.String obj) [0x0000a] in E:\Dev\FiveM\TestResourceDotNet\Client\ClientMain.cs:24 
[     44797] [b3095_GTAProce]             MainThrd/   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
[     44797] [b3095_GTAProce]             MainThrd/   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/    --- End of inner exception stack trace ---
[     44797] [b3095_GTAProce]             MainThrd/   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     44797] [b3095_GTAProce]             MainThrd/   at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\cfx-fivem\production\fivem\code\client\clrcore\EventHandlerDictionary.cs:107 

My simple example code is :

using System;
using System.Threading.Tasks;
using CitizenFX.Core;
using LemonUI;

namespace TestResourceDotNet.Client
{
    public class ClientMain : BaseScript
    {
        public ClientMain()
        {
            var pool = new ObjectPool();
            EventHandlers["login:ready"] += new Action<string>(Onlogin);
        }

        private void Onlogin(string obj)
        {
            Debug.WriteLine("Trying to get UserData");
            var b = Exports["my_external_resource"].user();
            Debug.WriteLine(b.firstname);
            Debug.WriteLine("Done");
        }

        [Tick]
        public Task OnTick()
        {
            return Task.FromResult(0);
        }
    }
}

The crash occurs when Onlogin is trigger by my custom login:ready event, and right after the debug message Trying to get UserData

My csproj is made from the FiveM template resource, and I just added the LemonUI.FiveM package from nuget ( I'm using VS2022 and the FiveM SDK seems to use .NET Framework 4.5.2)

<Project Sdk="CitizenFX.Sdk.Client/0.2.3">
    <ItemGroup>
        <Compile Include="../Shared/**/*.cs" />
    </ItemGroup>
    <ItemGroup>
      <PackageReference Include="LemonUI.FiveM" Version="2.0.0" />
    </ItemGroup>
</Project>

I put the 3 .dll files CitizenFX.Core.Client.dll LemonUI.FiveM.dll TestResourceDotNet.Client.net.dll generated by the build inside a Client folder, and my fxmanifest.lua is

fx_version 'cerulean'
game 'gta5'

files {
    'Client/CitizenFX.Core.Client.dll',
    'Client/LemonUI.FiveM.dll'
} 

client_script 'Client/TestResourceDotNet.Client.net.dll'

author 'Etuldan'
version '1.0.0'
description 'Test LemonUI'

Besides the Exports crashes, LemonUI features seems to be working fine.

@justalemon
Copy link
Member

'Client/CitizenFX.Core.Client.dll'

This should NOT be included. This is the dll that contains the classes used in the client, this should be loaded from FiveM and not from your files.

@justalemon justalemon added status: acknowledged We are aware of the bug or feature request priority: p4 not applicable Not a bug nor a feature type: question A simple question status: invalid Bug couldn't be reproduced or the feature is not possible and removed status: acknowledged We are aware of the bug or feature request labels Jan 30, 2024
@Etuldan
Copy link
Author

Etuldan commented Feb 2, 2024

'Client/CitizenFX.Core.Client.dll'

This should NOT be included. This is the dll that contains the classes used in the client, this should be loaded from FiveM and not from your files.

Unfortunately, I have the same issue without loading (in the fxmanifest) and/or copying the "CitizenFX.Core.Client.dll" from my build into the Client folder.

@justalemon
Copy link
Member

Looks like #85 is somehow back after some FiveM updates.

@Etuldan
Copy link
Author

Etuldan commented Feb 3, 2024

To be clear, my whole game doesn't crash, only my .NET module/plugin (client-side)

@justalemon
Copy link
Member

Yes, but it shows the same behavior: dynamic objects don't work, and exports are dynamics, hence exports will not work.

@justalemon justalemon added status: acknowledged We are aware of the bug or feature request priority: p2 medium A bug that makes things unstable or a feature that has been requested for a while and removed priority: p4 not applicable Not a bug nor a feature status: invalid Bug couldn't be reproduced or the feature is not possible labels Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 medium A bug that makes things unstable or a feature that has been requested for a while status: acknowledged We are aware of the bug or feature request type: question A simple question
Projects
None yet
Development

No branches or pull requests

2 participants