I am using the following code in a Utils script and calling this variable each time I want to create a HttpClient:
public static IHttpClientFactory httpClientFactory = new ServiceCollection().AddHttpClient().BuildServiceProvider().GetService<System.Net.Http.IHttpClientFactory>();
I have included all the dependencies under the plugins folder such the Microsoft.Extensions.DependencyInjection.dll and its respective dependencies dlls. When compiled with mono scripting backend the game server runs fine. the problem when compiling with IL2CPP I get the following error and the program seems to halt:
ArgumentNullException: Value cannot be null.
Parameter name: obj
at System.Threading.Monitor.ReliableEnterTimeout (System.Object obj, System.Int32 timeout, System.Boolean& lockTaken) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Monitor.ReliableEnter (System.Object obj, System.Boolean& lockTaken) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Monitor.Enter (System.Object obj, System.Boolean& lockTaken) [0x00000] in <00000000000000000000000000000000>:0
at Microsoft.Extensions.DependencyInjection.DependencyInjectionEventSource.ServiceProviderBuilt (Microsoft.Extensions.DependencyInjection.ServiceProvider provider) [0x00000] in <00000000000000000000000000000000>:0
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor (System.Collections.Generic.ICollection`1[T] serviceDescriptors, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options) [0x00000] in <00000000000000000000000000000000>:0
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider (Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options) [0x00000] in <00000000000000000000000000000000>:0
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider (Microsoft.Extensions.DependencyInjection.IServiceCollection services) [0x00000] in <00000000000000000000000000000000>:0
at Utils..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Myscript.Awake () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for 'Utils' threw an exception.
at Myscript.Awake () [0x00000] in <00000000000000000000000000000000>:0
I tried different methods I included the Link.xml file in my assets folder reading the following but the same error keep popping out:
<linker>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
</assembly>
<assembly fullname="Plugins/Microsoft.Extensions.Http" preserve="all" />
<assembly fullname="Plugins/Microsoft.Extensions.Logging.Abstractions" preserve="all" />
//The rest of the dlls included in the plugins folder declared in the same manner...
</linker>