Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit edbe783

Browse files
authored
Catch the FileNotFoundException when to get the obsolete attribute for type. (#27389)
* Catch the FileNotFoundException when to get the obsolete attribute for type. * Move continue out of if. * Add some comments. * Update the comments.
1 parent d9e55a9 commit edbe783

File tree

1 file changed

+24
-10
lines changed
  • src/Microsoft.XmlSerializer.Generator/src

1 file changed

+24
-10
lines changed

src/Microsoft.XmlSerializer.Generator/src/Sgen.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,37 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
232232
{
233233
Type type = types[i];
234234

235-
if (type != null)
235+
try
236236
{
237-
bool isObsolete = false;
238-
object[] obsoleteAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
239-
foreach (object attribute in obsoleteAttributes)
237+
if (type != null)
240238
{
241-
if (((ObsoleteAttribute)attribute).IsError)
239+
bool isObsolete = false;
240+
object[] obsoleteAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
241+
foreach (object attribute in obsoleteAttributes)
242242
{
243-
isObsolete = true;
244-
break;
243+
if (((ObsoleteAttribute)attribute).IsError)
244+
{
245+
isObsolete = true;
246+
break;
247+
}
245248
}
246-
}
247249

248-
if (isObsolete)
250+
if (isObsolete)
251+
{
252+
continue;
253+
}
254+
}
255+
}
256+
//Ignore the FileNotFoundException when call GetCustomAttributes e.g. if the type uses the attributes defined in a different assembly
257+
catch (FileNotFoundException e)
258+
{
259+
if (warnings)
249260
{
250-
continue;
261+
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoIgnoreType, type.FullName)));
262+
WriteWarning(e, parsableerrors);
251263
}
264+
265+
continue;
252266
}
253267

254268
if (!proxyOnly)

0 commit comments

Comments
 (0)