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.

Coverlet changes order of attributes

See original GitHub issue

Versions: dotnet core 2.1 asp.net core 2.1.5 coverlet 2.5.0

Some of our tests that rely on the order of asp.net ValidationAttributes for method parameters fail when run with coverlet. Coverlet instrumentation seems to change the order of attributes.

e.g.

  method.GetParameters().ForEach(p =>
            {
                var validationAttributes = p.CustomAttributes.Where(a => typeof(ValidationAttribute).IsAssignableFrom(a.AttributeType))
                    .Select(a => a.AttributeType).ToList();
                if (validationAttributes.All(a => a != typeof(ShouldBeFirstAttribute))) return;
                if (validationAttributes.First() != typeof(ShouldBeFirstAttribute))
                {
                    Assert.Fail("Action: {0}.{1}(...) should have {2} declared before other validation attributes", type.FullName, method.Name,
                        typeof(ShouldBeFirstAttribute).Name);
                }
            });

This passes when run with \p:CodeCoverage=false

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
dorgoldcommented, Jul 31, 2019

Thanks @MarcoRossignoli! Just found a workaround till then, i’ll use the Order property of ActionFilterAttribute: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-2.2#overriding-the-default-order

1reaction
MarcoRossignolicommented, Jul 31, 2019

@dorgold I opened a PR to upgrade Cecil lib https://github.com/tonerdo/coverlet/pull/508 to avoid reordering…you can use nightly untill next release https://github.com/tonerdo/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

coverlet-coverage/coverlet: Cross platform code ...
Coverlet is a cross platform code coverage framework for .NET, with support for line, branch and method coverage. It works with .NET Framework...
Read more >
Coverlet is not considering the excludefromCoverage ...
Hi, I'm using the Coverlet to measure .NET core 3.1 Web API code coverage. I have used entity framework for creating by repository....
Read more >
Is it possible to change order of attributes when toJson()?
The problem about changing the order is "How can I do that for an inherited class?" as in my example. It extracts the...
Read more >
Implementing Order Management
To ignore changes to all extensible flexfield values, make sure Use Flexfield Attributes for each step in the Change Management area isn't enabled....
Read more >
Changing the order of block attributes in AutoCAD
Solution: To change the order of block attributes. Use the BATTORDER (Command) which specifies the order of attributes for a block.
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