Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<SystemReflectionEmitPackageVersion>4.7.0</SystemReflectionEmitPackageVersion>
<SystemReflectionEmitLightweightPackageVersion>4.7.0</SystemReflectionEmitLightweightPackageVersion>
<SystemRuntimeLoaderPackageVersion>4.3.0</SystemRuntimeLoaderPackageVersion>
<SystemWebServicesDescriptionPackageVersion>8.1.2</SystemWebServicesDescriptionPackageVersion>
<WCFClientPackageVersion Condition="'$(TargetFramework)' == 'net6.0'">6.2.0</WCFClientPackageVersion>
<WCFClientPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">8.1.2</WCFClientPackageVersion>
<WCFClientPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">8.1.2</WCFClientPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ private static CodeTypeDeclaration CreateArrayOfXmlElementClass(CodeNamespace ns
classToGen.IsPartial = true;
classToGen.TypeAttributes = s_isInternal ? TypeAttributes.NotPublic : TypeAttributes.Public;

CodeAttributeDeclaration xmlSchemaProviderAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(Microsoft.Xml.Serialization.XmlSchemaProviderAttribute)),
CodeAttributeDeclaration xmlSchemaProviderAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.Xml.Serialization.XmlSchemaProviderAttribute)),
new CodeAttributeArgument(new CodePrimitiveExpression(null)),
new CodeAttributeArgument("IsAny", new CodePrimitiveExpression(true)));
classToGen.CustomAttributes.Add(xmlSchemaProviderAttribute);

classToGen.BaseTypes.Add(new CodeTypeReference(typeof(Object)));
classToGen.BaseTypes.Add(new CodeTypeReference(typeof(Microsoft.Xml.Serialization.IXmlSerializable)));
classToGen.BaseTypes.Add(new CodeTypeReference(typeof(System.Xml.Serialization.IXmlSerializable)));

CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Public;
Expand Down Expand Up @@ -191,7 +191,7 @@ private static void AddGetSchemaMethod(CodeTypeDeclaration classToGen)
getSchemaMethod.Attributes = MemberAttributes.Public;
getSchemaMethod.Name = "GetSchema";
getSchemaMethod.ImplementationTypes.Add(classToGen.BaseTypes[1]);
getSchemaMethod.ReturnType = new CodeTypeReference(typeof(Microsoft.Xml.Schema.XmlSchema));
getSchemaMethod.ReturnType = new CodeTypeReference(typeof(System.Xml.Schema.XmlSchema));

CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(
new CodeObjectCreateExpression(
Expand All @@ -209,7 +209,7 @@ private static void AddWriteXml(CodeTypeDeclaration classToGen)
writeXml.Attributes = MemberAttributes.Public;
writeXml.ImplementationTypes.Add(classToGen.BaseTypes[1]);

writeXml.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(Microsoft.Xml.XmlWriter)), "writer"));
writeXml.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(System.Xml.XmlWriter)), "writer"));
CodeVariableDeclarationStatement enumeratorDec =
new CodeVariableDeclarationStatement(
CreateTypeReference("System.Collections.Generic.IEnumerator`1", xelementType), "e",
Expand All @@ -219,7 +219,7 @@ private static void AddWriteXml(CodeTypeDeclaration classToGen)

CodeVariableReferenceExpression eRef = new CodeVariableReferenceExpression("e");
CodePropertyReferenceExpression eCurrent = new CodePropertyReferenceExpression(eRef, "Current");
CodeCastExpression iXmlSerCast = new CodeCastExpression(new CodeTypeReference(typeof(Microsoft.Xml.Serialization.IXmlSerializable)), eCurrent);
CodeCastExpression iXmlSerCast = new CodeCastExpression(new CodeTypeReference(typeof(System.Xml.Serialization.IXmlSerializable)), eCurrent);
CodeMethodInvokeExpression codeWrite = new CodeMethodInvokeExpression(iXmlSerCast, "WriteXml", new CodeVariableReferenceExpression("writer"));

CodeIterationStatement codeFor = new CodeIterationStatement();
Expand All @@ -240,11 +240,11 @@ private static void AddReadXml(CodeTypeDeclaration classToGen)
readXml.Attributes = MemberAttributes.Public;
readXml.ImplementationTypes.Add(classToGen.BaseTypes[1]);

readXml.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(Microsoft.Xml.XmlReader)), "reader"));
readXml.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(System.Xml.XmlReader)), "reader"));

CodeVariableReferenceExpression reader = new CodeVariableReferenceExpression("reader");
CodePropertyReferenceExpression readerNodeType = new CodePropertyReferenceExpression(reader, "NodeType");
CodeTypeReferenceExpression xmlNodeType = new CodeTypeReferenceExpression(typeof(Microsoft.Xml.XmlNodeType));
CodeTypeReferenceExpression xmlNodeType = new CodeTypeReferenceExpression(typeof(System.Xml.XmlNodeType));
CodePropertyReferenceExpression xmlNodeTypeEndElement = new CodePropertyReferenceExpression(xmlNodeType, "EndElement");
CodeBinaryOperatorExpression notEq = new CodeBinaryOperatorExpression(readerNodeType, CodeBinaryOperatorType.IdentityInequality, xmlNodeTypeEndElement);

Expand All @@ -261,7 +261,7 @@ private static void AddReadXml(CodeTypeDeclaration classToGen)
new CodeTypeReference(xelementType), "elem",
new CodeObjectCreateExpression(new CodeTypeReference(xelementType), new CodePrimitiveExpression("default")));

CodeCastExpression iXmlSerCast = new CodeCastExpression(new CodeTypeReference(typeof(Microsoft.Xml.Serialization.IXmlSerializable)), new CodeVariableReferenceExpression("elem"));
CodeCastExpression iXmlSerCast = new CodeCastExpression(new CodeTypeReference(typeof(System.Xml.Serialization.IXmlSerializable)), new CodeVariableReferenceExpression("elem"));

CodeMethodInvokeExpression codeRead = new CodeMethodInvokeExpression(iXmlSerCast, "ReadXml", new CodeVariableReferenceExpression("reader"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,12 @@ namespace Microsoft.Tools.ServiceModel.Svcutil
{
internal class NamespaceFixup : CodeDomVisitor
{
private static string s_microsoftXml = "Microsoft.Xml";
private static string s_systemXml = "System.Xml";
private static string s_microsoftCodeDom = "Microsoft.CodeDom";
private static string s_systemCodeDom = "System.CodeDom";
Comment on lines 12 to 15

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the Microsoft.Xml rewrite logic, NamespaceFixup now appears to only fix CodeDom namespaces. Consider renaming the visitor (and/or adding a clarifying comment) so its intent stays accurate (e.g., CodeDomNamespaceFixup), which will reduce confusion when debugging or extending codegen fixups.

Copilot uses AI. Check for mistakes.
private Dictionary<string, Type> _xmlTypes = new Dictionary<string, Type>();
private Dictionary<string, Type> _codeDomTypes = new Dictionary<string, Type>();

public NamespaceFixup()
{
// Microsoft.Xml.dll
var msxmlTypes = TypeLoader.LoadTypes(typeof(Microsoft.Xml.XmlDocument).GetTypeInfo().Assembly, Verbosity.Silent);
foreach (var type in msxmlTypes)
{
if (type.FullName.Contains(s_microsoftXml))
{
_xmlTypes[type.FullName] = type;
}
}

// Microsoft.CodeDom
var mscodedomTypes = TypeLoader.LoadTypes(typeof(Microsoft.CodeDom.CodeObject).GetTypeInfo().Assembly, Verbosity.Silent);

Expand All @@ -45,10 +32,6 @@ public NamespaceFixup()
protected override void Visit(CodeAttributeDeclaration attr)
{
base.Visit(attr);
if (attr.Name.Contains(s_microsoftXml) && _xmlTypes.ContainsKey(attr.Name))
{
attr.Name = attr.Name.Replace(s_microsoftXml, s_systemXml);
}
if (attr.Name.Contains(s_microsoftCodeDom) && _codeDomTypes.ContainsKey(attr.Name))
{
attr.Name = attr.Name.Replace(s_microsoftCodeDom, s_systemCodeDom);
Expand All @@ -58,10 +41,6 @@ protected override void Visit(CodeAttributeDeclaration attr)
protected override void Visit(CodeComment comment)
{
base.Visit(comment);
if (comment.Text.Contains(s_microsoftXml) && _xmlTypes.ContainsKey(comment.Text))
{
comment.Text = comment.Text.Replace(s_microsoftXml, s_systemXml);
}
if (comment.Text.Contains(s_microsoftCodeDom) && _codeDomTypes.ContainsKey(comment.Text))
{
comment.Text = comment.Text.Replace(s_microsoftCodeDom, s_systemCodeDom);
Expand All @@ -71,10 +50,6 @@ protected override void Visit(CodeComment comment)
protected override void Visit(CodeTypeReference typeref)
{
base.Visit(typeref);
if (typeref.BaseType.Contains(s_microsoftXml) && _xmlTypes.ContainsKey(typeref.BaseType))
{
typeref.BaseType = typeref.BaseType.Replace(s_microsoftXml, s_systemXml);
}
if (typeref.BaseType.Contains(s_microsoftCodeDom) && _codeDomTypes.ContainsKey(typeref.BaseType))
{
typeref.BaseType = typeref.BaseType.Replace(s_microsoftCodeDom, s_systemCodeDom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static bool IsIXmlSerializableType(CodeTypeDeclaration typeDecl)
{
foreach (CodeTypeReference typeRef in typeDecl.BaseTypes)
{
if (CodeDomHelpers.MatchType<Microsoft.Xml.Serialization.IXmlSerializable>(typeRef))
if (CodeDomHelpers.MatchType<System.Xml.Serialization.IXmlSerializable>(typeRef))
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Tools.ServiceModel.Svcutil
internal class XmlDomAttributeFixer : CodeDomVisitor
{
// removes members of the affected type
private static readonly Type[] s_filteredTypes = new Type[] { typeof(Microsoft.Xml.XmlAttribute), };
private static readonly Type[] s_filteredTypes = new Type[] { typeof(System.Xml.XmlAttribute), };
protected override void Visit(CodeTypeDeclaration type)
{
base.Visit(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using Microsoft.Xml;
using System.Xml;

namespace Microsoft.Tools.ServiceModel.Svcutil
{
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-svcutil/lib/src/CodeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using System.Linq;
using System.ServiceModel.Description;
using System.Text;
using Microsoft.Xml;
using Microsoft.Xml.Schema;
using System.Xml;
using System.Xml.Schema;
using WsdlNS = System.Web.Services.Description;

namespace Microsoft.Tools.ServiceModel.Svcutil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using System.Reflection;

namespace Microsoft.Xml
namespace System.Xml
{
using System;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Xml
namespace System.Xml
{
using System;

Expand Down
Loading