Skip to content

C#: Cannot use in parameter with generic method override on Linux #1554

Open
@impulsh

Description

@impulsh

An exception is thrown when overriding a generic class method with an in parameter. This works fine on a Windows client and server, but the same code on a Linux server fails loading the assembly. Tested with build 5777.

I'm not sure what version of Mono is used - or how easy it would be to cherry-pick some commits if need be, but I've come across mono/mono#10834 and believe this is the same issue, with mono/mono#12802 being the fix.

Minimal repro:

using CitizenFX.Core;

namespace Test
{
	public abstract class MyGenericClass<T>
	{
		public abstract void MyMethod(in T value);
	}

	public class MyDerivedClass<T> : MyGenericClass<T>
	{
		public override void MyMethod(in T value)
		{
			Debug.WriteLine(value.ToString());
		}
	}

	public class TestScript : BaseScript
	{
		public TestScript()
		{
			MyDerivedClass<Vector3> test = new MyDerivedClass<Vector3>();
			test.MyMethod(Vector3.Zero);
		}
	}
}

Exception thrown:

Failed to instantiate instance of script Test.TestScript: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  ---> System.TypeLoadException: Could not find method '.ctor' due to a type load error: Type Test.MyDerivedClass`1[T] has invalid vtable method slot 4 with method none assembly:data-0x7fb6516fdda0 type:MyDerivedClass`1 member:(null)
  at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <9391d7651e69459eae268d8a1dfa670f>:0
   --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00017] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x000a8] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00020] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <9391d7651e69459eae268d8a1dfa670f>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <9391d7651e69459eae268d8a1dfa670f>:0
  at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.String assemblyFile, System.Byte[] assemblyData, System.Byte[] symbolData) [0x0007b] in /src/code/client/clrcore/InternalManager.cs:156

Metadata

Metadata

Assignees

No one assigned

    Labels

    ScRT: C#Issues/PRs related to either C# scripting runtimes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions