Posts

Showing posts from October 20, 2013

Fixing bad sectors on WHS hard drive

When your WHS starts giving you hard drive errors make a note of where they are happening, somewhere on C:\fs\{drive letter}. Then open a command prompt and run: chkdsk /r C:\fs\{drive letter} After a few minutes it will then ask you if you would like to force a dismount. Say No. Then it will ask you if you would like to schedule a chkdsk /r the next time the system restarts. Say Yes. Restart WHS.

404 error in a REST WCF service

I created my first WCF REST service the other day and was getting a 404 error when I deployed the service to our server.  After some research I found the solution here: http://www.west-wind.com/weblog/posts/2008/Apr/10/WCF-REST-Configuration-for-ASPNET-AJAX-and-plain-REST-Services I needed to add: Factory ="System.ServiceModel.Activation.WebServiceHostFactory" to MyService.svc <% @ ServiceHost markup. There is also a very good write up on WCF REST service design here: http://msdn.microsoft.com/en-us/library/dd203052.aspx

.NET FxCop recommends not using List<T>

I like to use FxCop when I’m coding and sometimes I get hit with the rule that says do not use List<T>, but it doesn't say what to use instead or it’s not clear what to use instead. After some research I found some suggestions: http://blogs.msdn.com/kcwalina/archive/2005/09/26/474010.aspx http://blogs.msdn.com/fxcop/archive/2006/04/27/585476.aspx That recommend using Collection<T> but neither of them bothers to mention where Collection<T> is. So I did a little more research and I discovered it here: System.Collection.ObjectModel.Collection<T>

How to check if the current user has rights to read a file in .NET

I could not find any function in .NET that just straight out does this.  Furthermore I could not find any code on the web that explained what would be the best way to go about it.  Finally I found some code here: (post is no longer there) that checks if you could write to a file and I modified it to check if you could read: Public Shared Function CanReadFile( ByVal fileNameWithPath As String ) As Boolean Dim currentUser As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent() Dim currentPrinciple As System.Security.Principal.WindowsPrincipal = System.Threading.Thread.CurrentPrincipal Dim acl As System.Security.AccessControl.AuthorizationRuleCollection = System.IO.File.GetAccessControl(fileNameWithPath).GetAccessRules( True , True , GetType (System.Security.Principal.SecurityIdentifier)) Dim denyread As Boolean = False Dim allowread As Boolean = False ...

.NET generics with private accessors not compatible with MSTest

Was playing around with generics and suddenly my unit test project failed with this error: “Signature of the body and declaration in a method implementation do not match.” After some research I found a post here http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/b54e6634-1542-4bd8-a227-029bfb679dec that explained my problem was using a private on a generic class, and was a known bug that will not be fixed in VS 2010 as explained here https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=415357 .  Changed the private to public and was able to carry on.