Repository navigation
Description
In MIDL, developers can define methods that refer to properties in COM by attributing methods with particular signatures with the propget, propput, or propputref attributes. In built-in COM marshalling, .NET properties defined on a ComVisible(true) interface are turned into two slots on a vtable, a propget getter method and a propput setter method. For ComImport types imported with TLBImp, .NET properties are synthesized for propget and propput or propputref methods.
Note
If the property type is object, TLBs generated for a built-in .NET interface generate a propputref attribute instead of a propput attribute.
Currently, we block GeneratedComInterface interfaces from defining properties. We should look at providing support for properties in a similar way to the built-in .NET support for IUnknown-based interfaces.
We should consider introducing a feature to support specifying that particular methods provide the getter/setter implementation for a property as there is no restriction in COM that the propget and propput methods are sequential in the interface declaration (TLBImp supports defining a property that points to non-sequentially defined methods, but C# doesn't have a mechanism for it). Such a mechanism could be as simple as "define a default implementation of the property that calls the methods" and teach the COM source generator to ignore methods/properties that have default implementations.
API update.
In order to accomodate this effort naturally, we are also proposing the expansion of the MarshalUsingAttribute type to be applied to properties.
- [System.AttributeUsageAttribute(System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, AllowMultiple = true)]
+ [System.AttributeUsageAttribute(System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, AllowMultiple = true)]
public sealed partial class MarshalUsingAttribute : System.Attribute
{
}This will allow the application of a MarshalUsing in the following scenario.
partial interface INativeAPI
{
[MarshalUsing(typeof(TrackedIntMarshaller))]
int Value { get; set; }
}Contributes to #66674
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
StarRiver123 commentedon Jan 12, 2025
Does it Works in AOT?
m-celikba commentedon Jan 23, 2025
@jkoritzinsky is there an ETA for the property support ?
At least for propget and propput this is something that is vastly used when wrapping native COM object.
Not having property support is a breaking change when migrating to dotnet.
I found out that I can just mimic what's done on the C++ side.
This works:
This does not work:
If we had extension properties in c#, then this will be easier to fix.
m-celikba commentedon Sep 19, 2025
FYI: I've had success with this using extension properties from c#14 in dotnet10.
This provides portable code when migrating from dotnet framework builtin interop.
The only thing missing are indexers because the feature didn't make it to c#14.
Indexers appear when using IDispatch interfaces that expose collections.
example
// idl file
// c# interop
usage should be (because that's how it was in net framework):
@jkoritzinsky @jtschuster @AaronRobinsonMSFT
dotnet-policy-service commentedon Apr 13, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon May 28, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.
AaronRobinsonMSFT commentedon Jun 15, 2026
The expansion of support to properties of the
MarshalUsingattribute was approved offline./cc @bartonjs
Add support for properties in COM source generator (#128869)
Add support for properties in COM source generator (#128869)
Add support for properties in COM source generator (dotnet#128869)