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

System.InvalidOperationException: 'This operation is not supported for a relative URI.' #2021

Closed
MenNoWar opened this issue Jun 25, 2021 · 1 comment

Comments

@MenNoWar
Copy link

Problem: Serializing an object which has not an absolute URI, just a relative.
Exception thrown: System.InvalidOperationException: 'This operation is not supported for a relative URI.'

Source of the Problem: LiteDB/Client/Mapper/BsonMapper.cs::128

Original:
RegisterType<Uri>(uri => uri.AbsoluteUri, bson => new Uri(bson.AsString));

correct Version should be:
RegisterType<Uri>(uri => uri.IsAbsoluteUri ? uri.AbsoluteUri : uri.ToString(), bson => new Uri(bson.AsString));

Workaround:
manually register the custom mapper like:
BsonMapper.Global.RegisterType<Uri>(uri => uri.IsAbsoluteUri ? uri.AbsoluteUri : uri.ToString(), bson => new Uri(bson.AsString));

@lbnascimento
Copy link
Collaborator

@MenNoWar Thank you. This issue has been fixed in the master and its fix will be present in the next incremental release.

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

2 participants