[CSHARP-2138] Support ISupportInitialize when targeting .NET standard 1.5 Created: 05/Jan/18  Updated: 28/Oct/23  Resolved: 16/Oct/19

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.5
Fix Version/s: 2.9.3

Type: Improvement Priority: Major - P3
Reporter: Sergio Costa Assignee: Robert Stam
Resolution: Fixed Votes: 6
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.NET standard


Issue Links:
Duplicate
is duplicated by CSHARP-2220 ISupportInitialize ignored on some ve... Closed
Backwards Compatibility: Minor Change

 Description   

We are migrating a project to ASP.net core where we have POCOs beeing deserialized that implement ISupportInitialize

Looking at the driver source (https://github.com/mongodb/mongo-csharp-driver/blob/v2.5.0/src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs), this isn't supported in .net standard.

I looked around and couldn't find a reason for this. Can you guys include it again?

Thanks



 Comments   
Comment by Willian Gruber [ 16/Oct/19 ]

Thank you for the fix!

Comment by Robert Stam [ 16/Oct/19 ]

We added support for `ISupportInitialize` when targeting .NET Standard 1.5 using reflection.

Later when we target .NET Standard 2.0 or above we won't need to use reflection because .NET Standard 2.0 and above include the `ISupportInitialize` interface.

Comment by Ted Francis [ 16/Oct/19 ]

Thanks VERY much for the fast turnaround on this issue, Robert!

Comment by Githook User [ 16/Oct/19 ]

Author:

{'username': 'rstam', 'email': 'robert@robertstam.org', 'name': 'rstam'}

Message: CSHARP-2138: Support ISupportInitialize when targeting .NET standard 1.5.
Branch: v2.9.x
https://github.com/mongodb/mongo-csharp-driver/commit/e36efc98b80aead45263a70eb6c0ea07cf5512d3

Comment by Githook User [ 16/Oct/19 ]

Author:

{'username': 'rstam', 'email': 'robert@robertstam.org', 'name': 'rstam'}

Message: CSHARP-2138: Support ISupportInitialize when targeting .NET standard 1.5.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/794058d10e4f08ec39a8438311ad8bc6a632ff74

Comment by Willian Gruber [ 14/Oct/19 ]

Thank you Robert Stam!

By the way, I am using Core 3.0.

Comment by Robert Stam [ 14/Oct/19 ]

At this point we are not ready to change the minimum required framework versions.

We are investigating an approach using reflection to support `ISupportInitialize` without changing the minimum required framework versions.

Comment by Willian Gruber [ 11/Oct/19 ]

Hi,

My project depends on this functionality too.

Can you please recheck the minimum requirement and update the serializer?

Thank you

(By the way, just saw Ted Francis's and Christopher Sena's posts dates, and although they are the same as mine, I do not know them. Which means this problem affects many projects)

Comment by Christopher Sena [ 11/Oct/19 ]

Hi,

I'm desperate for this to be resolved. 

This issue is preventing my project from progressing. Any update on progress would be great as it's been almost 2 years now.

Thanks

Comment by Ted Francis [ 11/Oct/19 ]

Hi there. Same issue for me.  Have migrated our application from .NET 4.6.2 to .NET Standard 2.0 and all of our data migration code has stopped working because of this issue.

Comment by Ingmar Bode [ 17/Sep/19 ]

Hi Federico, are you saying that ISupportInitialize is working for .NET Standard 2.0 (but not for 2.1 so far)? Can't try this currently, because I'm on a trip. But I could easily step back to 2.0 if that helps ...

Comment by Federico Ceccatto [ 16/Sep/19 ]

I noticed you're aiming to target .NETStandard 2.0 in v2.10, would it be possible to also include this? It's just a tweak to a couple of #ifs

Comment by Ingmar Bode [ 16/Sep/19 ]

Hello guys, any news here? I am using .NET Standard 2.1 and C# Driver 2.9.1. 

I feel like there has been no progress so far?

Comment by Thomas Karbe [ 28/Sep/18 ]

Same issue over here.

 

Im currently looking for some logic to enable silent deployment in our CI Pipeline. I think, when we put some feature Toggles and this logic together well have it.

Comment by Robert Stam [ 18/Jun/18 ]

We do intend to target .NET Standard 2.0 soon.

We will either increase our minimum required .NET Standard version from 1.5 to 2.0, or we will add a third targeted framework (.NET Standard 2.0) to our currently targeted frameworks (.NET Framework 4.5 and .NET Standard 1.5).

We need to update our build process a bit first to make it easier to target multiple frameworks.

Comment by Ofir [ 18/Jun/18 ]

Robert, must of the community have updated to .NET Standard 2.0, what are the chances you will accept Liviu's suggestion to target multi-platforms?

Thanks!

Comment by Ingmar Bode [X] [ 14/Jun/18 ]

If there is any chance: I would love to have ISupportInitialize support in .NET Standard 2.0 as well. 

Comment by Robert Stam [ 27/Apr/18 ]

We currently target two frameworks:

  • .NET Framework 4.5
  • .NET Standard 1.5

We certainly could target multiple versions of .NET Standard. It just so happens that this is the first time there has been a possible need to target multiple versions of .NET Standard. Thank you for the suggestion.

Comment by Liviu Rezmerita [ 27/Apr/18 ]

Can you please explain why you can't target multiple .net standard versions?
Why can't you create a multi-targeting project with <TargetFrameworks>netstandard1.5;netstandard2.0;net45</TargetFrameworks> ,define dependencies for each targeting framework and add corresponding #if preprocessor directives in code?

Please provide a workaround for managing schema changes on .net core and mention this limitation in the documentation.

Comment by Robert Stam [ 26/Apr/18 ]

We currently only require .NET Standard 1.5. ISupportInitialize was not added to .NET Standard until version 2.0.

If we change the minimum requirement to .NET Standard 2.0 we would restrict the frameworks our driver could run on to only those frameworks that are new enough to support .NET Standard 2.0.

So the real issue here is when do we increase our minimum .NET Standard version and to what? It's a trade off between gaining access to new features and abandoning users who still run on older frameworks.

Comment by Liviu Rezmerita [ 26/Apr/18 ]

This issue hasn't been fixed in v2.5.1 either.
Robert, why don't you update the #if preprocessor directive to include .net core 2?

#if (NET45 || NETSTANDARD2_0 || NETCOREAPP2_0)
ISupportInitialize supportsInitialization = null;
#endif

Comment by Robert Stam [ 08/Jan/18 ]

It should be easy to add support back for ISupportInitialize. It would just be a matter of removing some #ifs.

A pull request for this would be welcome, but as I mentioned above the unanswered question is whether it is OK to require all our users to upgrade to .NET Core 2.0 to use the next release of the driver. So the timing of when the pull request might be merged could be a little further in the future.

Comment by Sergio Costa [ 08/Jan/18 ]

Hi Robert, thanks for your response.

If we provide a PR for this would you consider it for the next driver release?

Comment by Robert Stam [ 05/Jan/18 ]

At the time we first ported the driver to .NET Core the ISupportInitialize interface was not supported by .NET Core.

Looking at apisof.net it appears that ISupportInitialize is now supported in .NET Core 2.0 (and .NET Standard 2.0).

We currently target .NET Framework 4.5 and .NET Standard 1.5. To add support for ISupportInitialize (in .NET Core) we would have to increase our minimum required .NET Standard version to 2.0. I'm not sure yet whether requiring 2.0 is viable, or whether many of our users aren't yet ready to move to .NET Core 2.0.

Thanks for bringing this up. At some point we will definitely figure out how (and when) to bring back support for this in .NET Core.

Generated at Wed Feb 07 21:41:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.