2017-04-26 40 views
0

我想的byte []轉換爲XML文件,下載文件,我得到這個異常:異常而下載的byte []

無法因爲代碼優化或本機框架上,以評估表達調用堆棧的頂部。

代碼:

Response.Clear(); 
Response.ContentType = "application/xml"; 
Response.AddHeader("content-disposition", "attachment;filename=test.xml"); 
Response.BufferOutput = true; 
Response.BinaryWrite(fileData); 
Response.End(); 

任何一個建議我的代碼有什麼過錯?

+0

你看到的是不實際的異常。這就是你所看到的,因爲(因爲它說)調試器是*「無法評估表達式,因爲代碼被優化或本地框架在調用堆棧之上。」*這基本上意味着*「我不能說你的實際價值,因爲我不能訪問它。「* –

回答

0

您好你嘗試以下操作:

C#

try 
{ 
    Response.Clear(); 
    Response.ContentType = "application/xml"; 
    Response.AddHeader("content-disposition", "attachment;filename=test.xml"); 
    Response.BufferOutput = true; 
    Response.BinaryWrite(fileData); 
    Response.Flush(); 
    //response.End(); 
    Response.Redirect("",false); 
} 
catch (Exception e) 
{ 
    throw new Exception(e); 
} 
+0

我甚至嘗試過,但不顯示彈出的下載 – Ragavan

+0

你試過包裝整個方法或執行代碼塊與try catch?在「拋出新異常」中添加一個斷點並檢查是否沒有其他烹飪?在添加行HttpContext.Current.ApplicationInstance.CompleteRequest()後加入 – ThatAwesomeCoder

+0

; 沒有得到異常,沒有發生(沒有得到下載) – Ragavan