System OutOfMemoryException

Farah El Agha asked on December 27, 2017 17:45

Hello guys, I am facing a really weird situation, my project gives a System.OutOfMemoryException and then the repeater returns System.Web.HttpUnhandledException but the weird thing is that it is not permanent, sometimes the website opens normally (without cache) and after some refresh, the page redirects me to the error page, it happened after I tried to enter some data to the repeater which takes a TimeLine data type, here is my transformation

<%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>

<%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachmentsVideo.ascx" TagName="DocumentAttachmentsVideo" TagPrefix="cms" %>

protected override void OnInit(EventArgs e)
{
    CMS.DataEngine.DataClassInfo dci = CMS.DataEngine.DataClassInfoProvider.GetDataClassInfo(Eval("ClassName").ToString(), true);
    if (dci != null)
    {
        CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(dci.ClassFormDefinition);
        // field name we added in the page type
        CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("Images");
        CMS.FormEngine.FormFieldInfo ffiReports = fi.GetFormField("Reports");
        CMS.FormEngine.FormFieldInfo ffiFiles = fi.GetFormField("Files");

        Guid AttachmentGroupGUID = ffi.Guid;
        Guid AttachmentGroupGUIDRep = ffiReports.Guid;
        Guid AttachmentGroupGUIDFil = ffiFiles.Guid;

        ucDocAttachments.Path = Eval<string>("NodeAliasPath");
        ucDocAttachmentReports.Path = Eval<string>("NodeAliasPath");
        ucDocAttachmentFil.Path = Eval<string>("NodeAliasPath");

        ucDocAttachments.AttachmentGroupGUID = AttachmentGroupGUID;
        ucDocAttachmentReports.AttachmentGroupGUID = AttachmentGroupGUIDRep;
        ucDocAttachmentFil.AttachmentGroupGUID = AttachmentGroupGUIDFil;

        ucDocAttachments.TransformationName = "CMS.Root.Attachment";
        ucDocAttachmentReports.TransformationName = "CMS.Root.AttachmentLinks";
        ucDocAttachmentFil.TransformationName = "CMS.Root.AttachmentLinks";

        ucDocAttachments.ReloadData(true);
        ucDocAttachmentReports.ReloadData(true);
        ucDocAttachmentFil.ReloadData(true);
    }
}

< div class="innerSelectedElectionContainer col-xs-12 selected-<%# DataItemIndex %>" >

< div class="col-xs-12 selectedElectionInfo selectedContent-0">
    < div class="col-xs-12 selectedElectionTitle elem-to-hide">
        <%# Eval("Title") %>
    < /div>
    < div class="col-xs-12 selectedElectionText elem-to-hide">
        <%# Eval("Text") %>
    < /div>
</div>
<div class="selectedElectionInfo elem-to-hide selectedContent-1">
    <div class="col-xs-12 photosLabel"><%# Localize("{$photosGallery$}") %></div>
    <div class="selectedContent-1 owl-carousel owl-theme">
        <cms:DocumentAttachments ID="ucDocAttachments" runat="server" />
    </div>
</div>
<div class="selectedElectionInfo elem-to-hide selectedContent-2 col-xs-12">
    <div class="col-xs-12 photosLabel"><%# Localize("{$videosGallery$}") %></div>
    <cms:DocumentAttachmentsVideo ID="DocumentAttachmentsVideo" runat="server" ImageFieldValues='<%# Eval("Videos") %>' />
</div>
<div class="selectedElectionInfo elem-to-hide selectedContent-3">
          <div class="col-xs-12 photosLabel"><%# Localize("{$reports$}") %></div>
   <div class="col-xs-12 selectedContent-3 ElectionReports">
    <cms:DocumentAttachments ID="ucDocAttachmentReports" PageSize="50"  runat="server" />

< /div>

</div>
<div class="selectedElectionInfo elem-to-hide selectedContent-4">
   <div class="col-xs-12 photosLabel"><%# Localize("{$files$}") %></div>
   <div class="col-xs-12 selectedContent-4 ElectionFiles">
    <cms:DocumentAttachments ID="ucDocAttachmentFil" PageSize="50" runat="server" />
     </div>
</div>

and inside my code I wrote:

 public string ImageFieldValues { get; set; }



protected void Page_Load(object sender, EventArgs e)
{

    string pattern = "embed/(?<code>[A-Za-z0-9_-]*)";
    string[] values = ImageFieldValues.Split(new[] { "<br />" }, StringSplitOptions.RemoveEmptyEntries);



    LiteralControl litCon = new LiteralControl();
    litCon.Text = "<ul class='slides'>";
    if (values.Length != 0)
    {
        foreach (string source in values)
        {
            Match match = Regex.Match(source, pattern);
            var api = $"http://youtube.com/get_video_info?video_id=" + match.Groups["code"].Value;

            litCon.Text += "<li><img id='iframeImage' src='http://img.youtube.com/vi/" + match.Groups["code"].Value + "/hqdefault.jpg'/><img class='youtubeIcon' style='display: none;' src='LADE/media/LADE-images/Dakirby309-Simply-Styled-YouTube-(1).png'/><a name='testiFrame' data-fancybox='gallery' data-fancybox-type='iframe' id='runtimeIFrame' class='col-xs-12 various youtubeVideo iframe' href='" + source + "'></a></li>";



        }
        litCon.Text += "</ul>";
        AddToDivImages.Controls.Add(litCon);
    }
}

The Event Logs show:

Message: Exception of type 'System.OutOfMemoryException' was thrown.

Exception type: System.OutOfMemoryException Stack trace: at System.Data.SqlClient.TdsParserStateObject.TryReadPlpBytes(Byte[]& buff, Int32 offst, Int32 len, Int32& totalBytesRead) at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly) at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values) at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values) at System.Data.ProviderBase.SchemaMapping.LoadDataRow() at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) at CMS.DataEngine.AbstractDataConnection.CMS.DataEngine.IDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) at CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query) at CMS.DataEngine.GeneralConnection.RunQueryWithRetry(QueryParameters query, Int32 retryCount) at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query) at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query, Int32& totalRecords) at CMS.DataEngine.DataQueryBase1.GetDataFromDBInternal() at CMS.DataEngine.DataQueryBase1.GetDataFromDB() at CMS.DataEngine.DataQueryBase1.GetData() at CMS.DataEngine.DataQueryBase1.get_Result() at CMS.DataEngine.ObjectQueryBase2.GetResults(IDataQuery query, Int32& totalRecords) at CMS.DataEngine.DataQueryBase1.GetDataFromDB() at CMS.DataEngine.DataQueryBase1.GetData() at CMS.DataEngine.ObjectQueryBase2.GetData() at CMS.DataEngine.DataQueryBase`1.get_Result() at CMS.DocumentEngine.Web.UI.AttachmentsDataSource.GetDataSourceFromDB(Int32 offset, Int32 maxRecords, Int32& totalRecords) at CMS.DocumentEngine.Web.UI.CMSBaseDataSource.GetDataSourceFromDB() at CMS.DocumentEngine.Web.UI.CMSBaseDataSource.GetDataSource(Int32 offset, Int32 maxRecords) at CMS.DocumentEngine.Web.UI.CMSBaseDataSource.GetDataSource() at CMS.DocumentEngine.Web.UI.CMSBaseDataSource.get_DataSource() at CMSModules_Content_Controls_Attachments_DocumentAttachments_DocumentAttachments.ReloadData(Boolean forceReload) in C:\inetpub\wwwroot\Lebanon\Lade\lade-portal\CMS\CMSModules\Content\Controls\Attachments\DocumentAttachments\DocumentAttachments.ascx.cs:line 895 at ASP.cmsvirtualfiles_transformations__vg_6bab1a69_6607_4e8d_b031_f64e6a63e261_custom_elections_selectedelection_ascx.OnInit(EventArgs e) in http://server/Lade/CMSVirtualFiles/Transformations/=vg=6bab1a69-6607-4e8d-b031-f64e6a63e261/custom.Elections/selectedElection.ascx:line 35 at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.AddedControl(Control control, Int32 index) at System.Web.UI.ControlCollection.Add(Control child) at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) at CMS.DocumentEngine.Web.UI.BasicRepeater.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.Repeater.DataBind() at CMS.DocumentEngine.Web.UI.BasicRepeater.DataBind() at CMS.DocumentEngine.Web.UI.CMSRepeater.DataBind() at CMS.DocumentEngine.Web.UI.CMSRepeater.ReloadDataInternal(Boolean forceReload) at CMS.DocumentEngine.Web.UI.CMSRepeater.<>c__DisplayClass3.b__2() at CMS.Base.Web.UI.ControlsExtensions.CallHandled(Control ctrl, Action func)

And

Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.

Exception type: System.Web.HttpUnhandledException Stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.cmspages_portaltemplate_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Message: Object reference not set to an instance of an object.

Exception type: System.NullReferenceException Stack trace: at CMSModules_Content_Controls_Attachments_DocumentAttachments_DocumentAttachmentsVideo.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\Lebanon\Lade\lade-portal\CMS\CMSModules\Content\Controls\Attachments\DocumentAttachments\DocumentAttachmentsVideo.ascx.cs:line 22 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

What could be the cause for all this?

Correct Answer

Trevor Fayas answered on January 2, 2018 17:00

Just like i posted, in your transformation add the GetBinary="false" attribute to your controls that you are calling.

Another trick to help save on performance, is also add the attribute StopProcessing="true" on your declaration, then in your OnInit overwrite, set it to false before the reload. This way it won't try to "build" only to be rebuilt.

So change:

ucDocAttachments.ReloadData(true);
        ucDocAttachmentReports.ReloadData(true);
        ucDocAttachmentFil.ReloadData(true);

to

    ucDocAttachments.StopProcessing = false;
            ucDocAttachmentReports.StopProcessing = false;
                    ucDocAttachmentFil.StopProcessing = false;
        ucDocAttachments.ReloadData(true);
        ucDocAttachmentReports.ReloadData(true);
        ucDocAttachmentFil.ReloadData(true);

and change your inline tags to

<cms:DocumentAttachments ID="ucDocAttachments" GetBinary="false" StopProcessing="true" runat="server" />

0 votesVote for this answer Unmark Correct answer

Recent Answers


Development Support answered on December 28, 2017 06:27

If i'm reading this correctly, it's running out of memory retrieving the Document Listing, see at the top of the list "TryReadSqlValue" is where about it's running into problems, being called from CMSModules_Content_Controls_Attachments_DocumentAttachments_DocumentAttachments.ReloadData(Boolean forceReload (The Document Attachment).

Getting the document attachment, you SHOULD be able to tell it to get all the attachment data WITHOUT the binary data. I think it's a property on the DocumentAttachments, or see if you can limit the Columns returned and exclude the binary data. That should solve the issue.

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on December 28, 2017 09:17

hi, can you give me more details how to get the attachments data WITHOUT the binary data or how to limit the Columns returned and exclude the binary data? or give me some useful links if you have. Because I was'nt able to find info about that. also is there an explanation why sometimes its running normally without any memory exception?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on December 30, 2017 07:16

Farah, Sorry i didn't get back to you yet, i'll try to early next week look at the actual files, there should be a parameter you can pass to the DocumentAttachment control in your transformation.

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on January 2, 2018 07:54

Hi Trevor, still waiting your response for which parameter to use with the control.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on January 2, 2018 14:48

Sorry for the delay.

The Document Attachment control has a property "GetBinary", set that to false.

ex:

<cms:DocumentAttachments ID="ucDocAttachments" runat="server" />

Changes to

<cms:DocumentAttachments ID="ucDocAttachments" runat="server" GetBinary="false" />

Try that, that should do the trick!

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on January 2, 2018 16:25

thank you trevor, one more question, if I am using a repeater webpart, how can I set the GetBinary option?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.