为什么我得到'未处理的类型' System.StackOverflowException'发生在DLL'

时间:2014-06-24 07:08:53

标签: c#

我能够在目标路径上成功上传文件,但是我收到此错误并且我不知道原因。

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&#39;上方。

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

3 个答案:

答案 0 :(得分:5)

在此代码段中

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);
}

如果您从其他地方复制了这段代码(您说&#34; SaveSRLogoPhotoSite方法在另一个asmx.cs&#34;,但我不完全确定这意味着什么),您将必须弄清楚SaveSRLogoPhotoSite在该背景下所指的是什么。

答案 1 :(得分:2)

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

哦,具有讽刺意味的是,我们在stackoverflow.com上......

这段代码毫无意义。它在没有任何其他操作(或中断条件)的情况下调用自身。这将导致无休止的&#34;递归。当然,直到堆满了。

答案 2 :(得分:1)

这是递归电话吗?在其中进行调试。 (或者构造函数不起作用,因为初始化崩溃了。)

=&GT;实施SaveSRLogoPhotoSite功能