Skip to content

Plans to migrate to LibraryImportAttribute? #593

Closed as not planned
Closed as not planned

Description

Are there plans to migrate to LibraryImportAttribute for .NET7+?

Activity

  1. AArnott commented on Jun 24, 2022

    @AArnott
    Member

    This is the first I've heard about the attribute. I've heard about the source generator that avoids relying on the .NET runtime for interop code. CsWin32 is actually pretty close to this already for extern methods because if you turn off marshaling (a CsWin32 setting) we emit blittable, non-marshaled extern methods, and replace COM interfaces with blittable structs. It's not the most friendly API, but it's a start toward this if folks really want this.

  2. elachlan commented on Jun 24, 2022

    @elachlan
    ContributorAuthor

    Thanks for the reply!

    What about function pointers? Would they work/make sense in CSWin32 or are they already implemented?
    dotnet/winforms#4135

    eg:
    dotnet/winforms#4003

  3. AArnott commented on Jun 25, 2022

    @AArnott
    Member

    Yes, CsWin32 already generates function pointers where needed.

  4. alexrp commented on Jul 8, 2022

    @alexrp

    It's worth noting that CsWin32's support for disabling marshalling won't actually be usable with DisableRuntimeMarshallingAttribute yet because of SetLastError: https://docs.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling#disabled-features

    LibraryImportAttribute supports generating appropriate code for SetLastError, so that's a point in favor of using it.

  5. AArnott commented on Aug 10, 2022

    @AArnott
    Member

    Given Roslyn doesn't support chaining source generators. CsWin32 already does a significant amount of work to avoid relying on .NET marshaling already, and has just a bit more to do (#600).
    If we need more from LibraryImport, we'll just have to borrow code (or even the dll) from that source generator.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions