Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Catch the FileNotFoundException when to get the obsolete attribute fo…
Browse files Browse the repository at this point in the history
…r type. (#27389)

* Catch the FileNotFoundException when to get the obsolete attribute for type.

* Move continue out of if.

* Add some comments.

* Update the comments.
  • Loading branch information
huanwu authored Feb 27, 2018
1 parent d9e55a9 commit edbe783
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,37 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
{
Type type = types[i];

if (type != null)
try
{
bool isObsolete = false;
object[] obsoleteAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
foreach (object attribute in obsoleteAttributes)
if (type != null)
{
if (((ObsoleteAttribute)attribute).IsError)
bool isObsolete = false;
object[] obsoleteAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
foreach (object attribute in obsoleteAttributes)
{
isObsolete = true;
break;
if (((ObsoleteAttribute)attribute).IsError)
{
isObsolete = true;
break;
}
}
}

if (isObsolete)
if (isObsolete)
{
continue;
}
}
}
//Ignore the FileNotFoundException when call GetCustomAttributes e.g. if the type uses the attributes defined in a different assembly
catch (FileNotFoundException e)
{
if (warnings)
{
continue;
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoIgnoreType, type.FullName)));
WriteWarning(e, parsableerrors);
}

continue;
}

if (!proxyOnly)
Expand Down

0 comments on commit edbe783

Please sign in to comment.