c# - CA2000 and I don't see the reason -
i'm writing project , use microsoft code analysis , receive following error:
ca2000: dispose objects before losing scope.
this on code i've written around entity framework.
public bool isinstalled(installationcontext context) { var dbcontext = new scheduleframeworkdatacontext(); var repository = new taskrepository(dbcontext); try { // check if there task same name. if (repository.get().select(x => x.name == context.installationparameters.name).any()) { return true; } } { dbcontext.dispose(); } return false; }
now, think context disposed because it's in block. (the context ef code first db context). however, still receive error.
am missing here?
the code analysis tool right in instance.
if taskrepository()
constructor throws, finally
block won't run (since exception thrown outside of try
block), , dbcontext
not disposed.
moving constructor call , assignment repository
inside try
block suppress warning.
Comments
Post a Comment