ASP.Net错误:temp1.dll“和”temp2.​​dll&QUOT“式的'富'两者中的存在”; (PT 2) [英] ASP.Net error: “The type ‘foo’ exists in both ”temp1.dll“ and ”temp2.dll" (pt 2)

查看:232
本文介绍了ASP.Net错误:temp1.dll“和”temp2.​​dll&QUOT“式的'富'两者中的存在”; (PT 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方法:

我也感动ASHX和ASMX文件在同一时间,因为这。 WebService的/ WebHandler指令的class属性,指出在错误的命名空间。这个故事的寓意是,以确保您查看的标记所有 为* X 文件,你通过右键单击更改命名空间并选择查​​看标记。


我遇到了同样的问题在<一个href="http://stackoverflow.com/questions/371426/asp-net-error-the-type-foo-exists-in-both-temp1-dll-and-temp2-dll">this问题和此链接,但没有答案的固定我的问题。 (编辑:设置web.config中的批处理属性的作品,但是这是一个掩盖真相,而不是解决方案)

我遇到的问题是,我从根目录移动到子目录相同的Web应用程序项目中的用户控件。它用于正常工作之前,我把它。当我把它它开始给我的错误信息。

它说,类名在临时ASP.NET文件两个DLL文件存在。果然,当我打开反射器,它在两个dll。

如果我命名类和ASCX文件,一切工作正常。原名称的任何用途中的任何文件存在于我的整个应用程序。当我重命名文件,我打开了所有与反射在ASP.NET临时文件的DLL文件,而原来的类名不存在引用

那么,的这款虚引用来自我如何才能解决这个问题来了?

更新:我真的grepped为解决我的工作目录中的所有文件和我的临时目录中的老班名和删除包含其所有的文件。然后我重新命名回原来的,破碎的名字,我仍然得到错误。

  

在/应用程序中的服务器错误。   编译错误说明:   在编译过程中发生错误   维修本所需资源   请求。请检查以下   特定错误详细信息并修改   来源$ C ​​$ C正确。

     

编译器错误ssage:CS0433:类型   ASP.dashboard_badusercontrol_ascx   存在于两个C:\ Docunts和   设置\我\本地   设置\ TEMP \临时ASP.NET   文件\ ROOT \ 3c2b7e1f \ 2e8a7620 \ App_Web_badusercontrol.ascx.a57ad085.iljdmp1p.dll   和'c:\ Docunts和设置\我\本地   设置\ TEMP \临时ASP.NET   文件\ ROOT \ 3c2b7e1f \ 2e8a7620 \ App_Web_bhdqaimy.dll

     

源错误:

     

1098线:线1099:
  [System.Diagnostics.DebuggerNonUser codeAttribute()]   行1100:民营   全球:: ASP.dashboard_badusercontrol_ascx   @__ BuildControlMyBadUserControl(){   线1101:
  全球:: ASP.dashboard_badusercontrol_ascx   @__ctrl;行1102:

     

源文件:C:\ Docunts和   设置\我\本地   设置\ TEMP \临时ASP.NET   文件\ ROOT \ 3c2b7e1f \ 2e8a7620 \ App_Web_foo.aspx.a57ad085.1nw6dais.0.cs   行:1100


编辑: 好了,所以我做了什么工作,不工作的一些更多的测试。 比方说,原来的文件名是BadUserControl.ascx命名空间myNameSpace对象。

我移动的文件,以一个名为NewDirectory目录,并改变了命名空间MyNamespace.NewDirectory。有没有份BadUserControl.ascx的其他地方对我的硬盘。我双重检查我的TFS历史记录,以确保唯一的区别是增加了.NewDirectory来的标记和code隐藏文件的命名空间。

在这个命名空间中的其他两个用户控件命名为OtherUserControl和AnotherUserControl。

此情况将失败: 我有2个寄存器指令:

 &LT;%@注册的src =BadUserControl.ascx变量名=BadUserControl标签preFIX =UC1%&GT;
&LT;%@注册的src =OtherUserControl.ascx变量名=OtherUserControl标签preFIX =UC2%&GT;
 

这些情况下工作:

  1. 我把BadUserControl.ascx命名为是。 我在同一个命名空间的网页上1寄存器指令:

     &LT;%@注册的src =BadUserControl.ascx变量名=BadUserControl标签preFIX =UC1%&GT;
     

  2. 我改BadUserControl.ascx到GoodUserControl.ascx 我有2个寄存器指令:

     &LT;%@注册的src =GoodUserControl.ascx变量名=GoodUserControl标签preFIX =UC1%&GT;
    &LT;%@注册的src =OtherUserControl.ascx变量名=OtherUserControl标签preFIX =UC2%&GT;
     

  3. 不BadUserControl.ascx在所有2寄存器指令:

     &LT;%@注册的src =AnotherUserControl.ascx变量名=AnotherUserControl标签preFIX =UC1%&GT;
    &LT;%@注册的src =OtherUserControl.ascx变量名=OtherUserControl标签preFIX =UC2%&GT;
     

解决方案

更​​新:好吧,你发现,循环引用是错误的猜测,因为有可能导致类似行为的其他情况

说明问题的更普遍的方式是分批在运行时的工作中,可以掩盖问题,一个非常宽容的方式。基本上,我们试图一批一切都在一个文件夹中,但如果我们在编译批时得到一个编译错误,我们退回到单独的文件汇编。在许多情况下能正常工作,但有时,这可能会导致一个给定的网页越来越编了两次(类似我下面描述的是什么,但出于不同的原因)。

在另一方面,在严格的方式,在那里,如果配料失败了,它完全失败,并且不退回aspnet_compiler工作。这就是为什么在运行这个工具是一个伟大的方式来定位不同类型的问题(或潜在问题),可以远离明显的在运行时。我想我们没做好为此,传福音的这个工具:)

至于为什么重命名固定它的文件中,这可以通过将其改变这些文件的处理的顺序,这是有点任意引起的。这可能是因为,如果你将其重命名为别的东西,你会看到它再次发生。

坦率地说,回头看那种我希望我们做了这个批处理行为严格在运行时,要及早发现这些情况。我们选择了目前回落的设计的原因是为了避免失败只要有可能,但这想出了一个价格:什么是错的,这是一个痛苦抓住它:)


原来的答复: 总之,问题是,当配料打开(它是默认情况下),你应该避免目录级循环依赖。让我解释一下我的意思。

下面是一个例子。假设你有:

  • 在文件夹1:page.aspx和uc2.ascx
  • 在forder2:uc1.ascx

和说,page.aspx引用uc1.ascx(通过@Register指令),并uc1.ascx参考uc2.ascx。在文件级别,这是完全正常的,但在目录级,有一个循环依赖:文件夹1引用在FOLDER2的东西,它引用一些在文件夹1

为什么会出现这种问题,是因为有怎样配料工作原理:当您请求的页面时,它首先试图编译一切folder1中一起。但是,由于文件夹1 / page.aspx引用FOLDER2 / uc1.ascx,它需要编译FOLDER2才可以做文件夹1。但随后UC1使用UC2,这意味着它必须首先做到FOLDER1!在这一点上,ASP.NET检测情况,并试图做出最好的是通过自己编写uc2.asc。虽然这允许一些场景来工作,它也可能导致奇怪的事情,因为一些项目结束在两个组件编译。在这里,uc2.ascx将已编译本身并与文件夹1批次。

其实是有一个方法可以轻松地检测,如果你的网站有这样的文件夹级别的循环依赖。从VS控制台窗口,去你的网站和运行的根源:

  aspnet_compiler -v FOO -p。
 

如果您有文件夹级别的循环依赖,你会得到一些错误,如下所示:

  /foo/Sub/UC1.ascx(2):错误ASPPARSE:循环文件引用是不允许的。
 

便宜的方式,以避免这个问题是你已经知道:禁用配料。现在,至少你知道这是为什么工作的:)

但更好的事情做,如果你可以是为了避免文件夹级别循环依赖。如果你开始的每个文件夹的思想为'组件'产生的程序集,这实际上是有意义的,并且可以帮助你的网站的部分更加模块化。

是的,这也是公平的调用编译系统这是一个错误,或至少是限制。但是,一旦你意识到这一点,这也很容易避免的。

Solution:

I had also moved ashx and asmx files at the same time as this. The Class attribute of the WebService/WebHandler directives were pointed at the wrong namespace. The moral of the story is to make sure you view the markup for all as*x files you change the namespace for by right-clicking on them and choosing "View Markup".


I'm experiencing the same problem as in this question and this link, but none of the answers fixed my problem. (edit: Setting the web.config batch attribute works, but that's a coverup, not a solution)

The problem I'm having is with a User Control that I moved from the root directory to a subdirectory within the same Web Application project. It used to work fine before I moved it. When I moved it it started giving me the error message.

It's saying that the class name exists in two dll files in Temporary ASP.NET Files. Sure enough, when I open Reflector, it's in two dlls.

If I rename the class and ascx file, everything works fine. No usages of the original name exist within any of the files in my entire application. When I rename the file, I opened all of the dll files in Temporary ASP.NET Files with Reflector, and no references to the original class name exists.

So where's this phantom reference coming from how can I fix this?

Update: I literally grepped every file in my working directory for the solution and my temp directory for the old class name and deleted every file that contained it. I then renamed back to the original, broken name and I still get the error.

Server Error in '/' Application. 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 ssage: CS0433: The type 'ASP.dashboard_badusercontrol_ascx' exists in both 'c:\Docunts and Settings\me\Local Settings\Temp\Temporary ASP.NET Files\root\3c2b7e1f\2e8a7620\App_Web_badusercontrol.ascx.a57ad085.iljdmp1p.dll' and 'c:\Docunts and Settings\me\Local Settings\Temp\Temporary ASP.NET Files\root\3c2b7e1f\2e8a7620\App_Web_bhdqaimy.dll'

Source Error:

Line 1098: Line 1099:
[System.Diagnostics.DebuggerNonUserCodeAttribute()] Line 1100: private global::ASP.dashboard_badusercontrol_ascx @__BuildControlMyBadUserControl() { Line 1101:
global::ASP.dashboard_badusercontrol_ascx @__ctrl; Line 1102:

Source File: c:\Docunts and Settings\me\Local Settings\Temp\Temporary ASP.NET Files\root\3c2b7e1f\2e8a7620\App_Web_foo.aspx.a57ad085.1nw6dais.0.cs Line: 1100


Edit: Ok, so I did some more testing on what works and doesn't work. Let's say the original file name was "BadUserControl.ascx" in namespace "MyNamespace".

I moved the file to a directory called "NewDirectory" and changed the namespace to "MyNamespace.NewDirectory". There are no copies of "BadUserControl.ascx" anywhere else on my HDD. I double-checked my TFS history to ensure the ONLY difference is the addition of ".NewDirectory" to the namespace in the markup and code-behind files.

Inside of this namespace are two other user controls named "OtherUserControl" and "AnotherUserControl".

This situation fails: I have 2 Register directives:

<%@ Register src="BadUserControl.ascx" tagname="BadUserControl" tagprefix="uc1" %> 
<%@ Register src="OtherUserControl.ascx" tagname="OtherUserControl" tagprefix="uc2" %>

These situations work:

  1. I keep "BadUserControl.ascx" named as is. I have 1 Register directive on a page in the same namespace:

    <%@ Register src="BadUserControl.ascx" tagname="BadUserControl" tagprefix="uc1" %>
    

  2. I change "BadUserControl.ascx" to "GoodUserControl.ascx" I have 2 Register directives:

    <%@ Register src="GoodUserControl.ascx" tagname="GoodUserControl" tagprefix="uc1" %>
    <%@ Register src="OtherUserControl.ascx" tagname="OtherUserControl" tagprefix="uc2" %>
    

  3. 2 Register directives without BadUserControl.ascx at all:

    <%@ Register src="AnotherUserControl.ascx" tagname="AnotherUserControl" tagprefix="uc1" %>
    <%@ Register src="OtherUserControl.ascx" tagname="OtherUserControl" tagprefix="uc2" %>
    

解决方案

UPDATE: ok, as you found, the circular reference was the wrong guess, as there are other situation that may cause similar behavior.

The more general way to describe the problem is that batching at runtime works in a very permissive way which can mask problems. Basically, we try to batch everything in one folder, but if we get a compile error when compiling that batch, we fall back to individual file compilation. In many cases that works fine, but sometimes, this can lead to a given page getting compiled twice (similar to what I described below, but for a different reason).

On the other hand, aspnet_compiler works in a strict way, where if batching fails it fails altogether and does not fall back. That's why running this tool is a great way to locate various type of issues (or latent issues) that can be far from obvious at runtime. I guess we didn't do a good job evangelizing this tool for this purpose :)

As for why renaming the file fixed it, this may be caused by it changing the ordering in which files are processed, which is a bit arbitrary. It may be that if you rename it to something else, you'll see it happen again.

Frankly, looking back I kind of wish we had made this batching behavior strict at runtime, to catch those situations earlier. The reason we chose the current fall back design was to avoid failing whenever possible, but this came with a price: when something is wrong, it's a pain to catch it :)


ORIGINAL ANSWER: In short, the problem is that when batching is turned on (and it is by default), you should avoid having directory level circular dependencies. Let me explain what I mean by that.

Here is an example. Say you have:

  • In folder1: page.aspx and uc2.ascx
  • In forder2: uc1.ascx

And say that page.aspx references uc1.ascx (via a @register directive), and that uc1.ascx references uc2.ascx. At the file level, that’s perfectly fine, but at the directory level, there is a circular dependency: folder1 references something in folder2, which references something in folder1.

Why this is problematic has to do with how batching works: when you request the page, it first tries to compile everything in folder1 together. But since folder1/page.aspx references folder2/uc1.ascx, it needs to compile folder2 before it can do folder1. But then uc1 uses uc2, meaning it must first do folder1! At this point, ASP.NET detects the situation and tries to make the best of it by compiling uc2.asc by itself. While this allows some scenarios to work, it can also cause weird things because some items end up compiled in two assemblies. Here, uc2.ascx would be both compiled by itself and with the folder1 batch.

There is actually a way to easily detect if your site has such folder level circular dependencies. From a VS console window, go to the root of your site and run:

aspnet_compiler -v foo -p .

If you have folder level circular dependencies, you’ll get some errors that look like:

/foo/Sub/UC1.ascx(2): error ASPPARSE: Circular file references are not allowed.

The cheap way to avoid this issue is what you already know: disable batching. Now at least you know why that works :)

But the better thing to do if you can is to avoid the folder level circular dependencies. If you start thinking of each folders as a ‘component’ which produces an assembly, that actually makes sense, and can help make the pieces of your site more modular.

Yes, it’s also fair to call this a ‘bug’ in the compilation system, or at least a limitation. But once you’re aware of it, it’s fairly easy to avoid.

这篇关于ASP.Net错误:temp1.dll“和”temp2.​​dll&QUOT“式的'富'两者中的存在”; (PT 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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