locked
Pex Factory and Disposable Objects whitch are not disposed RRS feed

  • Question

  • Hi,
    I just noticed, that If you have a Pex Factory, which has the return type object, then Pex dosn't dispose the Object in the generated test.
    Even if the Object is disposable(Implements IDisposable).
    This may be expected, but in this case, I wouldn't expect the autogenerated factories to have the return type object, even if there are no public constructors!
    Tuesday, August 18, 2009 9:12 AM

Answers

  • > This solves the Automatic Factory problem, but I think the main Problem is that Pex didn't check if the type was disposable.
    > From your answer it seems to me, that this isn't handled, considert.
    > Any special reason for that ?

    It's just work on our side. Overall, dealing with IDisposable (and unmanaged resources in general) is tricky.

    > Another thing I noticed, in my Code, I have a internal/friend interface witch extents IDisposable.
    > And I have some public classes which are implementing my interface, but didn't implement IDisposable.

    How would that even compile?

    > Because of that, the Pex generated Tests, can't cast my classes to IDisposable, or rater VS gave me an error because of that.
    > I'm not sure if that's a Problem, but if is there any way to let Pex warn me about such 'external not visible impementations of external visible interfaces' ?

    I don't quite understand the problem; if you have a repro, then feel free to send it to pexbug@microsoft.com.

    Nikolai Tillmann
    Sunday, August 23, 2009 9:17 PM

All replies

  • Thanks for reporting the bug. I could reproduce the issue.
    I will keep this thread open until the bug has been fixed.

    Nikolai Tillmann
    Wednesday, August 19, 2009 12:00 AM
  • In the next Pex version, suggested factory methods for non-public types that implement IDisposable will have IDisposable instead of Object as their return type, and then the generated code will dispose them properly.

    As a workaround for the current Pex release, you can also manually change the suggested return type from Object to IDisposable; then the right code should get generated.

    Nikolai Tillmann

    Wednesday, August 19, 2009 12:16 AM
  • This solves the Automatic Factory problem, but I think the main Problem is that Pex didn't check if the type was disposable.
    From your answer it seems to me, that this isn't handled, considert.
    Any special reason for that ?

    Another thing I noticed, in my Code, I have a internal/friend interface witch extents IDisposable.
    And I have some public classes which are implementing my interface, but didn't implement IDisposable.
    Because of that, the Pex generated Tests, can't cast my classes to IDisposable, or rater VS gave me an error because of that.
    I'm not sure if that's a Problem, but if is there any way to let Pex warn me about such 'external not visible impementations of external visible interfaces' ?

    Wednesday, August 19, 2009 10:13 AM
  • > This solves the Automatic Factory problem, but I think the main Problem is that Pex didn't check if the type was disposable.
    > From your answer it seems to me, that this isn't handled, considert.
    > Any special reason for that ?

    It's just work on our side. Overall, dealing with IDisposable (and unmanaged resources in general) is tricky.

    > Another thing I noticed, in my Code, I have a internal/friend interface witch extents IDisposable.
    > And I have some public classes which are implementing my interface, but didn't implement IDisposable.

    How would that even compile?

    > Because of that, the Pex generated Tests, can't cast my classes to IDisposable, or rater VS gave me an error because of that.
    > I'm not sure if that's a Problem, but if is there any way to let Pex warn me about such 'external not visible impementations of external visible interfaces' ?

    I don't quite understand the problem; if you have a repro, then feel free to send it to pexbug@microsoft.com.

    Nikolai Tillmann
    Sunday, August 23, 2009 9:17 PM