ca2000

How to fix a CA2000 IDisposable C# compiler warning, when using a global cache

此生再无相见时 提交于 2019-12-29 08:40:06
问题 CA2000 is a warning regarding the IDisposable interface: CA2000 : Microsoft.Reliability : In method 'ImportProcessor.GetContext(string)', call System.IDisposable.Dispose on object 'c' before all references to it are out of scope. My method is used to store a cache of context like so: public class RegionContext : IDisposable { /* Implement Dispose() here */ } private Dictionary<string, RegionContext> contextCache = new ..... (); public RegionContext GetContext(string regionCode) {

CA2000 - “out-of-school-junior-programmers”-mistakes or false positive?

回眸只為那壹抹淺笑 提交于 2019-12-24 08:50:02
问题 I am currently developing some desktop applications using websockets (to be more precisely: i am working with Alchemy WebSockets). By now my code is working fine, but Visual Studio 2010 tells me to Warning 2 CA2000 : Microsoft.Reliability : In method 'ServerController.SetupServer(int)', call System.IDisposable.Dispose on object '<>g__initLocal0' before all references to it are out of scope. C:\Users\MaRiedl\documents\visual studio 2010\Projects\Alchemy-WebSockets\AWS-Server\ServerController

C# Code Analysis CA2000

非 Y 不嫁゛ 提交于 2019-12-12 11:05:51
问题 I have a function which I thought I had fixed the CA2000 warning in Code Analysis for, but it just won't go away. The warning is on SqlCommand. Here's the function: protected internal void LogUserSession(int? managerID) { using (var sqlCommand = new SqlCommand()) { sqlCommand.SetCommand("usp_UserActivity_Create"); SqlParameter prmSessionID = new SqlParameter(); prmSessionID.ParameterName = "@sessionID"; prmSessionID.Direction = ParameterDirection.Input; prmSessionID.SqlDbType = SqlDbType

C# CA2000:Dispose objects before losing scope using FileStream/XmlTextReader

一笑奈何 提交于 2019-12-06 23:49:15
问题 I have lots of code like this: FileStream fs = File.Open(@"C:\Temp\SNB-RSS.xml", FileMode.Open); using (XmlTextReader reader = new XmlTextReader(fs)) { /* Some other code */ } This gives me the following Code Analysis warning: CA2000 : Microsoft.Reliability : In method 'SF_Tester.Run()', object 'fs' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'fs' before all references to it are out of scope. If I follow the suggestion and I put the File.Open in a

C# CA2000:Dispose objects before losing scope using FileStream/XmlTextReader

北慕城南 提交于 2019-12-05 03:58:20
I have lots of code like this: FileStream fs = File.Open(@"C:\Temp\SNB-RSS.xml", FileMode.Open); using (XmlTextReader reader = new XmlTextReader(fs)) { /* Some other code */ } This gives me the following Code Analysis warning: CA2000 : Microsoft.Reliability : In method 'SF_Tester.Run()', object 'fs' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'fs' before all references to it are out of scope. If I follow the suggestion and I put the File.Open in a using statement, I get this: CA2202 : Microsoft.Usage : Object 'fs' can be disposed more than once in

Disabling/Fixing Code Analysis warnings from .Designer.cs files

落花浮王杯 提交于 2019-12-04 17:09:13
问题 I am using DataVisualization.Charting.Chart extensively, and for the most part it is working. However, I've been running Code Analysis frequently, and have all my own warnings taken care of. But, there are about 30 CA2000 (object not disposed along all exception paths) in the *.Designer.cs files that use the charting. The Designer files are generating pretty much all the charting code, and almost all the charting elements implement IDisposable . I have "Suppress results from generated code"

CA2000 passing object reference to base constructor in C#

耗尽温柔 提交于 2019-12-01 03:16:26
I receive a warning when I run some code through Visual Studio's Code Analysis utility which I'm not sure how to resolve. Perhaps someone here has come across a similar issue, resolved it, and is willing to share their insight. I'm programming a custom-painted cell used in a DataGridView control. The code resembles: public class DataGridViewMyCustomColumn : DataGridViewColumn { public DataGridViewMyCustomColumn() : base(new DataGridViewMyCustomCell()) { } It generates the following warning: CA2000 : Microsoft.Reliability : In method 'DataGridViewMyCustomColumn.DataGridViewMyCustomColumn()'

CA2000 passing object reference to base constructor in C#

喜欢而已 提交于 2019-11-30 23:45:12
问题 I receive a warning when I run some code through Visual Studio's Code Analysis utility which I'm not sure how to resolve. Perhaps someone here has come across a similar issue, resolved it, and is willing to share their insight. I'm programming a custom-painted cell used in a DataGridView control. The code resembles: public class DataGridViewMyCustomColumn : DataGridViewColumn { public DataGridViewMyCustomColumn() : base(new DataGridViewMyCustomCell()) { } It generates the following warning:

How to fix a CA2000 IDisposable C# compiler warning, when using a global cache

情到浓时终转凉″ 提交于 2019-11-29 13:53:30
CA2000 is a warning regarding the IDisposable interface: CA2000 : Microsoft.Reliability : In method 'ImportProcessor.GetContext(string)', call System.IDisposable.Dispose on object 'c' before all references to it are out of scope. My method is used to store a cache of context like so: public class RegionContext : IDisposable { /* Implement Dispose() here */ } private Dictionary<string, RegionContext> contextCache = new ..... (); public RegionContext GetContext(string regionCode) { RegionContext rc = null; if (!this.contextCache.TryGetValue(regionCode.ToUpper(), out rc)) { rc = new RegionContext