dotnet thoughts 

a dotnet developer's technical blog

Compiler Error Message: CS0016: Could not write to output file – Access is denied.

Last Sunday the Support guys in my machine, updated the OS(Windows Vista) and monday onwards while running my web application, I got a strange error,

Compiler Error Message: CS0016: Could not write to output file - Access is denied.

Compiler Error Message: CS0016: Could not write to output file - Access is denied.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\myapp\xxxxx\xxxxx\App_GlobalResources.xxxxxxx.dll’ — ‘Access is denied. ‘

I was not done anything in the Global Resources file, but it was showing the error related to this. After doing some searching, I found it can be an issue with Antivirus software. I stopped the Antivirus software and tried, but still the problem was there. Later I found it was related to permission issue in the Temp folder. To resolve this.

  1. Go to %Systemroot%, normally C:\WINDOWS or C:\WINNT
  2. Right-click the Temporary folder (mine is C:\WINDOWS\Temp) and select Sharing and Security.
  3. Select the Security tab and take a look at the list of “Group or user names:”
  4. NETWORK SERVICE should be in the list. If it is not, click Add and type Network Service in the text box.
  5. Make sure NETWORK SERVICE have Full Control in the Permissions list. Click OK.
  6. Restart IIS (Run iisreset)

If your machine doesn’t have NETWORK SERVICE or NETWORK SERVICES Group, look for “IIS_IUSRS” and apply same permissions.

How To Convert XMLNodeList To DataTable

After doing an XPath selection using .Net, using XmlDocument.SelectNodes(), it will return XMLNodeList class, sometimes we required to convert the XMLNodeList to Data Table for binding purposes. I couldn’t find a direct way, only way is using looping through the Nodes.

/// <summary>
    /// Converts an XMLNodelist object to data table.
    /// </summary>
    /// <param name="xmlNodeList">The XMLNodeList to convert to DataTable.</param>
    /// <param name="Columns">The columns required for the DataTable, using this parameter the
    /// data will be fetched from xmlnodelist.</param>
    /// <returns>DataTable with columns specified in the Columns parameter</returns>
    public DataTable XmlNodeListToDataTable(XmlNodeList xmlNodeList, string[] Columns)
    {
        //Creating the DataTable.
        using (DataTable dataTable = new DataTable("DataTable"))
        {
            //Adding data Table columns based on the columns parameter
            foreach (string column in Columns)
            {
                dataTable.Columns.Add(column);
            }
            //Adding rows with values.
            DataRow dataRow;
            foreach (XmlNode node in xmlNodeList)
            {
                dataRow = dataTable.NewRow();
                foreach (string column in Columns)
                {
                    dataRow[column] = node.SelectSingleNode(column).InnerText;
                }
                dataTable.Rows.Add(dataRow);
            }
            return dataTable;
        }
    }

You can also create the columns dynamically, but you need to check for duplicate Data Columns.

.Net 4.0 and Visual Studio 2010 Released

Download a full trial version at http://www.microsoft.com/visualstudio/en-us/download

Free Visual Studio 2010 Express editions available at http://www.microsoft.com/express/downloads/

Free e-book “Moving to Visual Studio 2010″ – Download from here http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=12a6de81-c633-4f2c-a35f-cea6fe772712