MessageLocation is not correctly resolved to file and line.

thijs.te.paske's Avatar

thijs.te.paske

16 Aug, 2017 10:07 AM

I wrote a custom ScalarConstraint with the following ValidateCode:

    public override void ValidateCode(object target)
    {
      if (target is FieldInfo fieldInfo && !typeof(Shader).IsAssignableFrom(fieldInfo.DeclaringType))
      {
        Message.Write(
          MessageLocation.Of(fieldInfo),
          SeverityType.Error,
          ConstraintCodes.UniformBufferAttributeRequiresShaderField,
          ConstraintMessages.UniformBufferAttributeRequiresShaderField,
          typeof(UniformBufferAttribute),
          typeof(Shader));
      }
    }

However the 'MessageLocation.Of(fieldInfo)' does not seem to resolve to the correct file-location when the Message.Write has been executed. Instead of the correct file location I get to see: "{directory}\packages\PostSharp.5.0.31\build\PostSharp.targets(329,5): {errorCode}: {errorMessage}".

I use VS2017 with PostSharp 5.0.31

  1. Support Staff 1 Posted by PostSharp Techn... on 16 Aug, 2017 12:43 PM

    PostSharp Technologies's Avatar

    Hello,

    Thank you for reporting this bug.

    We're closing the ticket for now as the bug has been internally filed as issue #15353. 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

    Best regards,
    -tony

  2. PostSharp Technologies closed this discussion on 16 Aug, 2017 12:43 PM.

  3. PostSharp Technologies re-opened this discussion on 23 Aug, 2017 10:11 AM

  4. Support Staff 2 Posted by PostSharp Techn... on 23 Aug, 2017 10:11 AM

    PostSharp Technologies's Avatar

    Hello,

    after further investigation, I've figured out that this might be caused by a fact, that the MessageLocation.Of() method does not work when the declaring type of the location doesn't contain any methods. (No matter if the location is a method or other element.)

    Could you please check if this is the case?

    Best regards,
    -tony

  5. 3 Posted by thijs.te.paske on 24 Aug, 2017 10:16 AM

    thijs.te.paske's Avatar

    Hello Tony,

    Yes, this seems to be the case. Once I add 'void Foo()' method to the structure where the attribute has been used the location is correctly resolved.
    Is this intended behavior, or is it a bug according the PostSharp team?

    Kind regards,
    Thijs

  6. Support Staff 4 Posted by PostSharp Techn... on 25 Aug, 2017 03:07 PM

    PostSharp Technologies's Avatar

    Hello,

    it's a current limitation of our implementation as we are using sequence points to determine the file in which the declaration is. While we may improve it in the future, it's not a bug per se.

    Thanks.

    Best regards,
    Daniel

  7. Support Staff 5 Posted by PostSharp Techn... on 05 Sep, 2017 02:57 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as we believe it was answered. Please feel free to reopen the discussion if you need more help.

    Best regards,
    PostSharp Team

  8. PostSharp Technologies closed this discussion on 05 Sep, 2017 02:57 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