[CSHARP-702] Stack trace when casting Created: 13/Mar/13 Updated: 05/Apr/19 Resolved: 13/Mar/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.7.1 |
| Fix Version/s: | 1.8 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Robert DeSimone | Assignee: | Craig Wilson |
| Resolution: | Done | Votes: | 2 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 64bit, .NET 4.0 |
||
| Description |
|
Using the following method: public static T ToId<T>(string meetingId) 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: |
| Comments |
| Comment by auto [ 13/Mar/13 ] | ||||||
|
Author: {u'date': u'2013-03-13T16:27:14Z', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}Message: | ||||||
| Comment by Robert DeSimone [ 13/Mar/13 ] | ||||||
|
Thanks Craig. That seemed to do the trick! Nice response time! | ||||||
| Comment by Craig Wilson [ 13/Mar/13 ] | ||||||
|
Fix in code review. | ||||||
| Comment by Craig Wilson [ 13/Mar/13 ] | ||||||
|
I can confirm this. In the meantime, you can change your code in the ObjectId portion to this:
|