Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'LiteDB.ObjectId' to type 'System.String' #68

Open
weloytty opened this issue Sep 25, 2018 · 3 comments
Open

Comments

@weloytty
Copy link

after a day or so of using ZLocation, I start to get this error:

C:\Users\whatever\AppData\Roaming\Local\tempz auto                                                                    
Exception calling "ToObject" with "2" argument(s): "Unable to cast object of type 'LiteDB.ObjectId' to type 'System.String'."     
At C:\Program Files\PowerShell\Modules\ZLocation\1.0.0\ZLocation.LiteDB.psm1:15 char:5                                            
+     ,$mapper.ToObject($type, $obj)                                                                                              
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                              
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException                                                         
+ FullyQualifiedErrorId : InvalidCastException     

When I go and look at z-location.db, I see, along with the normal entries, an entry like this:

[
{
"_id": {"$oid": "5ba9f338cfbf5e28a8f1314c"},
"weight": 1.0
}
]

If I remove that from the db, things work again. (Until a day or so later when I get the error again)

@vors
Copy link
Owner

vors commented Sep 25, 2018

@cspotcode do you know where that may come from?

@cspotcode
Copy link
Contributor

@vors, no I'm not sure, except it seems like somewhere we're accidentally putting a nonsense entry into the database. Maybe we're passing an incomplete object to the $mapper somewhere? Like, what happens if we accidentally try to increase the weight for a path when no such path entry exists in the database? Just a guess.

@cspotcode
Copy link
Contributor

cspotcode commented Sep 25, 2018

Now that I think about it for a few more minutes, I suspect that's the problem. I suspect that somewhere we're calling Add-ZWeight or $service.add() with a null $path. We have the Location class's path field mapped as LiteDB's _id. (LiteDB makes _id mandatory; otherwise I would have named it path within the database) So if $path/_id is unspecified, the database will auto-create an ID for that row, except the auto-created IDs aren't strings. Later, we try to map that row to a [Location] instance, and it fails because it can't convert the _id to Location's path field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants