Service Reference auto-generated classes in Reference.cs not being generated as Internal

2.5k Views Asked by At

I am adding Service References to my project and choosing the "internal" access option. Out of 15 web services, 3 are being stubborn and most of the classes inside the auto-generated Reference.cs are coming in as Public (even though I am choosing "internal")

I have gone through my classes in the Web References having this issue and nothing really jumps out as a major difference between the ones having issues and the ones that are working.

Does anyone know a common cause for this issue? such as an Xml Attribute to a class that might be causing this issue or anything?

1

There are 1 best solutions below

0
On

The issue is precisely that. XmlSerializer cannot serialize internal types. This limitation is briefly mentioned by Microsoft here in the section titled "Access Level for Generated Classes Setting Has No Effect".

Setting the Access level for generated classes option in the Configure Service References dialog box to Internal or Friend may not always work. Even though the option appears to be set in the dialog box, the resulting support classes will be generated with an access level of Public.

This is a known limitation of certain types, such as those serialized using the XmlSerializer.

As far as I know, there isn't really an acceptable workaround for this issue in regards to the auto-generated service references. However, DataContractSerializer is not restricted by this limitation so it can be used in other scenarios.

You'll have to take this one up with Microsoft. Assuming there hasn't already been a requested solution rejected as "Won't fix".