ASP.NET how to resolve CS1513: } expected error on page - asp.net

I am getting an error at run time when viewing my ASP.NET page in the browser. I am not getting any build errors however I am getting the following compiler error at runtime:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1513: } expected
Source Error:
Line 329: #line hidden
Line 330: __output.Write("\r\n\t\t\t</div>\r\n\t\t");
Line 331: }
Line 332:
Line 333: private System.Web.UI.Control __BuildControl__control7() {
Source File: c:\Windows\Microsoft.NET\Framework\v1.1.4322\
Temporary ASP.NET Files\xxxxxxxx\450ffa78\d46d847d\
k1gsz9dj.0.cs Line: 331
I cannot locate any missing } in my source code and this error is occurring in the generated code files that exist in the Temporary ASP.NET Files directory. How can I trace this to the line of code that is actually malformed in my page or user controls on my page?

If the error code related as following:
A variable name same as reserved word then you can rename variable.
A code segment such as:
#model MyModel
{
var appname = #Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp);
}
Remove '#' coming before Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)
A code segment or section usage such as:
#section{
<!-- hiiii it's not about an error -->
}
Remove the apostrophe from comment in section.
If it is none of these specific cases you can attempt to locate where the error is generated by applying a source reduction. Delete/cut/comment out pieces of code until you can reliably turn the error off and on. The code that turns the error on is likely the culprit if it is not one of the above situations.

Look in the markup (aspx or ascx) for blocks like:
<% ... some C# code.... { %>
markup(controls, html etc)
<% } %>
Any opened bracket { needs to be closed with another bracket }.
These pages or controls are compiled once by ASP .Net when they are first requested.
Visual Studio doesn't compile aspx or ascx files.
If the project is "Web Site" type, Visual Studio compiles the aspx/ascx files, but if the project is "Web Application" type Visual Studio doesn't "compile" the markup (it does not generate the corresponding classes to the aspx/ascx markup)

On my site, the problem was caused by a block of code that looked like this:
#{
var currentNode = #linkedList.Find(#CurrentPage);
if (#currentNode.Next != null)
{
var next = #currentNode.Next;
<li>
#next.Name
</li>
}
if (#currentNode.Previous != null)
{
var prev = #currentNode.Previous;
<li>
#prev.Name
</li>
}
}
I'm not sure why the problem was caused by the nesting. This may be a bug in the compiler.

I got a similar problem and oculd find it only after a log of trial and error.
The error I made was to add a '#' to variables inside a foreach loop which started with:
#foreach

Well as the error suggests, you are missing a closing curly brace '}'
Have a look at the msdn compiler errors documentation:
http://msdn.microsoft.com/en-us/library/83ht1k63(v=vs.80).aspx
As in the example on MSDN:
// the below will cause CS1513 since namespace is missing '}'
namespace y
{
class x
{
public static void Main()
{
}
}

try to compile it in visual studio. i think it will also show where the exact line of the code that has incomplete curly braces.
compilation error cs1513

Related

.Net 6.0 console application keeps displaying popup message while I am trying to code

I am typing in an example from the book, "C# 10 and .Net 6".
It is a console application with reflection.
Here is the code so far:
using System.Reflection;
Assembly? assembly = Assembly.GetEntryAssembly();
if (assembly == null) return;
// Loop through the assemlies that this app references
foreach (AssemblyName name in assembly.GetReferencedAssemblies())
{
// Load the assembly so we can read its details
Assembly a = Assembly.Load(name);
// declare a variable to count the number of methods
int methodCount = 0;
// loop through all the types in the assembly
foreach (TypeInfo t in a.DefinedTypes)
{
// add up the counts of methods
methodCount += t.GetMethods().Count();
}
//
}
I got this far and was about to type in the last part and I got the popup dialogue in the pic:
It says:
Specified argument was out of the range of valid values.
Parameter name: length
Why does this obtrusive popup keep displaying and stopping me from typing? What is it? What does it mean? Why does it not wait for you to try and build, compile or run before reporting the problem.
What is this and how do you make it go away?
I just want to add I was able to type it all in and the example runs correctly. But why does VS 2022 keep displaying this popup while I am trying to type?
This looks like a problem with Visual Studio or an extension. It's not a problem with your code.
You could try:
Restarting VS,
Restarting Windows,
Repairing/updating/reinstalling VS.

Is there a way to see the RenderTreeBuilder version of the razor file in blazor?

Take the index page for example:
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
It is my understanding that this will be translated into some code using the RenderTreeBuilder which may look something like this:
builder.OpenElement(0, "h1")
builder.AddContent(1, "Hello, world!")
.
.
.
Is there a place where I can inspect the RenderTreeBuilder version of the razor pages?
I would like to start trying out RenderTreeBuilder and would like to know how it is done, for references purposes.
Apologies in advanced if this is a duplicate. I will delete this question if so.
Thanks!
You are right. The BlazorMarkup is translated into C# files that are using the RenderTreeBuilder. It is comparable to what WPF does when it comes to XAML and C# files.
After you have built your project, go to the obj/debug/net5.0/Razor/.
Keep in mind to use a debug build. Otherwise, you won't see the files.
You will see the same directory structure as in your project. Directories are listed as long as they contain razor files. Open the file, e.g., Index.razor.g.cs (.g stands for generated), and you can see the calls to RenderTreeBuilder
[Microsoft.AspNetCore.Components.RouteAttribute("/")]
public partial class Index : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.AddMarkupContent(0, "<h1>Hello, world!</h1>\r\n\r\nWelcome to your new app.\r\n\r\n");
__builder.OpenComponent<BlazorApp1.Shared.SurveyPrompt>(1);
__builder.AddAttribute(2, "Title", "How is Blazor working for you?");
__builder.CloseComponent();
}
#pragma warning restore 1998
}

Exporting data from database into pdf in asp.net

I have a lot of tables with lot of rows and columns which I am trying to export into a pdf on a button click in an asp.net webform. This data looks good in a listview. I used iTextSharp, but I couldn't figure out how to export listview to pdf using iTextSharp. So I used datatable and it didn't look very well with iTextSharp. I came across "Spire.DataExport for .NET" but it doesn't seem to be available freely.
Please let me know what's the best way to export a listview into a pdf in asp.net.
UPDATE:
I tried using wkhtmltopdf from codaxy's github link. But even for a simple html line, the conversion is failing from the c# code. Any help on this will be really appreciated, as I have spent a lot of time on this getting nowhere.
c# code:
PdfConvert.ConvertHtmlToPdf(
new PdfDocument { Html = "<html><h1>test</h1></html>" },
new PdfOutput { OutputFilePath = "inline.pdf" }
);
Error::
Server Error in '/JobCosting' Application.
Html to PDF conversion of '-' failed. Wkhtmltopdf output:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: PdfConvertException: Html to PDF conversion of '-' failed. Wkhtmltopdf output:
Source Error:
Line 292: if (process.ExitCode != 0 && !File.Exists(outputPdfFilePath))
Line 293: {
Line 294: throw new PdfConvertException(String.Format("Html to PDF conversion of '{0}' failed. Wkhtmltopdf output: \r\n{1}", document.Url, error));
Line 295: }
Line 296: }
Use wkhtmltopdf from https://wkhtmltopdf.org/
Make HTML from this list control using RenderControl method, and write it fo file, then run that wkhtmltopdf.exe from net using System.Diagnostics.Process class, then it produce pdf file
More answers here Convert HTML to PDF in .NET

Compile IDL file error

I'm using VS 2008 Pro.
I have 1 idl file which contains:
module views {
// Introduced in DOM Level 2:
interface [
ObjCCustomImplementation,
OmitConstructor
] AbstractView {
readonly attribute Document document;
readonly attribute Media styleMedia;
};
}
(That's all, no more in the file.)
When I build the file (right click to file and press Compile, error occurs as following:
AbstractView.idl
..\page\AbstractView.idl(30) : error MIDL2025 : syntax error : expecting a type specification near "interface"
..\page\AbstractView.idl(31) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
What is the problem? How can I fix this?
Maybe it should be other way. As far as I remember, first you must define attributes, then interface itself. This link can be useful.
That might be a CORBA IDL file rather than a MIDL file.

Error handling for ASP based sites and forms

I'm working on a asp based (not .net) site, which spans about 400 odd pages... Now, throughout the site there're ASP and VBScript errors, such as:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Cdate'
/MySite/page.asp, line 71
(The above happened when I put in characters into a 'date' field. I know its VBScript in this case, but I get plenty all over.)
Now, I know I can avoid this scenario with client side validation (jQuery for example), but when such things do happen, how do I code up a default 'error' page? You hit the error, and instead of showing you the above, you get redirected to a generic 'error' page?
I've looked up some of this, and found the ASP 'On Error Resume Next' thing, but I haven't found any viable examples. Each one is tailored to a specific error (like dividing 5 by 0), and I really don't want to code up like 400+ potential error messages.
You could create custom error pages, via IIS. I'm not sure what version you're running, etc - but this should give you a good jumping off point. http://support.microsoft.com/kb/224070
You add following code in top in your page.
<% on error resume next%>
.
..
....
(Other code is above instead of point(.))
Then you add
<% if err then
response.redirect("err.page?code="&err.code)
end if%>
And you define error message in your generic error page according to error number.
if you ask same question for client side. You can try and catch code block for possible code clock that will can throw.
For examle
<script language="text/javascript">
try
{
//Code that will can throw error is here.
}
catch(err)
{
document.href.location="genericerrorpage.asp?err=" + err.code;
}
}
</script>

Resources