SecurityException was unhandled by user code


  • Hello friends,
    I am trying to migrate  my MOSS 2007 Webparts to Sharepoint 2010 environment.My environment is Windows Server 2008 64Bit,Visual Studio 2008,Sharepoint 2010.  On  adding  the  webparts to a Sharepoint 2010 Site behind the scene it is accesing the configuration file of log4net,While accesing this file its giving an error like "SecurityException was unhandled by user code".

    it is getting while running this line of code :

    FileInfo fi = new FileInfo(log4netConfigFilePath);

    Exact Error from Exception Type:

    "Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    This is the Stack Trace:

       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.IO.FileInfo..ctor(String fileName)
       at ProjectWorld.Logging.LogManager.Configure()
       at ProjectWorld.Logging.LogManager.EnsureConfiguration()
       at ProjectWorld.Logging.LogManager.GetLogger(WebPart webPart)
       at ProjectWorld.WebParts.PRSWebParts.QBWebPart..ctor()
       at T_c39ca68b_5b0a_4d36_b052_e470116a6771.CreateInstance()
       at System.Web.HttpRuntime.FastCreatePublicInstance(Type type)
       at System.Web.UI.WebControls.WebParts.WebPartManager.ImportWebPart(XmlReader reader, String& errorMessage)

    I am running this code under Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges,then also i am getting this error.

    PLease help me to solve this error. BEcause of this i cant the add webpart to the page.Thanks





    • Edited by Jaik Antony Tuesday, December 22, 2009 7:05 AM descriptive
    Sunday, December 20, 2009 12:37 PM

All replies

  • This isn't a SP security issue, it's a file system security issue.  Make sure the identity running this code has permissions to read the file system.
    Wednesday, December 23, 2009 12:50 AM