Closed Entoarox closed 6 years ago
Please have a look at #2 and #27 since they have a similar error message. Your problem is not the method but the .NET version or your environment that causes this.
I am using VS2017 to compile the DLL, it is compiled for .NET 4.5 (A must since that is what Stardew Valley [which this is intended for] is written in) and running it on a windows 7 PC.
I have no clue how to solve this, so any help you can give would be much appreciated!
I tried to replicate your issue and found that you wrote ref bool __return
there in fact it is ref bool __result
. Not sure if this is the problem but at least make sure that you correct this.
Unfortunately, I get an access violation for any .NET version higher than 3.5 Here is my minimal test code:
using Harmony;
using System;
namespace HarmonyConsoleApp
{
class Program
{
static void Main(string[] args)
{
var harmony = HarmonyInstance.Create("test");
harmony.PatchAll(typeof(Program).Assembly);
var instance = new Subclass();
instance.SomeMethod();
Console.ReadKey();
}
}
public class Subclass : BaseClass
{
public override void SomeMethod()
{
Console.WriteLine("Subclass");
base.SomeMethod();
}
}
public class BaseClass
{
public virtual void SomeMethod()
{
Console.WriteLine("BaseClass");
}
}
[HarmonyPatch(typeof(BaseClass))]
[HarmonyPatch("SomeMethod")]
static class LocationPatch
{
public static void Prefix()
{
Console.WriteLine("Prefix");
}
}
}
I just found out that if you build Harmony in Release and run your .NET test code in Release too, it does not trigger an access violation exception and it can patch virtual methods just fine.
I am trying to patch a base virtual method, but the following error occurs when I do so:
(Please excuse any translation errors in the error message, I had to translate the error message to english so it might not be 100% correct)
The patch code is as follows:
I am probably making some mistake here on my end, but the wiki has been useless in helping solve this, so I am stuck.