You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Marshal.GetObjectForNativeVariant is obsoleted with no workaround provided #28564
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?
@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.
@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.
@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.
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?
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.
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.
@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.
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.
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.
Activity
vcsjones commentedon Jan 30, 2019
@AaronRobinsonMSFT may know?
AaronRobinsonMSFT commentedon Jan 31, 2019
Thanks @vcsjones.
@jbartlau The obsolete statement is a nuanced indication about the intent of certain APIs and scenarios involving CoreCLR. As you probably know
VARIANTis 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.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
VARIANTfor the time being since support on non-Windows platform is still in question.cc @jeffschwMSFT
jbartlau commentedon Jan 31, 2019
@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.GetObjectForNativeVariantor the genericMarshal.GetNativeVariantForObject<T>.Anyway, thanks for the reassurance, issue could be closed if no further steps will be taken.
AaronRobinsonMSFT commentedon Jan 31, 2019
@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.
jkotas commentedon Jan 31, 2019
I think so.
AaronRobinsonMSFT commentedon Feb 1, 2019
@stephentoub, @jkotas, @jeffschwMSFT,
Are there any concerns about removing the
System.ObsoleteAttributeattribute from theVARIANTfamily 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
stephentoub commentedon Feb 1, 2019
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?
jkotas commentedon Feb 1, 2019
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.stephentoub commentedon Feb 1, 2019
In the docs:
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getobjectfornativevariant?view=netframework-4.7.2
AaronRobinsonMSFT commentedon Feb 1, 2019
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.
stephentoub commentedon Feb 1, 2019
Sounds fine to me.
jkotas commentedon Feb 1, 2019
The docs are not showing the right obsolete attributes in many cases dotnet/dotnet-api-docs#1184
danmoseley commentedon Feb 4, 2019
@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.
AaronRobinsonMSFT commentedon Feb 6, 2019
@safern Do you have any concerns with me putting up a PR with the attribute removed?
safern commentedon Feb 6, 2019
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
mairaw commentedon Feb 6, 2019
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.
crowo commentedon Mar 26, 2019
also dont forget removing obselete from UnmanagedType.SafeArray
AaronRobinsonMSFT commentedon Mar 27, 2019
@crowo Please refer to dotnet/corefx#35161 for the extent of the changes.