question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.FormatException: The format of value '' is invalid.

See original GitHub issue

Hello there!

I’m trying to make a request like this

#r "nuget: FsHttp"

open FsHttp

http {
    POST "https://api.jspm.io/generate"
    body
    json ("""{
    "install": [ "lodash" ],
    "env": [ "browser", "module" ],
    "graph":true,
    "provider": "jspm"}""")
}
|> Request.send
|> Response.toText
|> printfn "%s"

the expected JSON content is the following

{
  "staticDeps": [
    "https://ga.jspm.io/npm:lodash@4.17.21/lodash.js"
  ],
  "dynamicDeps": [],
  "map": {
    "imports": {
      "lodash": "https://ga.jspm.io/npm:lodash@4.17.21/lodash.js"
    }
  },
  "graph": {
    "https://ga.jspm.io/npm:lodash@4.17.21/": {
      "lodash.js": {}
    }
  }
}

but I get the following instead

PS C:\Users\scyth\repos\scripts> dotnet fsi script2.fsx
System.FormatException: The format of value '' is invalid.
   at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
   at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
   at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
   at FsHttp.Request.toAsync@152-4.Invoke(CancellationToken ctok)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528    
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
   at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1140
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1511
   at <StartupCode$FSI_0002>.$FSI_0002.main@() in C:\Users\scyth\repos\scripts\script2.fsx:line 6
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error

When I use nightingale I get this log, not sure if it helps at all

Method: POST, RequestUri: 'https://api.jspm.io/generate', Version: 2.0, Content: System.Net.Http.StringContent, Headers:
{
  Content-Type: application/json; charset=utf-8
}

StatusCode: 200, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
  Server: Google
  Server: Frontend
  Date: Fri, 30 Sep 2022 00:16:50 GMT
  Access-Control-Allow-Origin: *
  Content-Type: application/json
}

Let me know if you need further information

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Samuel-Dufourcommented, Oct 21, 2022

Hi, I added a PR that should fix this issue.

0reactions
CaptnCodrcommented, Nov 23, 2022

Yep, me too. 😄 This fix helped a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding HttpClient headers generates a FormatException ...
System.FormatException : The format of value key=XXX' is invalid. The solution is to remove the equals sign. Digging into reflector ...
Read more >
Adding HttpClient headers generates a FormatException ...
System.FormatException : The format of value key=XXX' is invalid. The solution is to remove the equals sign. Digging into reflector ...
Read more >
FormatException Class (System)
The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed....
Read more >
[Solved] Httpclient authorization issue
Why HttpClient rejects that exact value with a FormatException, is because it is an invalid Authorization value: valid Authorization values ...
Read more >
The format of value xxx is invalid · Issue #5046
I get the following exception when I run the code (I use Mac): The format of value ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found