StrataFrame Forum

ERROR - Image Field

http://forum.strataframe.net/Topic13213.aspx

By Rogerio Mauri - 12/31/2007

Checks the business rules on the current row returned error.

private void TbCadastroBO_CheckRulesOnCurrentRow(CheckRulesEventArgs e)
{
    if (this.Foto.Width > 110 || this.Foto.Height > 150)
        this.AddBrokenRule(TbCadastroBOFieldNames.Foto, "Foto com dimensão inválida");
    if (this.Foto.HorizontalResolution > 210 || this.Foto.HorizontalResolution < 80
        || this.Foto.VerticalResolution > 210 || this.Foto.VerticalResolution < 80)
        this.AddBrokenRule(TbCadastroBOFieldNames.Foto, "Foto com resolução inválida");
}

Returned error in get (try{..}): System.StackOverflowException was unhandled
{Cannot evaluate expression because the current thread is in a stack overflow state.}


[Browsable(false),
 BusinessFieldDisplayInEditor(),
 Description("Foto"),
 DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public System.Drawing.Bitmap Foto
{
    get
    {
        try
        {
            return (System.Drawing.Bitmap)this.BinaryFormatter.Deserialize(new MemoryStream((Byte[])this.CurrentRow["Foto"]));
        }
        catch
        {
            return null;
        }
    }
    set
    {
        MemoryStream loStream = new MemoryStream();
        this.BinaryFormatter.Serialize(loStream, value);
        this.CurrentRow["Foto"] = loStream.ToArray();
    }
}

By Rogerio Mauri - 12/31/2007

Please. To cancel this occurrence, therefore I already identified the code that was causing the error.
Invalid verify business rules in BusinessRulesChecked was returning error.

private void tbCadastroBO1_BusinessRulesChecked(MicroFour.StrataFrame.Business.BusinessRulesCheckedEventArgs e)
{
    ClearErrorProvider();
    //-- Verify Business Rules
    if (!tbCadastroBO1.CheckRulesOnRow())
    {
        foreach (BrokenRule loRule in tbCadastroBO1.BrokenRules.ToArray())
        {
            if (loRule.FieldName.EndsWith("Foto", StringComparison.OrdinalIgnoreCase))
                SetErrorProvider(picFoto, loRule.Description);
        }
    }
}

This is OK.
private void tbCadastroBO1_BusinessRulesChecked(MicroFour.StrataFrame.Business.BusinessRulesCheckedEventArgs e)
{
    foreach (BrokenRule loRule in tbCadastroBO1.BrokenRules.ToArray())
    {
        if (loRule.FieldName.EndsWith("Foto", StringComparison.OrdinalIgnoreCase))
            SetErrorProvider(picFoto, loRule.Description);
    }
}