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

Crash caused by <PrivateImplementationDetails> in MonoMod.MonoModRules #78

Open
WEGFan opened this issue Jul 7, 2021 · 0 comments
Open
Labels

Comments

@WEGFan
Copy link

WEGFan commented Jul 7, 2021

Description

MonoMod will crash if a method in MonoMod.MonoModRules contains <PrivateImplementationDetails> called during patch. Mostly because of initializing an array of primitive types or having a switch with more than 6 case and the compiler optimizes the code to <PrivateImplementationDetails>.

MonoMod version: 21.6.21.1

Example

SharpLab link

namespace MonoMod {
    public static class MonoModRules {
        static MonoModRules() {
            bool[] boolArray = {true, true, true, true, true, true, true, true};
            byte[] byteArray = {1, 2, 3};
            sbyte[] sbyteArray = {-1, 2, -3};
            char[] charArray = {'a', 'b', 'c'};
            short[] shortArray = {-1, 2, -3};
            ushort[] ushortArray = {1, 2, 3};
            int[] intArray = {-1, 2, -3};
            nint[] nintArray = {-1, 2, -3};
            uint[] uintArray = {1, 2, 3};
            nuint[] nuintArray = {1, 2, 3};
            long[] longArray = {-1, 2, -3};
            ulong[] ulongArray = {1, 2, 3};
            float[] floatArray = {-1, 2, -3};
            double[] doubleArray = {-1, 2, -3};
            string str = "a";
            switch (str) {
                case "a":
                    break;
                case "b":
                    break;
                case "c":
                    break;
                case "d":
                    break;
                case "e":
                    break;
                case "f":
                    break;
                case "g":
                    break;
            }
        }
    }
}

Compile this code to MonoMod.PrivateImplementationDetails.mm.dll and run MonoMod.exe MonoMod.exe, then MonoMod will crash with the following log:

MonoMod 21.6.21.1
[MonoMod] Reading input file into module.
[MonoMod] [Main] Scanning for mods in directory.
[MonoMod] [ReadMod] Loading mod dir: D:\My Documents\Rider\PrivateImplementationDetailsTest\PrivateImplementationDetailsTest.Mod.mm\bin\net452
[MonoMod] [ReadMod] Loading mod: D:\My Documents\Rider\PrivateImplementationDetailsTest\PrivateImplementationDetailsTest.Mod.mm\bin\net452\MonoMod.PrivateImplementationDetailsTest.mm.dll
[MonoMod] [Main] mm.AutoPatch();
[MonoMod] [AutoPatch] Parsing rules in loaded mods
[MonoMod] [RulesModder] [Write] Writing modded module into output stream.
System.TypeInitializationException: The type initializer for 'MonoMod.MonoModRules' threw an exception. ---> System.MissingFieldException: Field not found: '<PrivateImplementationDetails>.039058C6F2C0CB492C533B0A4D14EF77CC0F78ABCCCED5287D84A1A2011CFB81'.
   at MonoMod.MonoModRules..cctor()
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.RuntimeHelpers._RunClassConstructor(RuntimeType type)
   at MonoMod.InlineRT.MonoModRulesManager.ExecuteRules(MonoModder self, TypeDefinition orig)
   at MonoMod.MonoModder.ParseRules(ModuleDefinition mod)
   at MonoMod.MonoModder.AutoPatch()
   at MonoMod.Program.Main(String[] args)
@WEGFan WEGFan added the bug label Jul 7, 2021
@WEGFan WEGFan changed the title Crash related to <PrivateImplementationDetails> in MonoMod.MonoModRules Crash caused by <PrivateImplementationDetails> in MonoMod.MonoModRules Jul 7, 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