[ISSUE][C#]System.Drawing mismatch in fivem client lib

Found no issue template in source so report here.

There’s a mismatch between CitizenFX.Core.System.Drawing and default System.Drawing.
When using System.Drawing (using System.Drawing in code), It seems calling from System.Drawing in CitizenFX.Core.dll indeed.
However, we can’t use namespace System.Drawing in CitizenFX.Core.dll in code. Only the way to use it is to reference System.Drawing.dll from .net standard library path.

When using System.Drawing.Color in code:

  1. if sets reference path to client\citizen\clr2\lib\mono\4.5, source code won’t compile because System.Drawing.dll is an empty dll file in reference path.
  2. if set reference path to Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\ (which is default), it will compile. And in runtime, it seems calling from System.Drawing in CitizenFX.Core.dll indeed.

    (CitizenFX.Core.dll has its own System.Drawing namespce)
  3. AFAIK, there’s no way to use namespace System.Drawing in CitizenFX.Core.dll. We cannot write some code like CitizenFX.Core.System.Drawing.Color.Fromrgba and etc.
  4. Because class Color is not defined in System.Drawing.dll in fivem lib, we can’t refere this from Fivem library path, but from .Net standard lib.
  5. Since client picks its runtime environment from citizen\clr2\lib, we should use fivem client library as standard reference library path, instead of Microsoft .Net path.

There’s a facade assembly that will forward the few supported types to the implementation of System.Drawing in the CitizenFX.Core assembly. Color works fine if your assembly references the usual assembly identity for System.Drawing.

In general, there’s no “clean” set of reference assemblies for client usage yet; using the runtime assemblies is generally considered wrong due to the existence of facades like this one.

Thanks for reply.
So at present, should we use standard .net 4.5.2 assemblies in C# project?

I’ve found there are still some issues to use .net standard.

For example, use Color.Yellow in code will compile without problem but result in error in runtime , and the error trace is hard to track. Just because Color.Yellow is not defined in runtime assemblies.
(Below error trace show nothing about “non-exist” Color.Yellow error, which is hard to debug)

[ 2075188] Failed to instantiate instance of script wlMissionMostWantedDeliveryClient.MissionMostWantedDelivery: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.BadImageFormatException: Error verifying wlMissionMostWantedDeliveryClient.MissionMostWantedDelivery:ScheduleNewMission (): Cannot load method from token 0x0a00003e for call at 0x0055

[ 2075297] at wlMissionMostWantedDeliveryClient.MissionMostWantedDelivery…ctor () [0x00025] in C:\code\fivem\wlFreeroam\src\wlMissionMostWantedDeliveryClient\MissionMostWantedDelivery.cs:179

[ 2075407] at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)

[ 2075516] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in :0

[ 2075625] — End of inner exception stack trace —

[ 2075750] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00014] in :0

[ 2075860] at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in :0

[ 2075969] at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in :0

[ 2076078] at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in :0

[ 2076188] at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in :0

[ 2076297] at System.Activator.CreateInstance (System.Type type) [0x00000] in :0

[ 2076407] at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.String assemblyFile, System.Byte[] assemblyData, System.Byte[] symbolData) [0x000bb] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\InternalManager.cs:103