mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-09 17:44:48 +09:00
Add IsSerializerVersionMatch check (dotnet/corefx#30137)
* add IsSerializerVersionMatch check
* add eventsource for logging
Commit migrated from 1b270a4d56
This commit is contained in:
parent
d0fbcb7312
commit
1d65627eb0
5 changed files with 57 additions and 2 deletions
|
@ -390,7 +390,7 @@ namespace Microsoft.XmlSerializer.Generator
|
|||
return arg.Equals(formal, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public bool ShortNameArgumentMatch(string arg, string shortName)
|
||||
private bool ShortNameArgumentMatch(string arg, string shortName)
|
||||
{
|
||||
// Short name format, eg: -a
|
||||
if (arg.Length < 2 || arg[0] != '-')
|
||||
|
|
|
@ -3444,7 +3444,10 @@ Usage: dotnet {0} [--assembly <assembly file path>] [--type <type name&
|
|||
<data name="MoreHelp" xml:space="preserve">
|
||||
<value>If you would like more help, please type "sgen {0}".</value>
|
||||
</data>
|
||||
<data name="GenerateSerializerNotFound" xml:space="preserve">
|
||||
<data name="GenerateSerializerNotFound" xml:space="preserve">
|
||||
<value>Method 'System.Xml.Serialization.XmlSerializer.GenerateSerializer' was not found. This is likely because you are using an older version of the framework. Please update to .NET Core v2.1 or later.</value>
|
||||
</data>
|
||||
<data name="event_XmlSerializerExpired" xml:space="preserve">
|
||||
<value>Pre-generated serializer '{0}' has expired. You need to re-generate serializer for '{1}'</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<Compile Include="System\Xml\MTNameTable.cs" />
|
||||
<Compile Include="System\Xml\NameTable.cs" />
|
||||
<Compile Include="System\Xml\Ref.cs" />
|
||||
<Compile Include="System\Xml\Serialization\XmlSerializationEventSource.cs" />
|
||||
<Compile Include="System\Xml\ValidateNames.cs" />
|
||||
<Compile Include="System\Xml\XmlCharType.cs" />
|
||||
<Compile Include="System\Xml\XmlComplianceUtil.cs" />
|
||||
|
@ -520,6 +521,7 @@
|
|||
<Reference Include="System.Diagnostics.Debug" />
|
||||
<Reference Include="System.Diagnostics.Tools" />
|
||||
<Reference Include="System.Diagnostics.TraceSource" />
|
||||
<Reference Include="System.Diagnostics.Tracing" />
|
||||
<Reference Include="System.IO.FileSystem" />
|
||||
<Reference Include="System.Linq" />
|
||||
<Reference Include="System.Linq.Expressions" />
|
||||
|
|
|
@ -210,6 +210,14 @@ namespace System.Xml.Serialization
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
#if !FEATURE_SERIALIZATION_UAPAOT
|
||||
if (!IsSerializerVersionMatch(serializer, type, defaultNamespace))
|
||||
{
|
||||
XmlSerializationEventSource.Log.XmlSerializerExpired(serializerName, type.FullName);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -249,6 +257,20 @@ namespace System.Xml.Serialization
|
|||
}
|
||||
|
||||
#if !FEATURE_SERIALIZATION_UAPAOT
|
||||
private static bool IsSerializerVersionMatch(Assembly serializer, Type type, string defaultNamespace)
|
||||
{
|
||||
if (serializer == null)
|
||||
return false;
|
||||
object[] attrs = serializer.GetCustomAttributes(typeof(XmlSerializerVersionAttribute), false);
|
||||
if (attrs.Length != 1)
|
||||
return false;
|
||||
|
||||
XmlSerializerVersionAttribute assemblyInfo = (XmlSerializerVersionAttribute)attrs[0];
|
||||
if (assemblyInfo.ParentAssemblyId == GenerateAssemblyId(type) && assemblyInfo.Namespace == defaultNamespace)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GenerateAssemblyId(Type type)
|
||||
{
|
||||
Module[] modules = type.Assembly.GetModules();
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics.Tracing;
|
||||
|
||||
namespace System.Xml.Serialization
|
||||
{
|
||||
[EventSource(
|
||||
Name = "System.Xml.Serialzation.XmlSerialization",
|
||||
LocalizationResources = "FxResources.System.Private.Xml.SR")]
|
||||
internal class XmlSerializationEventSource : EventSource
|
||||
{
|
||||
internal static XmlSerializationEventSource Log = new XmlSerializationEventSource();
|
||||
|
||||
[Event(EventIds.XmlSerializerExpired, Level = EventLevel.Informational)]
|
||||
internal void XmlSerializerExpired(string serializerName, string type)
|
||||
{
|
||||
WriteEvent(EventIds.XmlSerializerExpired, serializerName, type);
|
||||
}
|
||||
|
||||
public class EventIds
|
||||
{
|
||||
public const int XmlSerializerExpired = 1;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue