I have an ascx that uses Eval in a repeater like this:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Similar.ascx.vb" Inherits="x.y.z.Similar" %>
<asp:repeater runat="server" id="rptAlternatives" visible="false" Enableviewstate="false">
<HeaderTemplate>
<section id="similar" class="sidelist sideModule">
<h3>Possible Alternatives:</h3>
<ul class="sideborder">
</HeaderTemplate>
<ItemTemplate>
<li>
<a href="/bar/<%# Eval("URL")%>" class="box">foo</a>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</section>
</FooterTemplate>
</asp:repeater>
This works fine on my development PC, but when I deploy it to our live server it fails saying: Compiler Error Message: BC30451: 'Eval' is not declared. It may be inaccessible due to its protection level.
What's really odd is that sometimes restarting the application pool makes it go away and then sometimes it comes back again. Also it's not breaking on every page that uses Eval
.
The local environment is IIS 7.5.7600.16385 with an application pool running ASP.NET v4.0 Classic. The server environment is the same. I publish from VS on my machine and copy this onto the live server to deploy.
Before this deployment the live site was using v2.0. Upgrading the site to v4.0 is part of the changes we're trying to release. This code has not changed as part of this release. It has always used Eval, and this has always been fine.
I have installed the Visual Studio 11 beta, but I'm using 2010 for this project.
Any ideas what could be causing this?
Edit:
This experts exchange post seems to describe exactly the same behaviour. They "fixed" it by changing the name of their class in both ascx and ascx.vb files. They matched before the change and they matched after the change, but the change obviously jogged something in the compiler. I might give this a go, but it doesn't seem satisfactory that a particular ascx would just stop working.
I've also found plenty of posts suggesting changing it to DataBinder.Eval(Container.DataItem, "URL")
. However, I'm again reluctant to do this when the code worked before and has suddenly stopped. It's a magic and random "fix" that I'm unwilling to use.