Set field and method to static

41 views
Skip to first unread message

Martin Finkel

unread,
Sep 17, 2018, 12:03:31 PM9/17/18
to mono-cecil
Hello,

I'm using a Fody weaver to modify a xamarin.ios dll post build to satisfy the [MonoPInvokeCallback] requirements.

foreach (var type in ModuleDefinition.Types)
{
   
foreach (var f in type.Fields.Where(IsEventHandler))
   
{
        f
.IsStatic = true;
   
}

   
foreach (var m in type.Methods.Where(NeedStaticKeyword))
   
{
        m
.IsStatic = true;
        m
.HasThis = false;
   
}
}

This makes PEVerify complain about IL

2>MSBUILD : error : [IL]: LibVLCSharp.Shared.MediaPlayer::add_PositionChanged][offset 0x00000038] Unrecognized arguments for delegate .ctor.(Error: 0x801318AA)
2>MSBUILD : error : [IL]: LibVLCSharp.Shared.MediaPlayer::remove_PositionChanged][offset 0x00000038] Unrecognized arguments for delegate .ctor.(Error: 0x801318AA)
2>MSBUILD : error : [IL]: LibVLCSharp.Shared.MediaPlayer::OnPositionChanged][offset 0x00000002][found Native Int][expected ref 'LibVLCSharp.Shared.MediaPlayer'] Unexpected type on the stack.(Error: 0x80131854)
2>MSBUILD : error : [IL]: LibVLCSharp.Shared.MediaPlayer::OnPositionChanged][offset 0x0000000E] Unrecognized argument number.(Error: 0x80131868)

I had a look at the `Body.Instructions` of the concerned methods/events, and tried removing `OpCodes.Ldarg_0` but that caused other issues and I don't even know if that's the right way to deal with those errors. I'm far from fluent in IL.

Any help is greatly appreciated.

Best,

mfkl

Jb Evain

unread,
Sep 17, 2018, 12:07:47 PM9/17/18
to mono-...@googlegroups.com
Hey Martin,

From the C# you're showing, that looks like a big breaking change. Turning fields and methods static is going to break a lot of things, and will require you to change basically all the code using those fields and methods.

Jb

--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Finkel

unread,
Sep 17, 2018, 12:14:53 PM9/17/18
to mono-cecil
Not something you would recommend then. I will look for another way I guess.

Thank you for your message.
Reply all
Reply to author
Forward
0 new messages