Aspects on interface properties are not inherited by descendants

alexander.jesner's Avatar

alexander.jesner

20 Sep, 2017 03:10 PM

Have a look at the following interface.
The [NotNull] aspect of the method is correctly applied on the derivative (the implementor of the interface).
The [NotNull] aspect of the property is lost.

    public interface IMyInterface
    {
        [NotNull]
        string Property { get; set; }

        void Method([NotNull] string arg);
    }

If I add [NotNull] to the property in the implementor it works as expected.

P# 4.3.32

  1. Support Staff 1 Posted by PostSharp Techn... on 21 Sep, 2017 03:52 PM

    PostSharp Technologies's Avatar

    Hello,

    I can confirm that this is a bug. We will be working on a fix.

    (issue #15522)

    Best regards,
    Daniel

  2. Support Staff 2 Posted by PostSharp Techn... on 02 Oct, 2017 03:30 PM

    PostSharp Technologies's Avatar

    Hello,

    We're closing the ticket for now as the bug has been internally filed as issue #15522. We will contact you as soon as the bug fix has been released.

    For more details on our support policies and prioritization of bug fixes, please visit https://www.postsharp.net/support/policies

    Thanks,
    PostSharp Team

  3. PostSharp Technologies closed this discussion on 02 Oct, 2017 03:30 PM.

  4. alexander.jesner re-opened this discussion on 23 May, 2018 01:13 PM

  5. 3 Posted by alexander.jesne... on 23 May, 2018 01:13 PM

    alexander.jesner's Avatar

    Any news on this one?
    We switched to PostSharp 5.0.46 and now I have a similar issue for abstract classes. In fact, this is a regression because this worked for abstract classes in 4.3.32

        [TestFixture]
        public class TestInheritance
        {
            public abstract class MySuperType
            {
                public abstract void DoSomething([NotNull] string s);
            }
    
            public sealed class MyImplementingType : MySuperType
            {
                public override void DoSomething(string s)
                {
                }
            }
    
            [Test]
            public void Test()
            {
                var x = new MyImplementingType();
    
                Assert.Throws<ArgumentNullException>(() => x.DoSomething(null));
                // -> never throws.
            }
        }
    
  6. Support Staff 4 Posted by PostSharp Techn... on 23 May, 2018 02:59 PM

    PostSharp Technologies's Avatar

    Hello,

    since fixing this bug requires bigger changes and there were issues of a higher priority, we had to plan this fix for a next version of PostSharp.

    I tried your latest example with PostSharp 5.0.46, but it works for me. Could you please share a complete project?

    Best regards,
    -tony

  7. 5 Posted by alexander.jesne... on 24 May, 2018 10:49 AM

    alexander.jesner's Avatar

    It seems that this only happens when the super-type is defined in a different project than the descending type.
    I crafted a test project that shows the behaviour.

  8. Support Staff 6 Posted by PostSharp Techn... on 24 May, 2018 03:21 PM

    PostSharp Technologies's Avatar

    OK, thank you! We'll check this and let you know whether we'll threat both as the same bug or if we'll fix the later one with a different priority.

    Best regards,
    -tony

  9. 7 Posted by alexander.jesne... on 05 Jun, 2018 04:44 PM

    alexander.jesner's Avatar

    Hi Tony, any news on this one? Were you able to reproduce the issue?

  10. Support Staff 8 Posted by PostSharp Techn... on 06 Jun, 2018 11:53 AM

    PostSharp Technologies's Avatar

    Hello,

    We are sorry for the delay with the response. Due to our mistake this discussion was skipped in our support workflow.

    We have reviewed your last sample again and noticed that you don't have PostSharp installed in your "b) Test" project. Even when you don't apply the aspects directly in the project, you still need PostSharp to process your assembly and apply the aspects inherited from the referenced project.

    After we install PostSharp NuGet package into "b) Test" project the test runs successfully. Please verify that installing PostSharp into "b) Test" project fixes the issue on your machine as well.

    Best regards,
    Alex

  11. 9 Posted by alexander.jesne... on 06 Jun, 2018 12:23 PM

    alexander.jesner's Avatar

    I tried this in our large production solution and you are right, installing PostSharp to the other projects solves this problem.
    I was thinking that with the new NuGet PackageReferences PostSharp should come in as a transitive dependency here, because e.g.: TestProject depends-on LibraryProject depends-on PostSharp.
    But as it seems this is not the case here...

    Thanks for your help!

  12. Support Staff 10 Posted by PostSharp Techn... on 06 Jun, 2018 01:05 PM

    PostSharp Technologies's Avatar

    Hello,

    PostSharp NuGet package needs to be installed explicitly in this case because it also modifies the project file to include additional step in the build process. Our PostSharp.Redist is the packages that serves as a redistributable transitive dependency (only library).

    Also, we have an update regarding the originally reported issue with the inheritance of attributes applied on properties. This has been promoted to a user story (#15652) and is currently in 6.1 version backlog.

    Best regards,
    Alex

  13. Support Staff 11 Posted by PostSharp Techn... on 27 Jun, 2018 04:02 PM

    PostSharp Technologies's Avatar

    Hello,

    We're closing the ticket for now as the user story has been internally filed as issue #15652. We will contact you as soon as the bug fix has been released.

    For more details on our support policies and prioritization of bug fixes, please visit https://www.postsharp.net/support/policies

    PostSharp Team

  14. PostSharp Technologies closed this discussion on 27 Jun, 2018 04:02 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac