Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
MarshalAs for Properties in a struct

I am trying to add getters and setters to this struct, so I can use it as a listView items source. The problem is, this causes MarshalAs to be invalid thus not allowing compilation. What would the best option be to fix this?

Attribute 'MarshalAs' is not valid on this declaration type. It is only valid on 'field, parameter, return' declarations.**

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct FileExplorerData
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 251)]
        public string name { get; set; }
        public FILETIME lastwrite { get; set; }
        public bool type { get; set; }
        public int size { get; set; }
    };
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can specify the underlying field as the target of the attribute

[field: MarshalAs(UnmanagedType.ByValTStr, SizeConst = 251)]
public string name { get; set; }

This is valid from C# 7.3+. See the documentation.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!