我'm得到"'Eval'未声明.由于其保护级别,它可能无法访问"在一个 ascx [英] I'm getting "'Eval' is not declared. It may be inaccessible due to its protection level" in a ascx

查看:31
本文介绍了我'm得到"'Eval'未声明.由于其保护级别,它可能无法访问"在一个 ascx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在中继器中使用 Eval 的 ascx,如下所示:

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>

这在我的开发 PC 上运行良好,但是当我将它部署到我们的实时服务器时,它失败说:编译器错误消息:BC30451:'Eval' 未声明.由于其保护级别,它可能无法访问. 真正奇怪的是,有时重新启动应用程序池会使其消失,然后有时又会再次出现.此外,它不会在每个使用 Eval 的页面上中断.

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.

本地环境为 IIS 7.5.7600.16385,应用程序池运行 ASP.NET v4.0 Classic.服务器环境是一样的.我在我的机器上从 VS 发布并将其复制到实时服务器上进行部署.

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.

在此部署之前,实时站点使用的是 v2.0.将站点升级到 v4.0 是我们尝试发布的更改的一部分.作为此版本的一部分,此代码未更改.它一直使用 Eval,这一直很好.

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.

我已经安装了 Visual Studio 11 测试版,但我在这个项目中使用的是 2010.

I have installed the Visual Studio 11 beta, but I'm using 2010 for this project.

任何想法可能导致这种情况?

Any ideas what could be causing this?

这个专家交流帖似乎描述的一模一样行为.他们通过在 ascx 和 ascx.vb 文件中更改其类的名称来修复"它.它们在更改前匹配,在更改后匹配,但更改显然在编译器中引发了一些问题.我可能会试一试,但特定的 ascx 停止工作似乎并不令人满意.

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.

我还发现很多帖子建议将其更改为 DataBinder.Eval(Container.DataItem, "URL").但是,当代码之前工作并且突然停止时,我再次不愿意这样做.这是我不愿意使用的魔法和随机修复".

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.

推荐答案

事实证明,重要的细节是我们正在从 v2.0 更新到 v4.0,并且我们在之前部署的顶部复制文件.

The important detail turned out to be that we were updating from v2.0 to v4.0 and that we were copying files over the top of the previous deployment.

在服务器上的 bin 目录中仍有 v2.0 预编译的网站 DLL 来自之前的部署.由于预编译的 DLL 名称在不同版本之间发生变化,因此不会替换旧的 DLL 名称.不知何故,在同一目录中拥有 v2.0 和 v4.0 DLL 会混淆服务器.因为我的开发机器上没有这些旧的 DLL,所以我没有看到同样的问题.

There were v2.0 precompiled website DLLs still in the bin directory on the server from the previous deployment. As the precompiled DLL names change between releases the old ones were not replaced. Somehow having v2.0 and v4.0 DLLs in the same directory was confusing the server. As I didn't have these old DLLs on my development machine I was not seeing the same problems.

删除旧的 DLL 已解决问题.

Deleting the old DLLs has fixed the issue.

这篇关于我&amp;#39;m得到&amp;quot;&amp;#39;Eval&amp;#39;未声明.由于其保护级别,它可能无法访问"在一个 ascx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆