Page 1 of 1

The name 'Reports' does not exist in the current context

Posted: Mon Sep 09, 2019 1:20 pm
by javorbg
I have problem with reports which have C# code in them when I open one of them and then open second one an error occur:
System.Exception HResult=0x80131500
Message=c:\Users\*\AppData\Local\Temp\uvk1gxkl.0.cs(510,40) : error CS0103: The name 'Reports' does not exist in the current context
c:\Users\*\AppData\Local\Temp\uvk1gxkl.0.cs(516,40) : error CS0103: The name 'Reports' does not exist in the current context
c:\Users\*\AppData\Local\Temp\uvk1gxkl.0.cs(522,40) : error CS0103: The name 'Reports' does not exist in the current context
Source=Stimulsoft.Report
StackTrace:
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile()
I tried to change the namespace and class name of the one of them but the same error occur. Is there any cache?

Re: The name 'Reports' does not exist in the current context

Posted: Mon Sep 09, 2019 4:38 pm
by HighAley
Hello.

What version of .Net Framework do you use?
Please, send us the line of code that cause the issue.
Could you send us a sample project?

Thank you.

Re: The name 'Reports' does not exist in the current context

Posted: Tue Sep 10, 2019 7:14 am
by javorbg
.net 4.6.2
that is when we import to report to our application

Code: Select all

 
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
using (BinaryReader br = new BinaryReader(fileStream))
{
                    long numBytes = new FileInfo(fileName).Length;
                    buff = br.ReadBytes((int)numBytes);


                    string template = Encoding.UTF8.GetString(buff);
                    var report = new StiReport();
                    if (fileName.EndsWith(".mrt"))
                    {
                        report.LoadFromString(template);
                    }
                    else
                    {
                        report.LoadPackedReportFromString(template);
                    }

                    report.Compile();
}
that is when we open the imported

Code: Select all

var report = new StiReport();
report.LoadPackedReportFromString(Encoding.UTF8.GetString(dbReport.Template));
report.LocalizeReport(LocalizeDictionary.CurrentCulture.TwoLetterISOLanguageName);
report.Compile();
report.DesignWithWpf(col[0], true);
The error occur on report.Compile(); line in both. If I try to import reports import the first one then on second one occur the error i need to close the program to import second one without the error, but then I open one of them on second one occur the error

Re: The name 'Reports' does not exist in the current context

Posted: Tue Sep 10, 2019 7:34 am
by javorbg
What I noticed when you have both of reports imported and open one of them then you try to open second one on compile can the names in the error are from the fist one for example "The name 'Reports' does not exist in the current context" - Reports is the namespace in the first one i rename the second one namespace because I thought problem is in the same namespace Name but is not.

Re: The name 'Reports' does not exist in the current context

Posted: Tue Sep 10, 2019 12:07 pm
by javorbg
Here is Examples reports and code which open them if you try to open second one without closing the program you will see the error

Code: Select all

private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".mrt";
            dlg.Filter = "(*.mrt)|*.mrt|" + " (*.mrz)|*.mrz";
            bool? result = dlg.ShowDialog();
            if (result == true)
            {

                StiLocalization.LoadDefaultLocalization();
                //// Open document 
                string fileName = dlg.FileName;
                byte[] buff = null;
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    long numBytes = new FileInfo(fileName).Length;
                    buff = br.ReadBytes((int)numBytes);

                    //// Write document into db
                    string template = Encoding.UTF8.GetString(buff);
                    var report = new StiReport();
                    if (fileName.EndsWith(".mrt"))
                    {
                        report.LoadFromString(template);
                    }
                    else
                    {
                        report.LoadPackedReportFromString(template);
                    }

                    report.Compile();
                    report.DesignWithWpf();
                }
            }
        }

Re: The name 'Reports' does not exist in the current context

Posted: Wed Sep 11, 2019 10:14 am
by HighAley
Hello.

The issue is in the custom function:

Code: Select all

public static int TestCode(string parameter)
You are adding the function with

Code: Select all

StiFunctions.AddFunction()
to the static class StiFunctions.

So, when you register the function second time it is trying to be taken from the first report. But it is not available.

The StiFunctions class was created to add one function for all reports. It's impossible to add different functions with the same name.

We can suggest you several solutions:

- Do no add the functions to the StiFunctions class. It will work anyway but you will not see it in the list of functions.

- Crete one function, add it to a separate assembly and load it from there.

- Use different name foe each function.

Thank you.

Re: The name 'Reports' does not exist in the current context

Posted: Wed Sep 11, 2019 11:19 am
by javorbg
Thank you HighAley :)

Re: The name 'Reports' does not exist in the current context

Posted: Thu Sep 12, 2019 6:48 am
by HighAley
Hello.

We are always glad to help you.

Thank you.