Skip to content

Specify SizeConst when marshalling field as ByValArray #36134

Closed
dotnet/roslyn
#68992

Description

@elinor-fung

When marshalling using UnmanagedType.ByValArray, the SizeConst field should be specified.

struct MyStruct
{
    [MarshalAs(UnmanagedType.ByValArray)]
    int[] Foo;
}

Category: Interoperability
Default: Enabled

cc @terrajobst @stephentoub @AaronRobinsonMSFT @jkoritzinsky

Activity

  1. added
    api-suggestion
    code-analyzer
    on May 8, 2020
  2. added
    untriaged
    on May 8, 2020
  3. AaronRobinsonMSFT commented on May 10, 2020

    @AaronRobinsonMSFT
    Member

    I think any of these type of requirements should be in some analyzer.

  4. removed
    untriaged
    on Jun 8, 2020
  5. added this to the 5.0 milestone on Jun 8, 2020
  6. modified the milestones: 5.0.0, 6.0.0 on Jul 21, 2020
  7. modified the milestones: 6.0.0, 7.0.0 on Jul 9, 2021
  8. added
    api-ready-for-review
    and removed
    api-suggestion
    on Jul 9, 2021
  9. terrajobst commented on Jul 13, 2021

    @terrajobst
    Contributor
    • The analyzer should probably also handle UnmanagedType.ByValTStr
      • Should be the same diagnostic ID with a slightly different message
    • Assuming code like this wouldn't work at runtime, turning the rule on by default seems fine
      • If code like this works today, then on by default might be noisy
  10. added
    api-approved
    and removed
    api-ready-for-review
    on Jul 13, 2021
  11. modified the milestones: 7.0.0, 8.0.0 on Jul 6, 2022
  12. added
    help wanted
    on Jul 6, 2022
  13. jkoritzinsky commented on Jul 10, 2023

    @jkoritzinsky
    Member

    Roslyn already requires SizeConst for ByValTStr. Should we instead extend Roslyn to also require SizeConst for ByValArray instead of writing a separate analyzer?

  14. added
    in-pr
    on Jul 19, 2023
  15. ghost locked as resolved and limited conversation to collaborators on Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Runtime.InteropServicescode-analyzerhelp wantedin-pr

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions