Skip to content

Marshal.GetObjectForNativeVariant is obsoleted with no workaround provided #28564

Closed

Description

@jbartlau

When using Marshal.GetObjectForNativeVariant, this gives a warning:

warning CS0618: 'Marshal.GetObjectForNativeVariant(IntPtr)' is obsolete: 'GetObjectForNativeVariant(IntPtr) may be unavailable in future releases.'

We heavily rely on being able to interop with variants (which actually works just fine in Core 3 Preview 2). Would be happy to move to a different technique, however the warning doesn't contain a suggested way to do things right. Does the obsoletion make sense? What's the future proof way to marshal variants then?

Activity

  1. vcsjones commented on Jan 30, 2019

    @vcsjones
    Member
  2. AaronRobinsonMSFT commented on Jan 31, 2019

    @AaronRobinsonMSFT
    Member

    Thanks @vcsjones.

    @jbartlau The obsolete statement is a nuanced indication about the intent of certain APIs and scenarios involving CoreCLR. As you probably know VARIANT is related to the COM and OLE technologies on the Windows platform. This fact makes it somewhat hard to reconcile with CoreCLR's goal of being an environment where one can build enterprise level cross-platform applications. The API doesn't really make sense in that environment and as such is "obsolete". The ugly truth of the matter is that the statement "may be unavailable in future releases", although technically possible, is highly unlikely. As long as there are still developers writing applications for .NET Core to run on Windows or porting .NET Framework applications to .NET Core, this API isn't going anywhere.

    What's the future proof way to marshal variants then?

    If your application is targeting Windows and only Windows, this API is fine to use and will be around for years to come. If there are plans for your application to run on non-Windows platforms, I would suggest avoiding any API that relates to VARIANT for the time being since support on non-Windows platform is still in question.

    cc @jeffschwMSFT

  3. jbartlau commented on Jan 31, 2019

    @jbartlau
    Author

    @AaronRobinsonMSFT Totally understood. Indeed, we're targeting Windows and only Windows, however we'd like to be able to use CoreCLR as it is more lightweight, faster and gets new features earlier (or even at all).

    Good to know there are actually no plans to remove this in the future. Maybe the obsoletion message should read a bit different then to save others from the same worries. Something like "not portable at all, not recommended to use if there are any plans to ever move to a cross-platform approach".

    Just for completeness, the same holds for a couple of other related enums and APIs like VarEnum, Marshal.GetObjectForNativeVariant or the generic Marshal.GetNativeVariantForObject<T>.

    Anyway, thanks for the reassurance, issue could be closed if no further steps will be taken.

  4. AaronRobinsonMSFT commented on Jan 31, 2019

    @AaronRobinsonMSFT
    Member

    @jkotas or @jeffschwMSFT could this be one of those APIs that got marked obsolete by accident? I can't ever see this being used outside of Windows, but as @jbartlau said the messaging is a bit strong for something that isn't going to happen - i.e. removal.

  5. jkotas commented on Jan 31, 2019

    @jkotas
    Member

    could this be one of those APIs that got marked obsolete by accident?

    I think so.

  6. AaronRobinsonMSFT commented on Feb 1, 2019

    @AaronRobinsonMSFT
    Member

    @stephentoub, @jkotas, @jeffschwMSFT,

    Are there any concerns about removing the System.ObsoleteAttribute attribute from the VARIANT family of functions? As pointed out the messaging is a bit misleading because I can't see anyway we would ever remove these functions, however I can see the attribute as a way to prompt users to seriously reconsider designs if possible. Thoughts?

    https://github.com/dotnet/corefx/blob/bcb76015585c91a1dfa63df68ef392bed317e8dd/src/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs#L561-L572

  7. stephentoub commented on Feb 1, 2019

    @stephentoub
    Member

    When were they marked as obsolete? Seems like they're marked in both .NET Core and .NET Framework. Any idea when it happened in netfx?

  8. jkotas commented on Feb 1, 2019

    @jkotas
    Member

    Where do you see them marked as obsolete for .NET Framework?

    It happened during .NET Native when folks tried to make interop APIs to either AOT-friendly (it is where all the generic overloads for Marshal.SizeOf, etc. came from) or obsolete them (when the API does not have a clear bound on the interop code it needs). These changes were done on a dogfood TFS server that was retired since then. I do not know where the soruce code history for that period lives to get you more details.

  9. AaronRobinsonMSFT commented on Feb 1, 2019

    @AaronRobinsonMSFT
    Member

    I believe the doc in this case is merely a reflection of what is in the corefx repo. I can't remember all the details but how the official doc relates to what is in corefx is kind of wonky and doesn't necessarily reflect an accurate view for each framework.

    At this point it sounds like this was a bit aggressive and I can remove the attributes.

  10. stephentoub commented on Feb 1, 2019

    @stephentoub
    Member

    Sounds fine to me.

  11. jkotas commented on Feb 1, 2019

    @jkotas
    Member

    The docs are not showing the right obsolete attributes in many cases dotnet/dotnet-api-docs#1184

  12. danmoseley commented on Feb 4, 2019

    @danmoseley
    Contributor

    @ahsonkhan and @safern are working on a plan for updating the corefx API docs for 3.0. I think they were mainly focused on API that wasn't documented at all, but we should think about this case also.

  13. AaronRobinsonMSFT commented on Feb 6, 2019

    @AaronRobinsonMSFT
    Member

    @safern Do you have any concerns with me putting up a PR with the attribute removed?

  14. safern commented on Feb 6, 2019

    @safern
    Member

    From the docs perspective sounds fine to me. We should be handing the new reference assemblies every release. So as long as reflection is done correctly, it should be reflected on the docs for next release. As long for .NET Core, because for netfx, I think the source of truth are not core ref assemblies, but still don't know enough to tell.

    cc: @mairaw

  15. mairaw commented on Feb 6, 2019

    @mairaw
    Contributor

    There's a bug in docs where the attribute is not version aware at the moment.
    When you look at the docs source, you can see exactly which versions have that attribute:
    https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Runtime.InteropServices/Marshal.xml#L4462

    Tagging @dendeli-msft to comment on when this bug should be fixed. I think it's still months away because it was dependent on some other work they need to do first to enable this.

    Yes, for netfx, Vivek gives me a pointer to the targeting pack for me to reflect on.

  16. crowo commented on Mar 26, 2019

    @crowo

    also dont forget removing obselete from UnmanagedType.SafeArray

  17. AaronRobinsonMSFT commented on Mar 27, 2019

    @AaronRobinsonMSFT
    Member

    @crowo Please refer to dotnet/corefx#35161 for the extent of the changes.

  18. transferred this issue fromdotnet/corefxon Feb 1, 2020
  19. added this to the 3.0 milestone on Feb 1, 2020
  20. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-System.Runtime.InteropServicesquestion

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions