September 30, 2010

Requested registry access is not allowed

I was trying to write some information from an application to the event viewer, but it gave a security exception.

 
System.Security.SecurityException: Requested registry access is not allowed.
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
   at System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
   at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message)
   at EC.SPNPortal.ToDoList.ToDoList.uxSend_Click(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 
After playing around, found the solution for this problem.

 
This mainly happens when the logged in user does not have write access to the event log. So for that, please perform below things in 32 bit machine

  • Open the registry entry using regedit command
  • Find the below place, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog
  • Right click on that and give full access to everyone.
In a 64 bit machine,
  • Open the registry entry using regedit command
  • Find the below place, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Security
  • Right click on that and give full access to everyone.

September 22, 2010

The specified service has been marked for deletion

Today I faced a problem when trying to install a custom windows service created using C# .net. When I try to install the service from the command prompt it gives this "The specified service has been marked for deletion" error. When I checked the local services, the service status was makred as disabled. Since it was really urgent for me, I looked for every where and got that you can delete the service by using the below command.
         "sc delete name"
So happily I tried it as well, but its also gave the same error., Finally, found the solution from this link. This problem happens mainly when you didn't close the services .msc window. Once I closed and opened it, the service was being sucessfully deleted.

September 08, 2010

Could not load file or assembly 'NLog'


Last week we had a problem when trying to test a dll which has used nlog.

When you use nlog, we normally code it as below,


This gave "Could not load file or assembly 'NLog'" exception.

We tried out many things, but still this was a real headache for us. But finally, we were able to solve it.

After doing many researches, we found out that since we are not using a strong name for the nlog assembly it is impossible to do GAC lookup. Therefore system cannot find the actual nlog path from GAC. So it throws an exception.

We were able to solve this problem by including the below section in the config file.