<%#: %> working locally but causes "Expression expected" on server - asp.net

This is not a duplicate of the above linked question - I'm fully aware of the difference between the two code blocks, just read the first line of the question!
(This will only make sense if the "This question may already have an answer here:" is still showing above)
I have recently discovered the <%: %> inline code block (to automatically Server.HtmlEncode the output), as well as the data binding version of <%#: %>.
I have a <asp:Repeater> which contains several <%#: %> blocks which is working locally on my development machine, but causes the following error when published to the server.
BC30201: Expression expected.
The code works correctly if I convert all instances of <%#:...%> to <%#Server.HtmlEncode(...)%>
Using <%: %> in the code on the server, does work.
The application pool in IIS (both my local machine and the server) is setup to use .NET4.0.
Is there anything obvious that could cause the error to happen on the server?
UPDATE
Thanks to #vcsjones, they have correctly pointed out that I have .Net 4.5 installed on my local machine (which I was positive was not the case).
This is the link they helpfully provided to see this was case.

This is because ASP.NET 4.5 was installed locally, and not on the server. The <%#: binding syntax was introduced in ASP.NET 4.5. The <%: and <%# syntaxes existed before 4.5, so that's why they work remotely as well.
The .NET Framework 4.5 is a "drop in" replacement for 4.0, so even if your project specifically targets .NET 4.0, it will still use the 4.5 parser if it's installed, which was happening locally.

Related

IIS .NET Framework, ASP.NET Version Mismatch

I have a .NET 4.0 web application which uses an asp gridview control to display data. The control will automatically sort data when a column header is clicked. I have this application running and sorting fine on both a dev and test server. However, on the prod server, it does not sort correctly. No error is thrown, it just does not act correctly. Since the code is identical I believe this has to be an environment issue.
When trying to troubleshoot this issue, I deliberately malformed the web.config in both environments and noticed the following difference when the error page is displayed:
Dev (code works as expected):
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
Prod (code does not work as expected):
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0
Could this be the cause of the issue? What exactly does this signify? Trying to find this answer on my own has proved fruitless. Any help is appreciated. Thanks!
This issue is caused by ASP.NET Version:4.6.81.0. When updating the dev server to match this version, the gridview does not sort correctly. I'm uncertain as to whether or not this is a bug in ASP.NET or a fix for a bug which was exploited by the code. Regardless, the original issue was caused by difference in ASP.NET versions.

Parse Error when application is deployed to IIS

I have an ASP.NET application written in .NET 4.0. When I run the application through Visual Studio, everything works and looks good. Same thing when I deploy it to IIS7 on my local machine. However, when I deploy it to another box running on Windows Server 2008 R2 with .NET 4.0 and IIS7, I get the following parse error:
Cannot create an object of type 'System.Web.UI.WebControls.TextBoxMode' from its
string representation 'Number' for the 'TextMode' property.
It's complaining that the TextMode property on asp:TextBox doesn't contain the Number option, even though it works perfectly fine on my local IIS. I came across this post and people are suggesting the two machines have different .NET versions. This is not the case for me; both machines are have .NET 4.0 and IIS7.
Besides this error, other pages are also rendered differently style-wise. For example, IIS on the server machine doesn't respect the Width property on any of the asp:TextBox controls; I have to apply the width as a style, even though my local IIS renders them just fine. I'm using IE10 w/o compatibility mode.
I originally thought the problem might have been with missing js or style files, but IE reports success status for all content files in the Network Profiler window.
I'm truly lost at this point. The code, IIS settings, and .NET versions are exactly identical on these two boxes, but the pages are rendered differently. The only thing I can think of is that some other Web component was installed with Visual Studio that is changing the way IIS renders aspx pages. Is that possible? If anyone has come across this issue at some point I'd appreciate it if you could give me some pointers as to what could be causing the issue.
So I finally figured out what the problem was. The parse error did in fact have something to do with .NET. I have .NET 4.5 installed on my machine but not on the server. What I'm still confused about is that the target version for my application is 4.5, so if the Number option exists only in 4.5, why does Visual Studio even display it? Not sure if that's a bug or if I'm overlooking something.
As for the discrepancies between local and server IIS, it turned out I had to install the ASP.NET Browser Definitions Hotfix (KB2600088) on the server. That fixed all the styling issues.

VS2010 converted project invalid reference

Opening a .Net 2 project in VS2010 it converts the project without any issues BUT when I attempt to build it fails.
The reason is that in VS2005 a reference was added to System.Web.Extensions which is a .Net 3.5 assembly. Now VS2005 never complained at this and quite happily worked but VS2010 is far more strict and won't allow it.
I've tried changing the targeted framework to .Net 3.5 but I get another situation there where the web page is never displayed, it simply hangs not even getting to Applicatin_OnStart.
Any help either on adding the reference with .Net 2 as target framework (prefered option for time) or getting the .Net 3.5 version to work would be greatly appreciated.
[Edit]
Ok so maybe the reference was a read herring. One of my colleagues opened the project and did the conversion and once he changed the targetted framework to .Net 3.5 it all worked. The difference between our machines is that he's on 32 bit XP and I'm on 64 bit Windows 7. When I change the targetted version and try to run the program the build seems to stop at CppCodeProvider and hang.
[Edit]
Check your web.config file for the references to System.Web.Extensions. It could be there are duplicate entries or entries pointing to older versions.
Check if the project is just targeting the client profile. The following link could provide you additional information: System.Web.Extensions Assembly cannot be resolved

xml error in webaplication publishing and running

i have developed a asp.net web application in visual studio 2008.
its running perfectly when i build it in visual studio.
but when i published it and configured in iis and try to browse that its geeting an xml error
i tried to browse this
http://localhost/myproject/Pop3Client.aspx
eror is like this
XML Parsing Error: not well-formed
Location: http://localhost/myproject/Pop3Client.aspx
Line Number 1, Column 2:<%# Page Language="C#" %>
-^
i dont what is the problem.
its working right when i build in visual studio...
but when i do this through iis its not..
can anyone help me...
Thanks
Delete the FrontPage-related (VTI) folder on the server and see if that fixes it? The VS publish operation uses this folder but you can still deploy without it by copying. Are you using CSS Adapters? If so, then they do not play nice with the VTI stuff.

Is intellisense not working properly in VS 2008?

I've got trouble getting Intellisense to work in ASP.NET source view.
For example, I register the Telerik RadControls DLL with a tag prefix, as it says in the samples:
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
But when typing <telerik: no intellisense appears.
Also, after adding a couple of controls, they get highlighted with the error "Unrecognized tag prefix or device filter 'telerik'". This is pretty annoying and I can't seem to find a solution.
Btw, the webpage itself works - its just the Intellisense that doesn't.
Intellisense may fail for various reasons so I am going to ask you a few questions:
Does design time work as expected?Sometimes if the design-time assembly is not loaded intellisense may fail.
Do you work on a remote drive by any chance? We have found issues with that as well. The remote drive needs to be added as a trusted location for assemblies.
If you are using an older version of RadControls you need to add reference to Telerik.Charting.dll as well. Which version do you use?
Finally we have found that upgrading to Visual Studio 2008 SP1 solves lots of problems. I strongly recommend you upgrade if not already.
Does your entire project compile? Intellisense often breaks if there are compile errors elsewhere (even compile errors in other pages).
ctrl + space is a shortcut to trigger it ...
probably won't help but at least you will know that the problem is probably with intellisense not being able to find its data.
do you get intellisense for other classes still?
I noticed a general problem with intellisense in VS2008 (with SP1).
As they started supporting JS intellisense a lot of things became slower - or not working sometimes.
I know the describe problem - not only with telerik controls, I also know it from other (and my own) control libraries.
Most of the time a rebuild - close of all pages, and restart of VS solves the problems for me.
My special problem (I guess it matters) is that I use a German release of VS2008.
But also other things rule (from my experiences):
The size of the project (somewhere above 50 pages things become worse).
The time I had to kill an app while debuging :)
General the time (in a session) I work on a project.
A last tip (which may help) I feel less problems when I add a ref to the controls directly in web.config. Additionally it frees me from havin the register directive on every page.
It looks like this:
<controls>
<add assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagPrefix="telerik" />
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions,
HTH
Manfred
Just fixed this myself for VS2008 (for aspx/ascx and codebehind) by adding the Telerik .dlls to the GAC on my local development machine.
I've had this issue before and both times it occurred was when my project was hosted on a network drive, where the project's path would be something like: *\\networkmachinename\c$\inetpub\projectname*
The fix:
On your local machine, go to Start > Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt (run as admin)
Using the gacutil tool and the following commands (or more depending on how many .dlls you wish to use), add the assemblies to your GAC:
gacutil.exe -i "C:\Program Files (x86)\Telerik\RadControls for ASPNET AJAX Q2 2008\Bin35\Telerik.Web.UI.dll"
gacutil.exe -i "C:\Program Files (x86)\Telerik\RadControls for ASPNET AJAX Q2 2008\Bin35\Telerik.Charting.dll"
Obviously modify the dirs as appropriate for your OS/Telerik/Framework versions, then close Visual Studio 2008 Command Prompt, close VS2008 (if open) and restart VS2008 again.
You'll find the intellisense works on the aspx/ascx files first, and given a few minutes it'll work on your codebehind files too. Close and retry if it still doesn't work.
One other note, if you have a small error somewhere in your website's root web.config file, you'll also lose intellisense for Telerik (and perhaps other) controls - so check your web.config files aren't erroneous first.

Resources