question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PEVerify giving coded rid out of range after adding interface

See original GitHub issue

Hi,

I’ve just started using cecil so I’m sure I must be missing something. I’m attempting to static weave the INotifyPropertyChanged interface onto objects that are decorated with a custom attribute.

I can weave the IL into the properties just fine, but as soon as I try to add the interface I get the following error for PEVerify:

[MD]: Error (Structural): Table=0x00000009, Col=0x00000001, Row=0x00000003, has coded rid out of range.
1 Error(s) Verifying .\StaticWeaving.exe

I am using the following code to implement the interface on an AfterBuild task:

using (var notifyPropertyChangedAssembly = AssemblyDefinition.ReadAssembly(typeof(INotifyPropertyChanged).Assembly.Location))
                {
                    using (var assembly = AssemblyDefinition.ReadAssembly(AssemblyPath, new ReaderParameters { ReadWrite = true }))
                    {
                        foreach (var type in assembly.MainModule.Types)
                        {
                            if (type.CustomAttributes.Any(x => x.Constructor.DeclaringType.FullName == typeof(NotifyPropertyChangedAttribute).FullName))
                            {
                                if (!type.Interfaces.Any(x => x.InterfaceType.FullName == typeof(INotifyPropertyChanged).FullName))
                                {
                                    Log.LogMessage($"{type.FullName} has {nameof(NotifyPropertyChangedAttribute)} but no {nameof(INotifyPropertyChanged)} implementation. Weaving...");

                                    var notifyPropertyChangedType = notifyPropertyChangedAssembly.MainModule.Types.FirstOrDefault(x => x.FullName == typeof(INotifyPropertyChanged).FullName);

                                    Log.LogMessage(notifyPropertyChangedType.FullName);

                                    type.Interfaces.Add(new InterfaceImplementation(notifyPropertyChangedType));
                                }
                            }
                        }

                        assembly.Write();
                    }
                }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
SimonCroppcommented, Aug 16, 2019

“dismayed” ?

1reaction
SimonCroppcommented, Aug 16, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - PEVerify fails on explicit interface property when the ...
I'm emitting a class that explicitly implements a simple interface property with a get method. There are no problems so long as the...
Read more >
Peverify.exe (PEVerify Tool) - .NET Framework
The PEVerify tool helps developers who generate Microsoft intermediate language (MSIL) (such as compiler writers and script engine developers) ...
Read more >
June | 2009 - Visual Studio Extensibility (VSX)
ArgumentException “Value does not fall within the expected range.” when adding commands, buttons, commandbars, etc. Most of the AddXXX methods of the automation ......
Read more >
Untitled
Code de triche sur minecraft solo, Herbretaise automobile tires! Mosaic music festival 2011 super, Redresseur de courant pdf, Sambaram telugu movie mp3 ...
Read more >
ProvidedTypes.fs
The SDK for creating F# type providers. Contribute to fsprojects/FSharp.TypeProviders.SDK development by creating an account on GitHub.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found