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

patch_ class doesn't get relinked when used in argument of an attribute #80

Open
WEGFan opened this issue Aug 27, 2021 · 0 comments
Open
Labels

Comments

@WEGFan
Copy link

WEGFan commented Aug 27, 2021

Description

If a patch_ class is used in the System.Type argument of an attribute, it will not be relinked to the actual class after patching.

MonoMod version: 21.8.19.1

Example

Main project, compiles to ConsoleApp.exe:

using System;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;

namespace ConsoleApp {
    public class TestAttribute : Attribute {
        public Type Type { get; set; }

        public TestAttribute(Type type) {
            Type = type;
        }
    }

    public class PatchClass {
        public static void TestMethod() {
        }
    }

    public static class Program {
        public static void Main(string[] args) {
            Type type = typeof(PatchClass).GetMethod("TestMethod")
                .CustomAttributes
                .First(attr => attr.AttributeType == typeof(TestAttribute))
                .ConstructorArguments[0]
                .Value as Type;
            Console.WriteLine(type.FullName);
        }
    }
}

Patcher project, compiles to ConsoleApp.Mod.mm.dll:

using System;
using MonoMod;

namespace ConsoleApp {
    public class patch_PatchClass : PatchClass {
        [MonoModReplace]
        [Test(typeof(patch_PatchClass))]
        public new static void TestMethod() {
        }
    }
}

Run MonoMod.exe ConsoleApp.exe in command line, and open MONOMODDED_ConsoleApp.exe, it should outputs ConsoleApp.PatchClass, but it throws this exception instead:

Unhandled Exception: System.TypeLoadException: Could not load type 'ConsoleApp.patch_PatchClass' from assembly 'ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.RuntimeTypeHandle.GetTypeByNameUsingCARules(String name, RuntimeModule scope, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByNameUsingCARules(String name, RuntimeModule scope)
   at System.Reflection.CustomAttributeTypedArgument.ResolveType(RuntimeModule scope, String typeName)
   at System.Reflection.CustomAttributeTypedArgument..ctor(RuntimeModule scope, CustomAttributeEncodedArgument encodedArg)
   at System.Reflection.CustomAttributeData.get_ConstructorArguments()
   at ConsoleApp.Program.Main(String[] args)
@WEGFan WEGFan added the bug label Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant