为什么我需要重新编译一个页面时所使用的方法,通过它的变化? [英] Why do I need a recompiled page when a method used by it changes?

查看:94
本文介绍了为什么我需要重新编译一个页面时所使用的方法,通过它的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在App code文件夹中使用的方法在一个类的aspx页面, DoSomething的(INT []×)。我改变了函数定义使用一个IEnumerable,而不是一个数组: DoSomething的(IEnumerable的< INT> X)。接下来,我precompiled网站,使用允许的网站是更新,并公布了新的APP_ code.dll。现在,该页面的precompiled版本在运行时给出了一个服务器错误:未找到方法结果。
如果我还发布了网页生成的DLL,App_Web_ [页码]的.aspx。[随机] .dll文件,它的工作原理。所以会出现功能的签名嵌入在页面编译...不知何故?这是为什么,是有没有办法改变现有的code时,为了避免这个问题?结果
我讨厌更新,每当我改变code在我的通用类所有我的网页的DLL。

I have an aspx page that used a method in a class in the App Code folder, doSomething(int[] x). I changed the function definition to use an IEnumerable instead of an array: doSomething(IEnumerable<int> x). Next, I precompiled the web site, using "allow web site to be updatable", and published the new App_Code.dll. Now, the precompiled version of the page gives a Server error at runtime: "Method not found".
If I also publish the DLL generated for the page, "App_Web_[page].aspx.[random].dll", it works. So it appears the signature of the function is embedded in the compiled page somehow…? Why is this, and is there a way to avoid this problem when changing existing code?
I'd hate updating all my page DLLs whenever I change code in my common classes.

推荐答案

当一个页面编译它看起来在所有的方法签名,基本上锁定下来。如果更改方法的签名被称为,那么页面将不会直到它被重新编译能够找到它。

When a page is compiled it looks at all the method signatures and essentially locks them down. If you change the signature of a method being called, then the page will not be able to locate it until it is recompiled.

例如假设你有一个像

public class Dog {
  public void Walk(Int32 distance) {
    /// blah blah
  }
}

和你后面的页面code称之为:

and you call this in a page code behind:

protected void MyButtonClick(....) {
  Dog d = new Dog();
  d.Walk(3000);
}

在此编译了网页将期待着与一个Int32签名的走法。

When this compiles down the page will expect a walk method with an Int32 signature.

现在,让我们说我们在狗类变更的步行方法:

Now, let's say we change the walk method in the Dog class to:

public void Walk(Int16 distance) {
  // blah blah
}

(是的,愚蠢的变化,但它突出问题)。
此时页面将无法找到散步方法,该方法一个Int32参数等都将炸毁,因为它应该。

(yes, stupid change but it highlights the issue). At this point the page will not be able to locate a Walk method that takes an Int32 parameter and so will blow up as it should.

这看起来不错,只是部署一个程序集你认为你需要,但问题的事实是可能有任意数量的发生在code,所以这是一个严重的坏习惯的变化。

It may seem nice to just deploy the one assembly you think you need, but the fact of the matter is there could be any number of changes that occurred in the code so this is a seriously bad practice.

这是好得多,以确保整个项目是一致的。更大的网站不要花这么长时间来部署。

It is much better to make sure the entire project is consistent. Even larger websites don't take that long to deploy.

当然,我觉得用网站项目反正自己和不良做法。部署未编译code到服务器(确实不好的),VS搜索您的驱动器来更新项目引用,即使你已经明确告诉它要使用的组件(通常是意外,没好的),具有一个共同的APP_ code文件夹中的所有主要code(限制的),等等。我可以去和这里...

Of course,I think that using web site projects are bad practice in and of themselves anyway. Deploying uncompiled code to the server (really bad), VS searching your drive to update references in the project even when you have explicitly told it which assembly to use (usually unexpected, never good), having all the main code in a common app_code folder (limiting), etc. I could go on and on here...

这篇关于为什么我需要重新编译一个页面时所使用的方法,通过它的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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