Closed ericwra closed 7 years ago
Thanks for reporting the error. Can you make another screenshot, where I can see the stacktrace? Simply click on the small triangle in front of each line. I just inserted a NotImplmentedException in another extension to demonstrate this:
I just saw you are running version 0.12. This is one of the first version I published. There are lots of known bugs. The current version 0.30 might already solve your problem.
You might have downloaded the last released published on github. But its also available on Visualstudio gallery, including autoupdate
I was mistaken about the version number. I have the latest from the visual studios marketplace / gallery version 0.30.
After further examination of the stack traces I've been able to determine there was indeed a IDisposable not being disposed of in each of the error locations. They were all simple declarations like the instance below.
I've attached a screenshot with the stacktrace as requested.
Line:25 -> var db = new EmailEntities();
changed to using(var db = new EmailEntities()) { blah blah... etc.. }
Hi, unfortunately I was not able to reproduce the problem, yet. But I refactored the code and split the method into several once. I published version 0.31 with this changes.
Can you once more try to reproduce the problem and send me a screenshot of the new stacktrace?
I've updated to 0.31 and was able to trigger the same exception as before.
Thanks for the new stacktrace.
No problem, let me know if there is anything I can do to help you track this down. I find this extension very useful when refactoring large code bases.
I think I finally found the problem. Do you use property initializers? Something like:
using System;
using System.IO;
namespace SomeNamespace{
internal class Program {
private static void Main(string[] args) {
var memoryStream = new MemoryStream();
new Foo {Prop = memoryStream};//this causes the problem
}
}
internal class Foo {
public IDisposable Prop { get; set; }
public Foo() { }
}
}
Can you please add the optional braces and check if the error is gone?
using System;
using System.IO;
namespace SomeNamespace{
internal class Program {
private static void Main(string[] args) {
var memoryStream = new MemoryStream();
new Foo (){Prop = memoryStream};//should be fixed with braces
}
}
internal class Foo {
public IDisposable Prop { get; set; }
public Foo() { }
}
}
I thought that each constructor should have a (maybe empty) ArgumentList, but when using property initializer the ArgumentList is actually null, instead of empty.
If you can verify the solution, the fix should be very easy.
That fixed the issue. Thanks for tracking down this exception!
By the way, which version of Visual Studio are you using? 2015/2017, Community Edition, Professional, Enterprise? I'm asking because currently I wasn't able to spot this problem on my own.
Is part of release 0.32
Prerequisites
Description
Some projects cause DisposableFixer to throw a System.NullReferenceException on Build.
Analyzer 'DisposableFixer.DisposableFixerAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Source Code
I have not been able to isolate this problem outside of my very large solution. If I recreate the project it is throwing on outside of the large solution it seems to have no issues during build.
Screenshot