BUG: Error message gives wrong information

edited October 2016 in FastReport .NET
I have run into a little error.

When having a DataSource field "Analysis.No" and type it wrong as e.g. "[Analysis.Na]" into a textbox I get this error:
wrote:
Text1: Error CS0103: Der Name 'Analysis' ist im aktuellen Kontext nicht vorhanden.

Translated e.g.
wrote:
Text1: Error CS0103: The Name 'Analysis' is not part of the current context.

Which is wrong. 'Analysis' is part of the current context, but 'Na' is not part of the 'Analysis' context.

I am using the .net Framework 4.0 demo of FastReport.

Samser

Comments

  • edited 3:41PM
    I learn something new from your question, "scripting".
    If there is an error in the script, compiler generates error "..... is not part of the current context."
    using System.CodeDom.Compiler;
    using System.Reflection;
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                Assembly myCode = CompileCode();
                if (myCode != null)
                {
                    MethodInfo mi = myCode.GetExportedTypes().FirstOrDefault().GetMethod("AnotherMethod");
                    try
                    {
                        object result = mi.Invoke(new object(), null);
                        MessageBox.Show(result.ToString(), "Dynamic Method", MessageBoxButtons.OK);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
                    }                
                }
            }
    
    
            private Assembly CompileCode()
            {
                using (CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"))
                {
                    CompilerParameters parameters = new CompilerParameters();
                    CompilerResults results = provider.CompileAssemblyFromSource(parameters, textBox1.Text);
                    if (results.Errors.HasErrors)
                    {
                        foreach (CompilerError err in results.Errors)
                        {
                            MessageBox.Show(err.ErrorText, "Compiler Error", MessageBoxButtons.OK);
                        }
                        return null;
                    }
                    return results.CompiledAssembly;               
                }     
            }
    


    and textBox1.Text contains :
    public class DynamicClass
    {
        public static string DynamicMethod()
        {
            return "Hello World";
        }
    
        public static string AnotherMethod()
        {
            return "Another World";
        }
    }
    
  • Thanks for this post. This is very helpful. For more information you can visit > outsourcing ict.

Leave a Comment