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] dynamic types not working after loading this library #85

Closed
Sander0542 opened this issue Aug 2, 2022 · 18 comments · Fixed by #99
Closed

[FiveM] dynamic types not working after loading this library #85

Sander0542 opened this issue Aug 2, 2022 · 18 comments · Fixed by #99
Labels
priority: p2 medium A bug that makes things unstable or a feature that has been requested for a while status: completed The feature has been completed of the bug has been patched type: bug This is a bug

Comments

@Sander0542
Copy link
Contributor

After this library has been loaded by the FiveM client, the dynamic type doesn't work anymore.

I ran the same code, but without LemonUI. That worked without any exceptions. Why could this happen?


Stacktrace:

[     39172] [b2545_GTAProce]             MainThrd/ Failed to run a tick for ClientMain: System.TypeLoadException: Could not resolve type with token 0100000e
[     39172] [b2545_GTAProce]             MainThrd/   at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesDataInternal (System.Reflection.ICustomAttributeProvider)
[     39172] [b2545_GTAProce]             MainThrd/   at System.MonoCustomAttrs.GetCustomAttributesData (System.Reflection.ICustomAttributeProvider obj) [0x0000e] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Reflection.CustomAttributeData.GetCustomAttributes (System.Reflection.Assembly target) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in /mnt/idfk/meow/mono/mcs/mcs/import.cs:1719 
[     39172] [b2545_GTAProce]             MainThrd/   at Mono.CSharp.MetadataImporter.GetAssemblyDefinition (System.Reflection.Assembly assembly) [0x00027] in /mnt/idfk/meow/mono/mcs/mcs/import.cs:972 
[     39172] [b2545_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 
[     39172] [b2545_GTAProce]             MainThrd/   at Microsoft.CSharp.RuntimeBinder.DynamicContext.Create () [0x000c6] in /mnt/idfk/meow/mono/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/DynamicContext.cs:104 
[     39172] [b2545_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 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Dynamic.DynamicObject+MetaDynamic.BindInvokeMember (System.Dynamic.InvokeMemberBinder binder, System.Dynamic.DynamicMetaObject[] args) [0x0003c] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Dynamic.InvokeMemberBinder.Bind (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args) [0x00016] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     39172] [b2545_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 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T] (System.Runtime.CompilerServices.CallSite`1[T] site, System.Object[] args) [0x00019] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
[     39172] [b2545_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 
[     39172] [b2545_GTAProce]             MainThrd/   at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object,bool)
[     39172] [b2545_GTAProce]             MainThrd/   at Kifflom.FiveM.RP.Client.Exports.SpawnManager.SetAutoSpawn (System.Boolean enabled) [0x00000] in C:\GitHub\Kifflom\Kifflom.FiveM.RP\src\client\Kifflom.FiveM.RP.Client.Exports\SpawnManager.cs:40 
[     39172] [b2545_GTAProce]             MainThrd/   at Kifflom.FiveM.RP.Client.Scripts.ClientMain+<PlayerJoinedTick>d__6.MoveNext () [0x00020] in C:\GitHub\Kifflom\Kifflom.FiveM.RP\src\client\Kifflom.FiveM.RP.Client\Scripts\ClientMain.cs:81 
[     39172] [b2545_GTAProce]             MainThrd/ --- End of stack trace from previous location where exception was thrown ---
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
[     39172] [b2545_GTAProce]             MainThrd/   at Kifflom.FiveM.RP.Client.Logging.BaseScript+<>c__DisplayClass5_0+<<add_Tick>b__0>d.MoveNext () [0x00086] in C:\GitHub\Kifflom\Kifflom.FiveM.RP\src\client\Kifflom.FiveM.RP.Client.Logging\BaseScript.cs:30 
[     39172] [b2545_GTAProce]             MainThrd/ 
@justalemon
Copy link
Member

Hm... weird.

What specific LemonUI features are you using?

@justalemon justalemon added type: bug This is a bug status: needs info More information is needed to fix the bug or implement the feature priority: p4 not applicable Not a bug nor a feature labels Aug 2, 2022
@Sander0542
Copy link
Contributor Author

It happens when I load the library and not even use any of the features. Just adding the NuGet packages triggers the error.

When I add all the .cs files to the project and compile it there it works.

@justalemon
Copy link
Member

It happens when I load the library and not even use any of the features

Including the fxmanifest.lua reference? It needs to be added as a client script.

@Sander0542
Copy link
Contributor Author

I tried with and without the reference in the client_scripts property in the fxmanifest.lua

@Sander0542
Copy link
Contributor Author

This code sample doesn't work while using LemonUI.FiveM

public class ClientMain : BaseScript
{
    public ClientMain()
    {
        Tick += PlayerJoinedTick;
    }

    private async Task PlayerJoinedTick()
    {
        if (API.NetworkIsPlayerActive(API.PlayerId()))
        {
            Exports["spawnmanager"].setAutoSpawn(false);

            Tick -= PlayerJoinedTick;
        }
    }
}

@Sander0542
Copy link
Contributor Author

I did some testing myself and was able to build a NuGet package which works.

This commit fixes the error (I only tested with FiveM)
292e1f3

@justalemon
Copy link
Member

Ill take a deeper look tomorrow Sunday.

@TomStilson
Copy link

I'm gettting the same problem and I think its related to Exports in CitizenFX.Core. For some reason, if LemonUI is loaded, whenever you use Exports, the exception System.TypeLoadException: Could not resolve type with token 0100000e will be thrown.

@justalemon justalemon added 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 labels Aug 13, 2022
@justalemon
Copy link
Member

Pinpointed the problem back to version 1.3.0, so this was caused by something between 1.2.0 and 1.3.0.

Ill try to see what I can do, but I would expect this to be fixed in the FiveM codebase instead of a LemonUI patch, as is not a LemonUI bug.

@justalemon
Copy link
Member

image

@Sander0542
Copy link
Contributor Author

When I updated the build system in my branch, I got it to work with the latest FiveM version. I am not very experienced with the C# compiler, but maybe you could take a look at my branch and see what could have fixed it.

One change that stands out is the removal of the .net suffix in assembly name of the FiveM csproj

<AssemblyName>$(AssemblyName).net</AssemblyName>

Commit:
292e1f3

Compare:
master...Kifflom-Creations:LemonUI:master

Repo:
https://github.com/Kifflom-Creations/LemonUI

@justalemon
Copy link
Member

That could work, yes. But this appears to be a FiveM bug that needs to be diagnosed and fixed upstream.

By the way, have you tried to just rename LemonUI.FiveM.net.dll to LemonUI.FiveM.dll?

@Sander0542
Copy link
Contributor Author

By the way, have you tried to just rename LemonUI.FiveM.net.dll to LemonUI.FiveM.dll?

No, I have not tested that

@justalemon
Copy link
Member

Interesting...
image

@justalemon
Copy link
Member

Managed to trigger the same FiveM crash again:

image

@justalemon
Copy link
Member

Ill end up using the solution suggested by @Sander0542

Looks like FiveM doesn't knows how to deal with the libraries set as client_script(s), so you will always see one of this:

  • System.TypeLoadException: Could not resolve type with token 0100000e
  • mono-2.0-sgen.dll!memcpy (0x180) crash

The behavior changes depending on the LemonUI version. Recent versions (1.3-master) show the exception, while old versions (alpha-1.2) show the crash.

Not gonna lie, I have been trying to fix this shit for months, fucking burnout got me every single time.

As it turns out, it was FiveM all along.

@justalemon
Copy link
Member

@Sander0542 would you be kind to send the Pull Request? So you get the credit for the commit :)

@Sander0542
Copy link
Contributor Author

I created a pull request with the required changes #99

If you want me to implement GitVersion, so you don't have to manually change the version for every release, then let me know and I'll create another PR with that part

@justalemon justalemon added status: completed The feature has been completed of the bug has been patched and removed status: needs info More information is needed to fix the bug or implement the feature labels Nov 9, 2022
@justalemon justalemon added this to the 1.9.2 milestone Feb 21, 2023
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: completed The feature has been completed of the bug has been patched type: bug This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants