如何查看在C#中引发InvalidCastException的类型?

时间:2009-08-04 19:11:05

标签: c# .net linq-to-sql exception

在我的LINQ-to-SQL DAL中,我收到“指定的转换无效”。

这是确切的错误:

System.InvalidCastException was unhandled by user code   Message="Specified cast is not valid." Source="System.Data.Linq"   StackTrace:
   at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager`2.TryCreateKeyFromValues(Object[] values, V& v)
   at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
   at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
   at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
   at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
   at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
   at System.Data.Linq.DataContext.SubmitChanges()
   at DomainModel.Repository.Concrete.SqlClientRepository.InsertClientByUsername(String username, Client clientInfo) in C:\Documents and Settings\Owner\Desktop\CollectionTree v1.1\DomainModel\Repository\Concrete\SqlClientRepository.cs:line 99
   at WebUI.Secure.Controllers.ClientAdminController.EditProfile(Client clientProfile) in C:\Documents and Settings\Owner\Desktop\CollectionTree v1.1\WebUI.Secure\Controllers\ClientAdminController.cs:line 69
   at lambda_method(ExecutionScope , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)   InnerException:

它发生在我的db.SubmitChanges()。

无论如何,在这个例外情况下,哪些类型的播放有问题?如果我知道它遇到什么具体类型,它将有助于缩小范围。我可以将鼠标悬停在Visual Studio中的异常上,但我不知道要查看哪些属性。

2 个答案:

答案 0 :(得分:1)

我偶尔通过COM互操作获得InvalidCastException并且......我是SOL?似乎纯IL中的InvalidCastException获取类型信息,但是当它在interop包装器转换中处理时,它会跳过该部分。我在COM包装器中猜测问题是因为E_NOINTERFACE的HRESULT不包含有关所涉及类型的信息,并且包装器无法返回并查看前一项{{1}正在寻找。即使它确实如此,它也必须去寻找Guid,并希望这种类型的互操作包装能够从中获取有意义的信息。

如果LINQ-to-SQL在幕后使用COM互操作,那就是你的答案。 :)

答案 1 :(得分:1)

你是SOL,至少对于.NET&lt; 4.0。我输入了一个Connect错误报告(“InvalidCastException Should Display or Contain More Detail”),他们说这是固定的。

我还没有看到修复。