![](/img/trans.png)
[英]An unhandled exception of type 'System.StackOverflowException' occured in WTApp
[英]Why am I getting 'An unhandled exception of type 'System.StackOverflowException' occured in DLL'
我可以在目標路徑上成功上傳文件,但是出現此錯誤,我也不知道為什么。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using R.One.Data;
using System.Data.SqlClient;
using R.One.All.Common.Base;
using R.One.All.Common.Base.Components;
using R.One.All.Common.Base.DAO;
using R.One.All.Common.BusinessObjects;
using R.WebServices.Facilities;
namespace Facilities.UploadSRLogo
{
public partial class UploadSRLogo : SaveFileUploadBasePage
{
private string destinationFilePath = string.Empty;
private int maxFileSize = 2048000;
private bool isUpload = true;
private void Page_Load(object sender, EventArgs e)
{
//Get the Posted File
}
protected override void SetOutputFilePath()
{
try
{
FileRepository fr = new FileRepository(base.Env, base.DBServer);
string repositoryPath = fr.getRepositoryPath(base.user.PMCID.ToString(), "");
string internalPath = @"\R\Facilities\";
string outputFilePath = string.Format("{0}{1}", repositoryPath, internalPath);
FileInfo file = new FileInfo(outputFilePath);
if (!file.Directory.Exists)
{
file.Directory.Create();
}
System.IO.Directory.CreateDirectory(outputFilePath);
string tempFileName = System.Guid.NewGuid().ToString();
file = new FileInfo(this.ImportFile.Value);
destinationFilePath = outputFilePath + tempFileName + System.IO.Path.GetExtension(file.Extension);
if (System.IO.File.Exists(destinationFilePath) == true)
{
System.IO.File.SetAttributes(destinationFilePath, System.IO.FileAttributes.Normal);
}
this.OutputFilePath = destinationFilePath;
if (this.ImportFile.PostedFile.ContentLength > maxFileSize)
{
uploadResponse.ConfirmAction = false;
FileResult.Value = "ERR_FILE_SIZE";
}
else if (this.ImportFile.PostedFile.ContentLength <= 0)
{
uploadResponse.ConfirmAction = false;
FileResult.Value = "ERR_FILE_EMPTY";
}
else
uploadResponse.ConfirmAction = true;
}
catch (Exception ex)
{
uploadResponse.ConfirmAction = false;
uploadResponse.ReasonFailed = "System error: " + ex.Message + " : " + ex.StackTrace;
uploadResponse.TechnicalReasonFailed = "Error in UploadPreferredItems - SetOutputFilePath";
}
}
protected override void PostHandleInputFile()
{
if (!uploadResponse.ConfirmAction) return;
try
{
SaveSRLogoPhotoSite(destinationFilePath);
if (isUpload)
{
base.OutputObjects.Add("UploadResponse", uploadResponse);
}
return;
}
catch (Exception ex)
{
uploadResponse.ConfirmAction = false;
uploadResponse.ReasonFailed = "System error: " + ex.Message + " : " + ex.StackTrace;
uploadResponse.TechnicalReasonFailed = "Error in UploadSRLogo - PostHandleInputFile";
}
}
#region Private Methods
private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{
return SaveSRLogoPhotoSite(destinationFilePath);
}
#endregion Private Methods
}
}
我在這部分上得到錯誤:
private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{ <------on this part is the error
return SaveSRLogoPhotoSite(destinationFilePath);
}
幫助請。 SaveSRLogoPhotoSite方法位於上面的“使用R.WebServices.Facilities”中包含的另一個asmx.cs文件中。
作為參考,我還將在下面粘貼SaveSRLogoPhotoSite方法:
#region SaveSRLogoPhotoSite
[WebMethod(EnableSession = true, Description = "Save sr logo photo in site db")]
[SoapHeader("Authentication")]
[R.One.All.Common.Base.Attributes.ProtectionLevel(true, 10, 20, "8vwsr", RightsBehavior = "or")]
[R.One.All.Common.Base.Attributes.SoapAuthExtension(Priority = 1)]
public SRLogoPhoto SaveSRLogoPhotoSite(string filePath)
{
DataSet ds = null;
Hashtable param = new Hashtable();
SRLogoPhoto srlp = new SRLogoPhoto();
try
{
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
Byte[] b = new Byte[fs.Length];
fs.Read(b, 0, b.Length);
fs.Close();
SqlParameter P = new SqlParameter("@Picture", SqlDbType.VarBinary, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b);
string sqlStr = "UPDATE SRSiteLogo SET srImage = @Picture ";
param.Add("Picture", P);
dbHelper.Entity = OneSiteDB.DBEntity.Site;
ds = dbHelper.GetDataSet(sqlStr, param);
#region SQL Code
string sqlStr2 = "select srImage from SRSiteLogo";
#endregion
int PictureCol = 0;
SqlDataReader reader = dbHelper.ExecuteSqlDataReader(sqlStr2);
reader.Read();
Byte[] b2 = new Byte[(reader.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];
reader.GetBytes(PictureCol, 0, b2, 0, b2.Length);
reader.Close();
string webservicepath = Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
string destfilepath = webservicepath.Replace("\\WebServices\\Facilities", "\\221\\Facilities\\300\\Setup\\srlogo\\images\\S" + base.SiteID + "Logo.jpg");
System.IO.FileStream fs2 = new System.IO.FileStream(destfilepath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
fs2.Write(b2, 0, b2.Length);
fs2.Close();
}
catch (Exception ex)
{
srlp.Error = "SaveSRLogoPhotoSite() web method failed on call to dbHelper.GetDataSet - " + ex.Message;
}
return srlp;
}
#endregion
在這個片段中
private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{ <------on this part is the error
return SaveSRLogoPhotoSite(destinationFilePath);
}
SaveSRLogoPhotoSite(string)
方法正在調用自身。 因此,如果您一次調用該方法,它將繼續調用自身,直到用完堆棧。 得到一個StackOverflowException 。
如果要在另一個程序集或命名空間中實現一個要調用的實現,則必須使用全名對其進行限定
private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{
return SomeAssembly.SomeNamespace.SaveSRLogoPhotoSite(destinationFilePath);
}
如果您已從另一位置復制了這段代碼(您說“ SaveSRLogoPhotoSite方法位於另一個asmx.cs上”,但我不確定是什么意思),則必須弄清楚SaveSRLogoPhotoSite
所指的是什么。上下文。
private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{ <------on this part is the error
return SaveSRLogoPhotoSite(destinationFilePath);
}
哦,具有諷刺意味的是,我們在stackoverflow.com上...
此代碼沒有任何意義。 它調用自身而沒有任何其他操作(或中斷條件)。 這將導致“無休止”的遞歸。 當然,直到堆棧已滿。
它是遞歸調用嗎? 逐步調試。 (或者構造函數不起作用,因為初始化會崩潰。)
=>實現您的SaveSRLogoPhotoSite函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.