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

Stimulsoft Reports.Wpf discussion
Post Reply
javorbg
Posts: 5
Joined: Mon Sep 09, 2019 6:57 am
Location: Sofia

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

Post by javorbg » Mon Sep 09, 2019 1:20 pm

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?
HighAley
Posts: 8047
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

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

Post by HighAley » Mon Sep 09, 2019 4:38 pm

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.
javorbg
Posts: 5
Joined: Mon Sep 09, 2019 6:57 am
Location: Sofia

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

Post by javorbg » Tue Sep 10, 2019 7:14 am

.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
javorbg
Posts: 5
Joined: Mon Sep 09, 2019 6:57 am
Location: Sofia

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

Post by javorbg » Tue Sep 10, 2019 7:34 am

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.
javorbg
Posts: 5
Joined: Mon Sep 09, 2019 6:57 am
Location: Sofia

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

Post by javorbg » Tue Sep 10, 2019 12:07 pm

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();
                }
            }
        }
Attachments
ReportExamples.zip
(14.04 KiB) Downloaded 4 times
HighAley
Posts: 8047
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

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

Post by HighAley » Wed Sep 11, 2019 10:14 am

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.
javorbg
Posts: 5
Joined: Mon Sep 09, 2019 6:57 am
Location: Sofia

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

Post by javorbg » Wed Sep 11, 2019 11:19 am

Thank you HighAley :)
HighAley
Posts: 8047
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

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

Post by HighAley » Thu Sep 12, 2019 6:48 am

Hello.

We are always glad to help you.

Thank you.
Post Reply