Last post Feb 12, 2016 04:57 AM by PaulTheSmith
Feb 12, 2016 04:21 AM|Surbakti|LINK
I have a problem about C# programming with visual studio express 2013.
Here the error:
An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll
in code block:
if (!System.Diagnostics.EventLog.SourceExists("EngineService")) // error when debug this code
how to fix this error.
Feb 12, 2016 04:45 AM|gerrylowry|LINK
Your code appears fine, for example, compare it to https://msdn.microsoft.com/en-us/library/System.Diagnostics.EventLog(v=vs.110).aspx:
// Create the source, if it does not already exist.
//An event log source should not be created and immediately used.
//There is a latency time to enable the source, it should be created
//prior to executing the application that uses the source.
//Execute this sample a second time to use the new source.
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
HOWEVER, it is absolutely essential that EventLog.CreateEventSource be Run As Administrator.
Feb 12, 2016 04:57 AM|PaulTheSmith|LINK
how to fix this error
Which part do you want to fix? The 'unhandled' part or the 'occurred' part?
If you want to fix the 'unhandled' part then add a try/catch block around the code which is throwing the exception and put a handler in the catch statement.
If you want to fix the 'occurred' part then you should use the debugger to get more details of why the exception is occurring. Inspect the Exception. What are its properties? Are there inner exceptions? What are their properties (including any inner exceptions
they might have)?