title: SecurityException was unhandled by user code .Request for the permission of type 'System.Security.Permissions.FileIOPermission
body: <p>I am trying to migrate my <code>MOSS 2007</code> web parts to a <code>SharePoint 2010</code> environment.<br>
  My environment is a <code>Windows Server 2008 64Bit</code>, <code>Visual Studio 2008</code> and  <code>SharePoint 2010</code>.</p>
  
  <p>On adding the web parts to a <code>SharePoint 2010</code> site behind the scene, it is accessing the configuration file of <code>log4net</code>, and doing so it's producing an error saying "<strong>SecurityException was unhandled by user code</strong>".</p>
  
  <p>It is getting while running this line of code :</p>
  
  <pre><code>FileInfo fi = new FileInfo(log4netConfigFilePath);
  </code></pre>
  
  <p>Exact error from Exception Type:</p>
  
  <pre><code>"Request for the permission of type 'System.Security.Permissions.FileIOPermission
     , mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
     failed."
  </code></pre>
  
  <p>This is the stack trace:</p>
  
  <pre><code>at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; 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&amp; errorMessage)
  </code></pre>
  
  <p>I tried running this code under <code>Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges</code>, but it also produced this error.</p>
  
  <p>Please help me solve this error.</p>