3

我正在处理 asp.net 4.0 web 项目,当我运行它时,我收到了错误消息

“myproject.MyClass”类型存在于“c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d76f4ecb\381a37f3\assembly\dl3\824d7fec\6a842c0e_ad7bce01\myproject.DLL”中和 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d76f4ecb\381a37f3\App_Code.lfoxsb3d.dll'

MyClass.cs 驻留在 App_Code 文件夹中我尝试清理 ASP.net 临时文件夹,清理解决方案,重置 IIS,但没有运气,我在这里找到了一个解决方案,所以我尝试重命名 App_Code,重命名后运行良好,但是当我登录到我的应用程序,它给出了异常

Unable to cast object of type 'ASP.masterpage_master' to type 'myproject.MasterPage'

在这条线上

((MasterPage)Master).PageSection = "Accountant";

我撤消了重命名 App_Code(因为它不能解决我的问题)如何修复这种类型存在错误?我正在使用 Telerik.Web.UI v4.0.30319

4

2 回答 2

1

This is occurring because your project is a "Web Application", when you Compile in Visual Studio, all the code in your site (including in App_Code) gets compiled into an assembly called, in this instance, MyProject.dll. When you run your site, asp.net knows about a "special" folder called App_Code and compiles the content of it into an assembly with a unique name, in this instance `App_Code.xxxxxxxxx.dll'.

One solution is to rename your App_Code folder to another name, such as BusinessLogic.

于 2016-05-17T05:35:09.523 回答
0

您还可以创建一个新文件夹并将所有 app_code 文件放在该文件夹中。

于 2018-07-21T19:35:06.127 回答