diff options
author | Huangli Wu <huanwu@microsoft.com> | 2018-01-20 01:14:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-20 01:14:00 +0300 |
commit | 91a83313344bd96127dbc2c50723a930f93c33c5 (patch) | |
tree | 13273b49a2fc8186e54b3fb2f7a24e84d9d4e906 /src/System.Private.Xml | |
parent | b265a0f0066dbce3cf4845c25444fe85266c81d0 (diff) |
Put the code to get serializerPath into try/catch to catch any exception. (#26304)
* Put the code to get serializerPath into try/catch to catch any exception.
* Add null empty string check to the path before call Path.Combine.
* Put Path.Combine into one try/catch.
* Following the code in full framework, catch two more exceptions.
* Remove extra line.
Diffstat (limited to 'src/System.Private.Xml')
-rw-r--r-- | src/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs b/src/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs index 99b53934da..f4f650a0a7 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs @@ -167,19 +167,29 @@ namespace System.Xml.Serialization name.Name = serializerName; name.CodeBase = null; name.CultureInfo = CultureInfo.InvariantCulture; - string serializerPath = Path.Combine(Path.GetDirectoryName(type.Assembly.Location), serializerName + ".dll"); - if (!File.Exists(serializerPath)) - { - serializerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), serializerName + ".dll"); - } + + string serializerPath = null; try { - serializer = Assembly.LoadFile(serializerPath); + if (!string.IsNullOrEmpty(type.Assembly.Location)) + { + serializerPath = Path.Combine(Path.GetDirectoryName(type.Assembly.Location), serializerName + ".dll"); + } + + if ((string.IsNullOrEmpty(serializerPath) || !File.Exists(serializerPath)) && !string.IsNullOrEmpty(Assembly.GetEntryAssembly().Location)) + { + serializerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), serializerName + ".dll"); + } + + if (!string.IsNullOrEmpty(serializerPath)) + { + serializer = Assembly.LoadFile(serializerPath); + } } catch (Exception e) { - if (e is OutOfMemoryException) + if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } @@ -190,6 +200,7 @@ namespace System.Xml.Serialization return null; } } + if (serializer == null) { if (XmlSerializer.Mode == SerializationMode.PreGenOnly) |