Why is code from .Net Reflector different than MS source code?
pascal
Posts: 3 Bronze 1
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.
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
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?
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 becomesSystem.Data.<span>SqlClient.</span>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.
CONNECTIONOBJECTNAME
in namespaceNAMESPACE
. Those would be replaced at build-time by the correct class name and namespace name, and this allows multipleDbConnection
-derived classes to share theDispose()
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?