How to remove all DebuggerHiddenAttribute

How can I remove all DebuggerHiddenAttribute from the assembly only if the compiler generated this attribute?

I am trying to use this code, but it does not work.

    ModuleDefinition module = ...;
MethodDefinition targetMethod = ...;
MethodReference attributeConstructor = module.Import(
    typeof(DebuggerHiddenAttribute).GetConstructor(Type.EmptyTypes));

targetMethod.CustomAttributes.Remove(new CustomAttribute(attributeConstructor));
module.Write(...);

Thanks in advance.

0
source share
1 answer

This is not real. Attributes defined in the compiled assembly are immutable. You cannot change them without reproducing the entire assembly.

In this particular answer, when you call Remove, it is called in the array returned by the property CustomAttributes. It will remove it from the array, not from the metadata on the assembly

0
source

Source: https://habr.com/ru/post/1653159/


All Articles