citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.42k stars 2.01k forks source link

Missing .dll on Linux build of FXServer #2270

Open BuddiesTV opened 8 months ago

BuddiesTV commented 8 months ago

System.ComponentModel.Composition.dll is missing on Linux builds of the FXServer(should be here: citizen\clr2\lib\mono\4.5\Facades), which is why this following error occurs, would be good to have them added, so this issue is resolved.

Bug: I'm encountering an issue when using the Autofac's ContainerBuilder.build() function on a server-side application. The function works as expected on Windows, but throws an exception when run on Linux.

The exception thrown is System.TypeLoadException: Could not resolve type with token 0100009f from typeref (expected class 'System.Lazy`2' in assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51')

Here are the classes where the issue is reproducible:

ServerClass.cs:

using CitizenFX.Core;
using Server.Utils.Helper;
using Server.Utils.Misc;

namespace Server
{
    public class ServerClass : BaseScript
    {
        public static ServerClass instance;
        public ContainerHelper containerHelper;

        public Logger logger;

        public ServerClass()
        {
            ServerClass.instance = this;
            logger = new();

            containerHelper = new();
        }
    }
}

ContainerHelper.cs:

using Autofac;
using System.Reflection;
using System;
using System.Collections.Generic;
using Server.Utils.Models;
using Server.Utils.Enums;

namespace Server.Utils.Helper
{
    public class ContainerHelper
    {
        public IContainer container;
        public ILifetimeScope lifetimeScope;

        public ContainerHelper()
        {
            try
            {
                ContainerBuilder containerBuilder = new();

                List<Type> allModules = LoadAllTypes(typeof(Utils.Models.Module<>));

                allModules.ForEach((module) => {
                    containerBuilder.RegisterType(module)
                        .AsImplementedInterfaces()
                        .AsSelf()
                        .SingleInstance()
                        .OnActivated((m) =>
                        {
                            ModuleBase moduleBase = m.Instance as ModuleBase;
                            ServerClass.instance.logger.Log(LoggerType.Info, $"Loaded module {Misc.ConsoleColor.Green}{moduleBase.Name}");
                        });
                });

                container = containerBuilder.Build(); //<- Exception is thrown here

                lifetimeScope = container.BeginLifetimeScope();
                allModules.ForEach((module) => {
                    lifetimeScope.Resolve(module);
                });
            } catch(Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }

        public List<Type> LoadAllTypes(Type genericType)
        {
            List<Type> allTypes = new();

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == genericType)
                {
                    allTypes.Add(type);
                }
            }

            return allTypes;
        }
    }
}
thorium-cfx commented 8 months ago

Are you using the same libraries on both platforms?

It's odd as we don't offer assembly netstandard. Neither should System.Lazy2 be in there, are you sure it's not System.Lazy`2? if so then it should target either mscorlib or System.Runtime (type forward).

Edit: looking in client and both server files, System.Lazy`2 which should be in System.ComponentModel.Composition.dll seems to be absent completely.

BuddiesTV commented 8 months ago

Are you using the same libraries on both platforms?

Yes

It's odd as we don't offer assembly netstandard. Neither should System.Lazy2 be in there, are you sure it's not System.Lazy`2? if so then it should target ~either mscorlib or~ System.Runtime (type forward).

Yeah sorry, I meant System.Lazy`2 but because of formatting the ` got lost

Edit: looking in client and both server files, System.Lazy`2 which should be in System.ComponentModel.Composition.dll seems to be absent completely.

Yeah, the FXServer for windows ships with System.ComponentModel.Composition.dll, but the file is missing on linux

thorium-cfx commented 8 months ago

Yeah, the FXServer for windows ships with System.ComponentModel.Composition.dll, but the file is missing on linux

Just double checked this, Windows also doesn't come with it, did you add it yourself? https://runtime.fivem.net/artifacts/fivem/build_server_windows/master/

BuddiesTV commented 8 months ago

Just double checked this, Windows also doesn't come with it, did you add it yourself?

No I haven't added that, you need to look into the Facades Directory, the dll is in there citizen\clr2\lib\mono\4.5\Facades

thorium-cfx commented 8 months ago

Ah good find! Seems like I have some things to find out. Can you change this issue into a request for these files to be added to Linux (with the issue still explained) instead? (it will apply to both mono environments, so v1 can be removed)

BuddiesTV commented 8 months ago

Ah good find! Seems like I have some things to find out. Can you change this issue into a request for these files to be added to Linux (with the issue still explained) instead? (it will apply to both mono environments, so v1 can be removed)

Done, thanks for your time so far 👍