Using Fody/Mono.Cecil, I'm attempting to modify IL post build to turn some fields and methods to static.
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;
}
}
However, PEVerify complains
MSBUILD : error : [IL]: Error: \xamarin.ios10\LibVLCSharp.dll : LibVLCSharp.Shared.MediaPlayer::add_PositionChanged][offset 0x00000038] Unrecognized arguments for delegate .ctor.(Error: 0x801318AA)
2>MSBUILD : error : [IL]: Error: \xamarin.ios10\LibVLCSharp.dll : LibVLCSharp.Shared.MediaPlayer::remove_PositionChanged][offset 0x00000038] Unrecognized arguments for delegate .ctor.(Error: 0x801318AA)
2>MSBUILD : error : [IL]: Error: \xamarin.ios10\LibVLCSharp.dll : LibVLCSharp.Shared.MediaPlayer::OnPositionChanged][offset 0x00000002][found Native Int][expected ref 'LibVLCSharp.Shared.MediaPlayer'] Unexpected type on the stack.(Error: 0x80131854)
Regarding the first 2 errors, my understanding is even though I set the field to static, references to it did not get the message and are still using .this
(ldarg.0
) to perform the call which makes the IL invalid. Tried removing that instruction but got other errors. Is my assumption correct? How do I fix it?
Regarding the last error, I'd say some IL magic is needed as well but looking at Body.Instructions
, no idea what.
Any help welcome.
User contributions licensed under CC BY-SA 3.0