CA1804 code analysis error occurs intermittently

I get the following error intermittently:

CA1804: Microsoft.Performance: 'ChannelFactoryCache.GetChannel (string)' declares a variable '<> s__LockTaken0' of type 'bool', which is never used or assigned. Use this variable or delete it.

for the following code in the first expression if

public static T GetChannel<T>(string endpoint)
{
    if (!Cache.ContainsKey(typeof(T)))
    {
        lock (ObjLock)
        {
            if (!Cache.ContainsKey(typeof(T)))
            {
                ChannelFactory<T> channelFactory = new ChannelFactory<T>(endpoint);
                channelFactory.Open();
                Cache.Add(typeof(T), channelFactory);
            }
        }
    }

    T channel = ((ChannelFactory<T>)Cache[typeof(T)]).CreateChannel();
    ((IChannel)channel).Open();
    return channel;
}

Any idea what I'm doing wrong? CA runs in release mode.

+4
source share

Source: https://habr.com/ru/post/1534268/


All Articles