The name 'Reports' does not exist in the current context
The name 'Reports' does not exist in the current context
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?
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
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.
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
.net 4.6.2
that is when we import to report to our application
that is when we open the imported
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
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();
}
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);
Re: The name 'Reports' does not exist in the current context
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
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 266 times
Re: The name 'Reports' does not exist in the current context
Hello.
The issue is in the custom function:
You are adding the function with 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.
The issue is in the custom function:
Code: Select all
public static int TestCode(string parameter)
Code: Select all
StiFunctions.AddFunction()
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
Thank you HighAley
Re: The name 'Reports' does not exist in the current context
Hello.
We are always glad to help you.
Thank you.
We are always glad to help you.
Thank you.