title: ClosedXML Read excel file Error: The type initializer for 'MS.Utility.EventTrace' threw an exception. (C#)
body: <p>I was developing Excel upload functionality in the asp.net application using closedXML.
  The functionality works fine when I use local IIS and gives exception when I use Visual Studio 2013. Which is not allowing me to do further debugging in the code.</p>
  <p><strong>Exception:</strong></p>
  <pre><code>Message: The type initializer for 'MS.Utility.EventTrace' threw an exception.
  Stack Trace: 
     at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID)
     at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare, Boolean streaming)
     at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
     at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable, OpenSettings openSettings)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable)
     at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
     at ClosedXML.Excel.XLWorkbook.Load(String file)
     at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking)
     at ClosedXML.Excel.XLWorkbook..ctor(String file)
     at OnlinePolicyUpload.ReadExcel(String filePath) in d:\Application\XYZ\OnlineUpload.aspx.cs:line 413
  </code></pre>
  <p><strong>Inner exception:</strong></p>
  <pre><code>Message: Requested registry access is not allowed.
  Stack Trace:    
     at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
     at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
     at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
     at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue)
     at MS.Utility.EventTrace.IsClassicETWRegistryEnabled()
     at MS.Utility.EventTrace..cctor()
  </code></pre>
  <p><strong>My Code segment:</strong></p>
  <pre><code>private DataTable ReadExcel(string filePath)
      {
          try
          {
              DataTable dt = new DataTable();
              IXLWorkbook workBook = new XLWorkbook(filePath);
              IXLWorksheet workSheet = workBook.Worksheet(1);
              bool firstRow = true;
              foreach (IXLRow row in workSheet.Rows())
              {
                  if (firstRow)
                  {
                      foreach (IXLCell cell in row.Cells())
                      {
                          dt.Columns.Add(cell.Value.ToString());
                      }
                      firstRow = false;
                  }
                  else
                  {
                      dt.Rows.Add();
                      int i = 0;
                      foreach (IXLCell cell in row.Cells())
                      {
                          dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString();
                          i++;
                      }
                  }
              }
              return dt;
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  </code></pre>
  <p>Exception is thrown at line <code>IXLWorkbook workBook = new XLWorkbook(filePath);</code></p>
  <p>File path has Full access permission to <strong>Everyone, IIS_IUSRS</strong>.
  Changing this to <strong>false</strong> will affect my application login to fail.
  <code>&lt;identity impersonate=&quot;true&quot; userName=&quot;username&quot; password=&quot;pass&quot; /&gt;</code></p>
  <p>Tried changing permission to everyone with full access to registry
  <strong>HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics</strong>. No luck.</p>
  <p>Please help me with this.</p>