Fixed: Access is denied Exception
Access is denied.
Really?! Could you be a little more explicit?
I ran into this error recently when trying to deploy an application at a client. We ended up spending way too much time figuring out the root cause of this exception due to the sheer lack of details. Worst of all, the exact same code was working just fine in our QA environment.
At the end of the day, it turned out that our production box did not have the custom Event Log Source that our logger was attempting to log to. Normally, Windows is kind enough to create the Event Log Source for you, but the application we were running did not have sufficient privileges (Access is denied). After we added the source manually, everything started working again.
The Stack Trace
Unhandled Exception: ***** Exception***** Exception Message: Access is denied. Stack Trace:
Server Stack Trace
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at : at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
To fix this error, create the event log source on your production machine. If your application lives in Windows Azure, you will need to perform a few extra steps.
C:\PS> New-Eventlog -source YourEventLog -logname Application
Please let me know if this saves you any time/hassle. I need something to make me feel better for all of the time I wasted trying to fix this issue.