Using the following method:
public static T ToId<T>(string meetingId)
{
if (typeof(T) == typeof(Guid))
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)