System.UnauthorizedAccessException when Trying to Delete a File

Wednesday, 18 September 2013 00:06 by ranjanbanerji

There are probably several reasons why one would get this error when attempting to delete a file from code:  System.UnauthorizedAccessException: Access to the path ‘blah.exe' is denied.  I recently encountered it when writing a WinForm application and went through the obvious reasons:

  • Permissions.  Does the current user have rights to delete the file in question.
  • Attributes.  Does the file have a read only attribute
  • In use.  Is some other application using, hence, locking the file.

What I did not consider is if the my own code was loading the file.  At first glance the answer was no.  My code was simply looking at the version of an executable and deleting it if it was old.  This was no LoadLibrary kind of code or was it?  After much pondering I decided to look into Assembly.ReflectionOnlyLoadFrom which is how I was loading the executable to get its version.  AssemblyName.GetAssemblyName is the correct way to do so because it does not load the file (thereby does not lock the file).

Version currentVersion = Assembly.ReflectionOnlyLoadFrom( filePath).GetName().Version;  //WRONG WAY as in this will load and keep the assembly in memory
Version currentVersion = AssemblyName.GetAssemblyName( filePath).Version;  //RIGHT WAY as in this will not load the assembly into memory so the file will not be locked.

 

A day and a half wasted figuring this out.  Awesome!!!!!!!!!!!!!!!

Oh! The Information Age

Saturday, 15 June 2013 15:23 by ranjanbanerji

Right since history lessons in high school to watching Ancient Aliens on History channel nowadays one can derive a common theme which is that smart people use information to their advantage, no matter what era they belonged to and no matter whether they were real or imaginary.  Now let’s fast forward to the modern era of mankind.  The one we call the information age.  Since the early 90s the Internet has been increasingly used by the common person and industry.  It can safely be said that nearly any innovative idea on the Internet is based on information.

Since information is so critical to the notion of the “Information Age” duh!!!!!! several corporations have developed their entire business model around the art of collecting and analyzing information.  Since the Internet is used by almost everyone one the largest source of information and target of information is people themselves.  Then there are businesses that strive to improve their performance by analyzing information on people so that they can better serve them.  So even if they are not in the information business, information itself is key to their business.

So now let’s take two business that I have had to deal with recently.  The first being Google.  There isn’t a person in the developed world who hasn’t used Google.  Yes they make products but to make things easier let’s just say they are in the information business. After all one could argue that Android is merely an information collection device.  But we digress……..

The other company is AT&T which is a communications company but has grown to even provide IT support and consulting services to the Federal government and possibly others.  But most of us know AT&T as a provider of cellular services and the cell company that signed the lucrative exclusive contract when the iPhone was first released.  Clearly two giants in their own domain.  One collecting information and making it available to those who need it, the other selling mobile communications and IT Services and needs information to do a good job and be successful.

So let’s begin our tale of two corporate giants in this age of “information is everything”.  So I used to have an AT&T mobile phone and I decided to retire it as I no longer needed it.  But I wanted to save my number so that in the future if I needed a mobile phone I could use the same number.  This is where Google enters the story.  I transferred my AT&T number to Google Voice.  Now several years later I decided to transfer/port my number out of Google voice back to AT&T.  I googled (yes its a verb and no binged is not) and found the process on how to port my number out of Google voice.  In fact the instructions were provided by Google itself (https://support.google.com/voice/answer/1316844?hl=en).  You simply go to and unlock your Google voice number so that the other company can port out the number.  This can be done by going here (or just read the instructions in the link above).

So I followed all the instructions provided and unlocked my number.  Then I went to the AT&T store and asked them to give me a new phone and to port this number over.  After about an hour of trying AT&T failed to do so.  At this point they escalated to the issue to some higher level of support.  You think they will solve the problem right?  Wrong!  Worse….  The lady on the phone asked me to give her my Google password.  WTF?  Yes you heard that right.  WTF?  I tried to explain to her the implications of giving out ones password.  But she insists that is the only way the number can be transferred.   Now you got to remember that this is the same company that provides IT services to the government and key agencies like the Department of Defense.  Agreed its not the same group of people who provide support for cell phones but still you would think there would be a corporate culture that promotes security.

Instead of giving the AT&T lady my Google password I told her I will research the issue myself and call back.  Luckily she agreed to that.  She gave me a temporary AT&T number for my new phone sent me a text message with a number to call to assist with porting problem.  The text included hours of operation which clearly states that Saturday and Sunday is 9am to 10pm EST.  As of 9:15am on Sunday they say their office is closed.  Awesome!

So after some research I found that in addition to your Google account password, you can set a PIN for your Google voice account.  So perhaps what AT&T needs is the PIN not my account password.  But since AT&T offices are closed (contrary to their message to me) there is not much I can do.

So let’s recap;

  • Google does not completely document the porting process.  They omit the part about the PIN.  Though the PIN may not be necessary for the port and it may just be AT&T that is completely and utterly clueless.
  • AT&T despite being in the business of porting numbers and despite successfully porting numbers from Google voice seems to have no clue as to what they do to be successful.  Knowledge management, employee training, knowledge base mean anything to you AT&T? (google it, you will find many who say they ported their Google voice number to AT&T)
  • AT&T sent me published hours of business which is incorrect.  Seriously?  AT&T does not even know when they do or do not work?  Let’s double recap, we are talking about the information age right?  If I am not wrong even in 5000 BC traders knew when they would and would not work.  Hellooooo AT&T is anyone there?
  • AT&T asking for my password.  They have got to be kidding.  In this day and age when everyone is talking about cyber attacks and hackers, AT&T employees are blatantly asking people to hand over their account passwords?

So the next business day I call AT&T armed with a PIN number and all.  They tell me that there is no record of any number port for me.  Huh?  Wow! this just keeps getting better.  The lady I was talking to was extremely helpful and she started the port process, did not need any password or PIN.  She texted me later in the day to call back to complete the port process.  So it was all done.  Finally!!!!!!!!!!!!!!!

Tags:   , ,
Categories:   Rants | IT | Management
Actions:   E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed