为什么我得到';类型为';System.StackOverflowException';发生在DLL&

本文关键字:StackOverflowException System DLL 类型 为什么 | 更新日期: 2023-09-27 18:09:58

我能够在目标路径上成功上传文件,但我遇到了这个错误,我不知道为什么。

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方法位于另一个asmx.cs文件上,该文件包含在我上面的"使用R.WebServices.Facilities"中。

为了参考,我还将粘贴下面的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

为什么我得到';类型为';System.StackOverflowException';发生在DLL&

在这个片段中

private SRLogoPhoto SaveSRLogoPhotoSite(string destinationFilePath)
{   <------on this part is the error
   return SaveSRLogoPhotoSite(destinationFilePath);
}

方法CCD_ 1正在调用它自己。因此,如果您调用该方法一次,它将继续调用自己,直到您用完堆栈,即获得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功能

相关文章:
  • 没有找到相关文章