0

I found a few answers on StackOverflow about C# URI validator. But can somebody explain me where I'm wrong? There are a few examples on Wikipedia and one is special. I'm not able in C# to make this valid:

ldap://[2001:db8::7]/c=GB?objectClass?one

It's invalid with this method Uri.IsWellFormedUriString("ldap://[2001:db8::7]/c=GB?objectClass?one", UriKind.RelativeOrAbsolute);

Who is wrong? C# or Wikipedia?

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
ms_devel
  • 502
  • 1
  • 10
  • 27

1 Answers1

1

you are wrong!

if I test it, I get

string _uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
Uri.IsWellFormedUriString(_uri, UriKind.RelativeOrAbsolute) == True;

try it: https://dotnetfiddle.net/H4k8fH

Falco Alexander
  • 3,092
  • 2
  • 20
  • 39
  • Hmm, i see. But something is wrong. I don't know what. Look at this https://i.imgur.com/WRJx780.png now i'm able make that valid in dotnetfiddle. But in my code is still unvalid and another screenshot with watch : https://i.imgur.com/ZRuyQDS.png – ms_devel Feb 26 '20 at 15:09
  • then your string is probably somehow different. can you double check? – Falco Alexander Feb 26 '20 at 15:12
  • yes, triple checked. I really don't understand whats going on.When i put that code into single solution without any other code. it's valid. But in that old solution is unvalid. I really don't understand. But thank you for that check in dotnetfiddle.I will try to figure out where the problem is and I will put answer here after that. But this is super weird. – ms_devel Feb 26 '20 at 15:15
  • what is the source of the string that contains the URI you're testing? it's somehow different when you check equality with the code snipped? – Falco Alexander Feb 26 '20 at 15:29
  • I added same code from dotnetfiddler into my solution. And look at this. It was only copied. https://i.imgur.com/mDcXywO.png – ms_devel Feb 26 '20 at 15:34
  • Ok, so, this is related. My project is silverlight and it's bug. https://stackoverflow.com/questions/6977325/bug-in-wp-7-implementation-of-uri-iswellformeduristring – ms_devel Feb 26 '20 at 15:39
  • this is a crazy find. can you use a different Uri Class or replace it by an regex? https://stackoverflow.com/questions/30847/regex-to-validate-uris – Falco Alexander Feb 26 '20 at 15:44
  • 1
    Yes, i will implement that regex method. It is really crazy :D regex will help :D Thank you – ms_devel Feb 26 '20 at 15:48