Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-702

Stack trace when casting

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.8
    • Affects Version/s: 1.7.1
    • Component/s: None
    • Environment:
      Windows 7 64bit, .NET 4.0

      Using the following method:

      public static T ToId<T>(string meetingId)
      {
      if (typeof(T) == typeof(Guid))

      { Guid guidId; Guid.TryParse(meetingId, out guidId); return (T)Convert.ChangeType(guidId, typeof(T)); }

      else if (typeof(T) == typeof(ObjectId))

      { ObjectId objectId; ObjectId.TryParse(meetingId, out objectId); return (T)Convert.ChangeType(objectId, typeof(T)); }

      return default(T);
      }

      When upgrading from the MongoDb .NET driver 1.5 to version 1.7.1.4791, we're receiving the following stack trace:

      Message: Specified cast is not valid.

      Stack Trace:
      at MongoDB.Bson.ObjectId.System.IConvertible.ToType(Type conversionType, IFormatProvider provider)
      at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
      at System.Convert.ChangeType(Object value, Type conversionType)
      at Tntp.Controls.ViewModels.Meeting.MeetingBaseViewModel.ToId[T](String meetingId) in C:\Dev\Tntp.TeacherTrack2\Tntp.Controls\ViewModels\Meeting\MeetingBaseViewModel.cs:line 72
      at Tntp.Controls.ViewModels.Meeting.MeetingViewModel.GetMeetings(MeetingTypes meetingTypes, String meetingParentId) in C:\Dev\Tntp.TeacherTrack2\Tntp.Controls\ViewModels\Meeting\MeetingSessionViewModel.cs:line 28
      at Tntp.Web.Admin.UserControls.Meetings.MeetingDetails.Page_Load(Object sender, EventArgs e) in C:\Dev\Tntp.TeacherTrack2\Tntp.Web\Admin\UserControls\Meetings\MeetingDetails.ascx.cs:line 34
      at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
      at System.Web.UI.Control.OnLoad(EventArgs e)
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            icenine Robert DeSimone
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: