RicoSuter / Namotion.Reflection

.NET library with advanced reflection APIs.
MIT License
212 stars 44 forks source link

XmlDocsExtensions.GetXmlDocsSummary fails on <inheritdoc/> and concurrent access #132

Open mediawolf opened 1 year ago

mediawolf commented 1 year ago

Commit ID: 33e53f600197357307599c7536daa7715e1dbd00

Steps:

The following snippet will fail with an exception thrown by Linq implementation:

    public interface IMyObject
    {
        /// <summary>
        /// Description
        /// </summary>
        void DoSomething();
    }

    public class MyObject : IMyObject
    {
        /// <inheritdoc/>
        public void DoSomething() { }
    }

    internal class Program
    {
        static void Do()
        {
            typeof(MyObject).GetMember(nameof(MyObject.DoSomething)).Single().GetXmlDocsSummary();
        }

        static void Main(string[] args)
        {
            for (int i = 0; ; ++i)
            {
                Console.WriteLine(i);
                var tasks = new[]
                {
                    Task.Run(Do),
                    Task.Run(Do),
                    Task.Run(Do),
                    Task.Run(Do),
                };
                Task.WaitAll(tasks);
                XmlDocs.ClearCache();
            }
        }
    }

In my case, it's about running unit-tests performing a JSON validation using JsonSchema in parallel. JsonSchema is generated on the fly.