Quantcast
Channel: MVPXML Work Item Rss Feed
Viewing all articles
Browse latest Browse all 27

Commented Issue: XmlSerializerCache is not thread safe (fix included) [26717]

$
0
0
public System.Xml.Serialization.XmlSerializer GetSerializer(Type type
, XmlAttributeOverrides overrides
, Type[] types
, XmlRootAttribute root
, String defaultNamespace)
{
string key = CacheKeyFactory.MakeKey(type
, overrides
, types
, root
, defaultNamespace);

System.Xml.Serialization.XmlSerializer serializer = null;

var isCacheHit = false;

if (!Serializers.TryGetValue(key, out serializer))
{
lock (SyncRoot)
{
if (!Serializers.TryGetValue(key, out serializer))
{
serializer = new System.Xml.Serialization.XmlSerializer(type
, overrides
, types
, root
, defaultNamespace);

Serializers.Add(key, serializer);

if (null != NewSerializer)
{
NewSerializer(type
, overrides
, types
, root
, defaultNamespace);
}
}
else
{
isCacheHit = true;
}
}
}
else
{
isCacheHit = true;
}

if (isCacheHit && CacheHit != null)
{
// Tell the listeners that we already
// had a serializer that matched the attributes

CacheHit(type
, overrides
, types
, root
, defaultNamespace);
}

System.Diagnostics.Debug.Assert(null != serializer);
return serializer;
}
Comments: ** Comment from web user: taliesins **

This same approach could be used to fix GetCompiledExpression thread safety problem.


Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>