1. 程式人生 > >.net 編譯器錯誤資訊: CS0016: 未能寫入輸出檔案 解決方法

.net 編譯器錯誤資訊: CS0016: 未能寫入輸出檔案 解決方法

一.錯誤資訊提示如下:

編譯器錯誤資訊: CS0016:未能寫入輸出檔案: '*:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\*\*.dll'--拒絕訪問."

原因1:許可權問題,訪問許可權問題。

解決方法1:為使用者NETASP(NETWORK SERVICE [window 2003])設定windows下Temp資料夾的所有許可權

解決方法2:

1、如果C:/Windows目錄下沒有Temp資料夾,則建立一個;

2、右鍵Temp資料夾--屬性--安全,新增一個使用者"NETWORK SERVICE ",(如果是.NET Framework 1.0 則新增使用者"aspnet

user"), "賦予許可權--完全控制;

3、右擊"我的電腦"-"屬性"-"高階"-"環境變數",選擇系統變數下的"TEMP",點編輯,設定變數值為 %SystemRoot%\TEMP,確定,再對"TMP"進行同樣的操作,點選確定;

4、重啟IIS服務,問題解決。

原因2:服務被某些優化軟體禁止。

解決方案:

1、ASP.NET State Service被停止了,重新啟動ASP.NET State Service服務,並設為自動。

2、開始-執行-iisreset;。

3、OK

參考

二、 另外還有一個 Access denied 的錯誤說是不能訪問 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files 下的某個目錄。產生這些錯誤的原因很多,主要的可能包括:Bin 目錄或者 Web.config 被更改以及訪問檔案系統的許可權不夠。

但是另外還需要注意一些別的問題,

  • 檢查 Bin 目錄的檔案系統訪問許可權。一般只要確保 Users 容器擁有“讀取和執行”、“列出資料夾目錄”和“讀取”的許可權就可以了。
  • 如果提示說不能訪問 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\... ,可以將 Temporary ASP.NET Files 目錄的訪問許可權列表中新增 Everyone,並設定為擁有所有的許可權。然後在訪問一次此 Web 應用程式後,將 Temporary ASP.NET Files 目錄的訪問許可權列表中將 Everyone 刪除就可以了。

綜上所述的方法,主要包括:

  • 禁用或設定 Indexing Service 服務;
  • 檢查 Bin 目錄的訪問許可權;
  • 設定 Temporary ASP.NET Files 目錄的訪問許可權。

三、在 Windows2003 下(IIS6),出現如下錯誤資訊:

出現CS0016的原因一般是臨時目錄的許可權不夠,至於為什麼中途出現這種問題,我尚不清楚,解決的辦法是給Windows目錄下的臨時資料夾Temp的安全選項卡中加入NetWork Service使用者並賦予全權。更詳盡的解釋參考MSDN。

MSDN給出的解釋如下:

When you view a Microsoft ASP.NET Application in a Web browser, you may receive the following error messages:

For the Microsoft .NET Framework version 1.1, the error message is the following:
CS0016: Could not write to output file 'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\application1\c11b43f6\cf3ec03\rizcntet.dll' . The directory name is invalid.
For the .NET Framework 1.0, the error message is the following:
CS0013: Unexpected error writing metadata to file 'C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET Files\application2\3fc72f26\eb731247\ev2bslce.dll'. The directory name is invalid.


CAUSE
The system TEMP and TMP variables point to a folder that does not exist. The compiler generates temporary files in the folder where the TEMP and the TMP variables point to before the files are copied to the Temporary ASP.NET Files folder. However, the folder where the system variables point to is deleted when you restart the computer. Therefore, the compiler cannot generate the temporary files.
 

RESOLUTION
1. Create a temporary folder under %Systemroot%, and then name it Temp. 
2. Grant full permissions on the Temp folder to the aspnet user account in .NET Framework 1.0 or to the NETWORK SERVICE user account in .NET Framework 1.1.
3. Right-click My Computer, and then click Properties.
4. On the Advanced tab, click Environment Variables.
5. Select the TEMP variable under System variables, and then click Edit.
6. Type %SystemRoot%\TEMP in the Variable Value box, and then click OK.
7. Repeat steps 5 and 6 to edit the TMP variable. Click OK two times.
8. Click Start, and then click Run. 
9. To reset Internet Information Services (IIS), type iisreset on the command prompt.

Note If the error message that is mentioned in the "Symptoms" section of this article persists, restart the computer.