Archive
HowTo: Remove unused references and using clauses in Visual Studio
I recently posted a list of the VS2015 extensions I use on my main machine at: https://zoomicon.wordpress.com/2015/11/13/visual-studio-2015-extensions-i-use/
From that list of extensions I use the Productivity Power Tools one, it has a "Power Commands > Remove and Sort Usings" action that one can right click and run on the whole solution. Much easier than opening it for each
There is another nice extension called ResolveUR that is not available for VS2015, but only for VS2013 (think you can edit its .vsix and make it work for it too though, see the process for other similar extension explained at https://devio.wordpress.com/2014/12/03/remove-unused-references-with-visual-studio-2013/). I usually open up the solution in VS2013 too just to run that. Resharper also has such functionality as shown at:
https://www.jetbrains.com/resharper/help/Refactorings__Remove_Unused_References.html
Alternative is to use the Copy References extension and right click a reference under the References subtree of a project, then select "Copy Reference", then Remove the reference and rebuild that project. If rebuild fails, then right click at the References again and select Paste Reference. Then repeat till you remove all references that are not needed
In fact one should FIRST remove all unused using clauses and THEN remove unused references. That is because some files like App.xaml.cs, AssemblyInfo.cs may have using clauses that they don’t really use. So unless those using clauses are removed, the compiler thinks respective references to assemblies those namespaces were at are needed
Fix: Cleanup after upgrading from Windows 10 technical preview
I recently replaced the internal hard disk of my old Lenovo S10-3t Tablet PC with an SSD and installed Windows 10 technical preview, but recently realized the hard disk had almost run out of space.
Trying to figure out why, I realized that upgrading from the Windows 10 technical preview version to the final Windows 10 version (this happened automatically via Windows Update), left back a “Windows.old” folder at the hard disk root taking up 3.14GB, as if I had upgraded from Windows 7 or Windows 8 via Microsoft’s free OS upgrade offer (that offer is valid for a year btw, so make sure you don’t miss it).
You’ll notice the Disk Cleanup tool (you can find it by pressing the search icon (magnifying glass) at the Windows taskbar and writing “cleanup”, temporary Windows installation files are also mentioned as taking up an extra 3.22 GB, but there is some double counting there, since I ended up with 5.30GB free after cleanup, from around 200MB I had left on the hard disk before I run Disk Cleanup (note that I already had run CCleaner, but I hadn’t selected the option there to cleanup files from previous Windows installation, since I didn’t expect to have any such).
Note, that Disk Cleanup will even warn you that you won’t be able to restore the machine back to the previous Windows version (aka the technical preview), but why should you care to do so anyway?
Update:
To make some extra disk space and since I use a fast SSD, I had set Windows to compress the hard disk contents (one can set this option by right clicking the disk and selecting Properties), so probably there is no double-counting by Disk Cleanup dialog, it just must be showing the uncompressed space those things it cleans take up. So it could indeed be 3.14GB + 3.22GB of useless space taken up by updating Windows technical preview to the official Windows 10 release via the normal automatic Windows Update process, which is quite a lot.
Microsoft should show some warning to the user about all this extra space taken up (right away after updating and offer to remind them in the future again if they opt to keep the files till they’re confident the latest version works OK) and offer them the choice of cleaning this up
Another interesting thing I notice is that although I had selected the option to compress the drive and it had applied respective attribute to all files (showing a progress dialog), it didn’t remember that setting (not sure if I had set it before the upgrade), so probably it wasn’t compressing newer files.
Gotcha: MediaElement Source=null releases stream, SetSource(null) fails
This is my contribution to:
If you use MediaElement, make sure you don’t get bitten by this one: http://msdn.microsoft.com/en-us/library/cc626563(v=vs.95).aspx
ArgumentNullException – The mediaStreamSource is null.
…After calling this method, MediaElement.Source returns null. If this is called and MediaElement.Source is set, the last operation wins.
If a MediaElement is removed from the UI tree while is has an opened MediaStreamSource, subsequent calls to SetSource may be ignored. To ensure featureSetSource calls will work, set the Source property to null before detaching the MediaElement from the UI tree.
naturally one would expect, if they only use SetSource(somestream) to use SetSource(null) to release the resources. Nope, they thought "better", you have to use Source=null instead to release resources and SetSource(null) throws ArgumentNullException
that is what I call a design bug (breaks the rule of "least expected" behavior and causes bugs that bite you at runtime only [unless somebody has made a static analysis rule to catch such a thing – would need metadata of course that some argument can’t be null, like in Code Contracts])
I managed to introduce this bug while refactoring some code in ClipFlair Studio‘s AudioRecorder control the other day 😦
Note that you can’t use at MediaElement something like Source = stream to open a Stream, since that is a Uri property (not an Object property to also accept Stream) and you have to use SetSource(stream) instead, so you’d also expect to be able to use SetSource(null) to release the resources.
Update: Fixed this in AudioRecorderView class (uses MVVM pattern) of AudioRecorderControl, at Audio property’s "set" accessor it needed the following null-guarding pattern:
if (mediaStreamSource != null)
player.SetSource(mediaStreamSource);
//must set the source once, not every time we play the same audio,
//else with Mp3MediaSource it will throw DRM error
else
player.Source = null;