这个警告是非常恼人的,我已经看过一些文章,建议如何绕过它,但它们似乎不起作用。
据我所见,我已经处理了下面代码中的所有场景,但我仍然收到了警告。我正在使用VS2010。我很想压制它,但如果它不变得太丑,我宁愿把它修好。有什么建议吗?
private LicenseModules CreateDataSource
{
get
{
// set default result
LicenseModules result = null;
try
{
result = new LicenseModules();
// lookup the "Tools" class in the current entry assembly
var lookup = Assembly.GetEntryAssembly().GetTypes().FirstOrDefault(item => item.Name.Equals("Tools", StringComparison.Ordinal));
// ensure the lookup result is valid
if (lookup != null)
{
// lookup the Configuration property
var prop = lookup.GetProperty("Configuration", BindingFlags.Static | BindingFlags.Public);
// validate the lookup result
if (prop != null)
{
// read the current Configuration value
object value = prop.GetValue(lookup, null);
// ensure the read value is valid
if (value != null)
result = (value as Configuration).Solutions.LicenseModules;
}
}
// return current result
return result;
}
catch (Exception)
{
if (result != null)
{
result.Dispose();
}
throw;
}
}
}发布于 2013-11-25 07:49:58
在此:
if (value != null)
result = (value as Configuration).Solutions.LicenseModules;在没有处理在这里创建的实例的情况下,您为result分配了一个新值:
result = new LicenseModules();在分配新的结果之前,您应该创建一个块并释放旧的结果值:
if (value != null) {
result.Dipose();
result = (value as Configuration).Solutions.LicenseModules;
}https://stackoverflow.com/questions/20187138
复制相似问题