这是我网站上的错误。在Visual Studio中没有错误,它编译得很好。当我在本地运行网站并点击按钮在Chrome或任何其他浏览器中显示区域时,会发生这种情况。我完全被这个难住了,我正在寻找任何帮助?不胜感激。无效投射例外 - 投射无效
System.InvalidCastException: Specified cast is not valid.
at MySite.Web.Areas.Mpa.Controllers.ZonesController.d__7.MoveNext() in C:\MySite\Development\routing_branch\src\MySite.Web\Areas\Mpa\Controllers\ZonesController.cs:line 125
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()
这是我打电话的方法,显示行125:
93 public async Task<PartialViewResult> MapViewModal()
94 {
95 int? impersonatorTenantId;
96 int value;
97 object obj;
98 IZoneAppService zoneAppService = this._zoneAppService;
99 if (this.AbpSession.ImpersonatorTenantId.HasValue)
100 {
101 impersonatorTenantId = this.AbpSession.ImpersonatorTenantId;
102 value = impersonatorTenantId.Value;
103 }
104 else
105 {
106 impersonatorTenantId = this.AbpSession.TenantId;
107 value = impersonatorTenantId.Value;
108 }
109 List<ZoneListDto> zonesByTenantId = await zoneAppService.GetZonesByTenantId(value, true);
110 if (zonesByTenantId == null || zonesByTenantId != null && zonesByTenantId.Count == 0)
111 {
112 zonesByTenantId = new List<ZoneListDto>();
113 }
114 ITenantSettingsAppService tenantSettingsAppService = this._tenantsettingsAppService;
115 if (this.AbpSession.ImpersonatorTenantId.HasValue)
116 {
117 impersonatorTenantId = this.AbpSession.ImpersonatorTenantId;
118 obj = impersonatorTenantId.Value;
119 }
120 else
121 {
122 impersonatorTenantId = this.AbpSession.TenantId;
123 obj = impersonatorTenantId.Value;
124 }
125 string tenantCoordinates = await tenantSettingsAppService.GetTenantCoordinates((long)obj);
126 ZonesMapView zonesMapView = new ZonesMapView()
127 {
128 Zones = zonesByTenantId,
129 TenantCoordinates = tenantCoordinates
130 };
131 return this.PartialView("_MapViewModal", zonesMapView);
132 }
我的表布局是这样的:
dbo.MySiteZones
Columns:
Id (PK, bigint, not null)
TenantId (int, not null)
Name (nvarchar(255), not null)
Caption (nvarchar(600), null)
IsActive (bit, not null)
IsDeleted (bit, not null)
DeleterUserId (bigint, null)
DeletionTime (datetime, null)
LastModificationTime (datetime, null)
LastModifierUserId (bigint, null)
CreationTime (datetime, not null)
CreatorUserId (bigint, null)
PolygonCoordinates (nvarchar(max), null)
HexColor (nvarchar(12), null)
PolygonCoordinatesReversed (nvarchar(max), null)
没有'Convert.ToLong()' - 你可能是指'Convert.ToInt64()' - https://msdn.microsoft.com/en-us/library/0c5w856c(v=vs.110)。 aspx – Jonno
你是对的......现在真的太晚了;)thx。更新 –
非常感谢!那完全是它。我有一些其他代码依赖于名称,所以(Convert.ToInt64(obj));是答案!再次感谢! – zberg007