Comments (15)
I prioritized Mono but that does not mean that with a few checks one couldn't add .NET compatibility. I think I address this in the future or let someone else do it in a pull request. I am pretty sure that it is possible to have one version of Harmony that supports both environments.
from harmony.
Can you specify your settings? Which Mono version, OS or application? Did you use the release version of Harmony or the latest master? I agree, it should work.
It is a bit weird that your stack trace points to the creation of the DynamicMethod. At that time, nothing has been created or patched yet so it is not related to how you patch. I never had that error "Only public, static, standard supported". Sounds like your runtime is non-standard.
C:\repo\Harmony\Harmony\Tools\DynamicTools.cs:line 22
var method = new DynamicMethod(
patchName,
MethodAttributes.Public | (original.IsStatic ? MethodAttributes.Static : 0),
CallingConventions.Standard,
AccessTools.GetReturnedType(original),
paramTypes,
original.DeclaringType,
true
);
You can clearly see that it is public and standard and in my environment it adding static or not does not matter. A dynamic method is by nature static with a possible instance parameter as the beginning. One thing you could to, is to test if you succeed by removing the optional "original.IsStatic" and always have "MethodAttributes.Public | MethodAttributes.Static" instead:
var method = new DynamicMethod(
patchName,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
AccessTools.GetReturnedType(original),
paramTypes,
original.DeclaringType,
true
);
Let me know your findings,
Andreas
from harmony.
Well, I'm not using Mono, and that may be the problem. I'm using a unit test framework on .NET 4.5.1, but I thought it might work the same.
from harmony.
Yes, it might even be that it works different outside of unit testing. Anyway, you should really try to do the edit I suggested and see if that works.
from harmony.
Hey, that seems to have worked partially! I now get an error in DynamicTools.cs:line 75
. It's not finding the CreateDynMethod
method on the DynamicMethod
class. Inspecting it, I couldn't find that method either. It may be due to a change in the structure of DynamicMethod
past .NET 3.5. I'll continue digging.
UPDATE:
Just realized that the .NET version shouldn't be changing, and that Harmony is still targeting 3.5, so it shouldn't have failed to find that method. Thoughts?
Update 2:
Pulled latest master
, still seeing this behavior.
from harmony.
Should the line be
typeof(DynamicTools).GetMethod("CreateDynamicMethod", BindingFlags.NonPublic | BindingFlags.Instance);
instead of
typeof(DynamicMethod).GetMethod("CreateDynMethod", BindingFlags.NonPublic | BindingFlags.Instance);
?
from harmony.
No. That line actually gets a private method inside DynamicMethod to compile it. Pretty certain it is Mono specific.
from harmony.
Well, that might be the problem then :P. I wonder if I can find something suitable to use outside of Mono...
from harmony.
In .NET CreateDynMethod doesn't exist in DynamicMethod class and I see no similar construct. But even if you surpass this problem then you get against next wall which is native calls to mono libs. At this point I just gave up.
I rally would like to use this library, shame.
from harmony.
In my early experiments, I had a different strategy to force creation of the dynamic method: I simply "pre-run" them by calling them. Since it's a dynamic method one could add a small IL header to the method that simply returns directly and then call into your newly build method. The trick is then to find the right start point in the resulting assembler code after that immediate return. Use that as the destination of the assembler jump from the original method and you're done.
Alternatively, one could add IL code using a static "firstTime" bool to do the same. This will remove the need to find a different start in the assembler but at the cost of an extra if-check which makes it a slower approach.
Finally, the mono calls are just for getting the jit-ed assembler code starting location. I think that this can be done in MS.NET too but in a different way.
from harmony.
Please try the latest changes that were merged into the master and report back any findings.
from harmony.
@pardeike it works now for me, thanks!
from harmony.
Excellent!
from harmony.
When will this fix be released?
from harmony.
Releases are rather sparse because they require a very good quality level. Mostly because of other applications and communities depend on a stable version.
I am working towards a v1.1 release within the coming weeks.
from harmony.
Related Issues (20)
- NuGet Package reference assembly conflict HOT 8
- ModuleInitializerAttribute HOT 1
- RtDynamicMethod get MetadataToken throws InvalidOperationException HOT 2
- Patch on .net 7&8 throw TypeLoadException while debugging HOT 18
- 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)
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.