Load execution assembly for System.ServiceModel.Primitives.dll instead of reference assembly in Sgen - #32403
Conversation
Lxiamail
left a comment
There was a problem hiding this comment.
Should we use non-case sensitive comparison?
| string reference = s_referencedic[assemblyname]; | ||
|
|
||
| //for System.ServiceModel.Primitives, we need to load its execution assembly rather than reference assembly | ||
| if (assemblyname.Equals("System.ServiceModel.Primitives")) |
There was a problem hiding this comment.
What if there is third party assembly having the same name as System.ServiceModel.Primitives?
There was a problem hiding this comment.
I don't think this is a concern as it's understood that only framework libraries start with System. Even Microsoft will often release packages beginning with "Microsoft." to indicate that while it's created by Microsoft, it's not a core system library. Basically it's a reserved namespace by well understood convention. We only stuck with System for WCF because of the pre-existence of the code on .NET Framework and it would end up being a rename. Otherwise we likely wouldn't have used System as a prefix.
In reply to: 219902748 [](ancestors = 219902748)
| } | ||
|
|
||
| if(s_referencedic.ContainsKey(assemblyname)) | ||
| if (s_referencedic.ContainsKey(assemblyname)) |
There was a problem hiding this comment.
I do not know much about the context when this is executed, but would it be possible that nuget has downloaded and added reference to the project? (or if runtime load is needed then perhaps at least some library nuget perhaps provides)
| { | ||
| string reference = s_referencedic[assemblyname]; | ||
|
|
||
| //for System.ServiceModel.Primitives, we need to load its execution assembly rather than reference assembly |
There was a problem hiding this comment.
Do we understand why we were trying to load the reference assembly before?
There was a problem hiding this comment.
Yes. We need to reflect over the developers classes to generate the code for the serializer. A serializer needed for a WCF service needs to examine attributes which are defined in S.SM.Primitives. The reflection API's for attributes cause the attribute to be instantiated which means we can't load the reference assembly. For the rest of the data types referenced, a reference assembly is sufficient as there's no instantiation required.
In reply to: 220660138 [](ancestors = 220660138)
…of reference assembly in Sgen (dotnet#32403)
…of reference assembly in Sgen (dotnet/corefx#32403) Commit migrated from dotnet/corefx@d76a744
Fixes #32017
@mconnew @huanwu @Lxiamail