繁体   English   中英

自升级到Visual Studio 2013以来的投射错误

[英]Casting Errors Since Upgrade to Visual Studio 2013

自从升级到Visual Studio 2013以来,我一直在投射一些错误。当我说“升级”时,我的意思是说最初该项目是在Visual Studio 2010中构建和维护的。现在在VS2013中进行处理时,出现了我不理解的转换错误。

我得到了两个,特别是其中一个我坚持。

第一个,我不太担心

Server Error in '/' Application.

Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'System.Security.Principal.WindowsPrincipal'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'System.Security.Principal.WindowsPrincipal'.

Source Error: 
Line 21:     {
Line 22:      // omitted
Line 23:         WindowsPrincipal temp2 = (WindowsPrincipal)WindowsPrincipal.Current.Identity;
Line 24:         //HttpContext temp = (HttpContext)HttpContext.Current.User.Identity;
Line 25:         CustomClass spindle = (CustomClass)HttpContext.Current.User.Identity;

 Source File:  C:\My Projects\New Project\Default.aspx.cs    Line:  23 

Stack Trace: 

[InvalidCastException: Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'System.Security.Principal.WindowsPrincipal'.]
   _Default.Page_Load(Object sender, EventArgs e) in C:\My Projects\New Project\Default.aspx.cs:23
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237 

我关注的第二个

我在另一个演员表中遇到相同的错误问题,但是这种情况更加具体。 我正在using使用SystemSystem.CollectionsSystem.Collections.GenericSystem.Security.Principal的内部类。 该类继承并实现了MarshalByRefObjectIIdentity

当我创建自定义类的实例并尝试为其分配值HttpContext.Current.User.Identity我得到与上面相同的转换错误。 这是代码。

CustomClass temp = (CustomClass)HttpContext.Current.User.Identity;

string FullName = temp.LastName + ", " + temp.FirstName;
Namelbl.Text = FullName;

就像我之前解释的那样,当我在Visual Studio 2010中使用该项目时,我没有遇到任何此类问题。将项目迁移到供我们在Visual Studio 2013中使用的这些错误开始出现。 老实说,如果我在Visual Studio 2012中打开相同的项目,则不会收到错误消息。

打开项目,构建项目,右键单击文件并在浏览器中选择视图时,出现错误。 这是一个带有C#代码隐藏的Web项目。 我在web.cofig文件中尝试了十几种不同的解决方案,这些解决方案也无法正常运行。

堆栈跟踪对我来说也有点陌生,因此,如果有人可以破译它并提供一种出色的解决方案。

编辑

我想我可能已经找到了解决方案,但是我不知道我是否在正确地解决问题。 我发现在“引用”选项卡下的“属性页”(单击项目并单击Shift + F4)内,所有CustomClass的引用都被版本化为“自动更新”。 如果您单击一个类文件,然后单击“更新”按钮,则会在旧位置向引用该文件的文件显示错误。

如果我从“属性”页中删除引用,则它将dll从项目中的Bin文件夹中删除。 因此,我删除了在其版本列中具有“自动更新”的参考。 将dll从旧的项目位置(但不是太旧)复制到项目的Bin文件夹中。 然后使用正确的文件夹路径将它们添加回去,但这似乎也不起作用。 我没有正确添加参考吗?

编辑

我现在认为引用的链接失败。 当我尝试查看在Visual Studio 2013中使用Microsoft.ReportViewer.WebForms创建的报表时,出现了错误。 尽管引用了GAC,但似乎仍然找不到它。 我得到的错误是

Parser Error Message: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

这似乎非常类似于

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'CustomClass'.

也许它不能将其强制转换为CustomClass,因为它不知道它在哪里/在哪里!

我的自定义类的更新解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM