Why is code from .Net Reflector different than MS source code?

Hi,
 I was looking at the System.Data.SqlClient.SqlConnection on .Net 4.8 and finding differences between what reflector shows and what is shown by the Microsoft source files in github (https://github.com/microsoft/referencesource/blob/master/System.Data/fx/src/data/System/Data/SqlClient/SqlConnection.cs or https://referencesource.microsoft.com/#System.Data/fx/src/data/System/Data/SqlClient/SqlConnection.cs,48932d2b804ed473). I was particularly looking at the Dispose() method which reflector shows implementation for it but the MS source file does not show any implementation for it. There are other subtle differences as well which I can't explain.
Tagged:

Answers

  • Hi @pascal ,

    Thanks for your post!

    Would you mind sharing a few screenshots of the differences you're seeing to help us get a better understanding?

    I see the Dispose(Boolean) method but it appears to be in Microsoft's source file as well.

    Thank you!

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • Jessica RJessica R Posts: 1,159 Rose Gold 4
    Thanks @pascal!

    Ah I was seeing the Dispose(boolean) in the ms file and didn't realize it was actually in the SqlDebugContext class.

    However, our developers have taken a look into this and the exact same definition of Dispose(Boolean) shown by .NET Reflector does in fact exist in /System/Data/ProviderBase/DbConnectionHelper.cs.

    Technically, it is defined in a class NAMESPACE.CONNECTIONOBJECTNAME. Our understanding is that it is a kind of a "template" class which later becomes System.Data.SqlClient.SqlConnection (and others).

    Though we unfortunately can't find an official source to confirm this, according to someone at Stack Overflow it will be replaced at build time, which explains why it ends up in the final System.Data.dll file.

    This defines a class CONNECTIONOBJECTNAME in namespace NAMESPACE. Those would be replaced at build-time by the correct class name and namespace name, and this allows multiple DbConnection-derived classes to share the Dispose() implementation.

    (Note that ILDASM shows the Dispose(boolean) method in System.Data.SqlClient.SqlConnection )

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Sign In or Register to comment.