Comments (13)
This is my test case. Done in VS2017, with .NET 4.6.1 and Release build:
using Harmony;
using System;
namespace HarmonyConsoleApp
{
class Program
{
static void Main(string[] args)
{
var a = new Test();
var harmony = HarmonyInstance.Create("com.company.project.product");
var original = typeof(Test).GetMethod("Call");
var prefix = typeof(Patch).GetMethod("Before");
var postfix = typeof(Patch).GetMethod("After");
harmony.Patch(original, new HarmonyMethod(prefix), new HarmonyMethod(postfix));
var b = new Test();
Console.WriteLine("a=" + a.Call());
Console.WriteLine("b=" + b.Call());
Console.ReadKey();
}
}
public class Test
{
// if Call() is too simple, it will get inlined and no patching is ever possible
/*
public string Call()
{
return "ORIGINAL";
}*/
public string Call()
{
var c = new char[] { 'O', 'R', 'I', 'G', 'I', 'N', 'A', 'L' };
return string.Join("", c);
}
}
public class Patch
{
public static bool Before(ref object __result)
{
Console.WriteLine("Before..");
__result = "PATCHED";
return false;
}
public static void After()
{
Console.WriteLine("After");
}
}
}
from harmony.
Seems to be a .NET 4+ issue. Works with 3.5. Any quickfix ideas?
from harmony.
Did you test with the master version?
from harmony.
yes. just cloned again.
and release mode seems to be not supported at all?
from harmony.
The release is currently for unity (mono) only. Iām working on incorporating the pull requests to make an new master.
from harmony.
so next master branch will support release mode and .net 4+?
from harmony.
kinda sorted it out. The master branch downloaded as zip doesn't include the AccessViolation Fix. It doesn't even contain the NativeLibrary.cs
.
Seems like it was reverted by hcoona.
however, git clone ..
gets a master branch with the fix included, but still not solving the AccessViolation Exception
on my Windows 10 x64, with .NET 4.0+ versions.
from harmony.
Maybe this is related to the content of your patch? Usually, access violations appear when patching, not during runtime. Or you are running this in a specific environment that enforces access rules more aggressively. Can you provide more details?
from harmony.
this is the content of my patch / target class, in a clean Console app project just attached to the Harmony solution:
public class Test
{
public string Call()
{
return "asd";
}
}
public class Patch
{
public static bool Before(ref object __result)
{
Console.WriteLine("Before..");
__result = "asdfa";
return false;
}
public static void After()
{
Console.WriteLine("After");
}
}
the difference which makes this patch work is either:
- in .Net 4+; have all
new Test()
instantiations before patching - or .Net 3.5
- all .net versions; only Debug mode support (release mode completely ignoring patch, no exceptions either. the original target method being invoked as if there was no patch at all.)
my environment is windows 10 x64 (no vbox) with VS 2015.
that enforces access rules more aggressively
where to look further?
thanks
from harmony.
trying public static bool Before(ref string __result)
just crashed the whole OS with a bluescreen
from harmony.
It should not. The prefix is called from within the main method as a subroutine and the ref argument is put on the call stack as an ordinary IL code. All you should get is a an exception from the CIL execution which cannot drag your binary down like you describe.
from harmony.
yes it shouldn't normally. happened once strangely.. cant get it there again without code change
from harmony.
Cannot reproduce with latest version
from harmony.
Related Issues (20)
- Harmony 3.0: Utility Epic
- Investigate Testing the NuGet Package Directly HOT 3
- Add a Release Pipeline
- Hook exception: System.Exception: Cannot get result from void method System.Void HOT 2
- How to patch method of base class? HOT 1
- When applying a patch fails, the replacement's IL is not printed to the debug log HOT 2
- System.Exception: Parameter "xx" not found in method HOT 10
- SymbolExtensions does not resolve overriden method HOT 3
- can lib work in arm64? HOT 2
- Companion project promotion: Harmony Tools HOT 3
- PatchFunctions.UpdateWrapper NotImplementedException on MacOS HOT 11
- How do i change valuetype HOT 1
- Harmony.Patch() is a bit slow. HOT 2
- 'CORINFO_METHOD_INFO' from assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. HOT 4
- I try to hook DateTime.UtcNow but it throw exception HOT 5
- IL Compile Error when using PrefixFactory to provide a non-static Prefix method (Mono)
- x86 platform makes patch fail
- return type only support void and bool? why doesn't string work HOT 1
- Could not load type 'CORINFO_METHOD_INFO' from assembly 'System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. HOT 1
- "ref" keyword not allowed for "__runOriginal" HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmony.