Hi, I am using ktor client on iOS and trying to mo...
# ktor
a
Hi, I am using ktor client on iOS and trying to move API requests to background thread, but get this error:
Copy code
Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
        kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87
        kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
        kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
        kfun:kotlin.native.IncorrectDereferenceException.<init>(kotlin.String)kotlin.native.IncorrectDereferenceException + 85
        ThrowIncorrectDereferenceException + 137
        CheckIsMainThread + 25
        kfun:io.ktor.http.<get-URL_ALPHABET_CHARS>#internal + 35
        kfun:io.ktor.http.encodeURLPath@kotlin.String.()kotlin.String + 717
        kfun:io.ktor.http.takeFromUnsafe$ktor-http@io.ktor.http.URLBuilder.(kotlin.String)io.ktor.http.URLBuilder + 2278
        kfun:io.ktor.http.takeFrom@io.ktor.http.URLBuilder.(kotlin.String)io.ktor.http.URLBuilder + 263
My code is
Copy code
...
withContext(workerDispatcher){
    val loginResponse = <http://client.post|client.post><LoginNetworkResponse>("$apiEndpoint/init/auth?v=1") {
            contentType(ContentType.Application.Json)
            body = LoginNetworkRequest(
                ...
            )
        }
   ....
}
c
This is bug. No workaround.
a
Has it been raised anywhere for tracking?
c
Yes, we aware of it: we have tons of top-level vals that don’t work with K/N. Need to cleanup them somehow.
a
Do you have a target release or date for it yet?
c
I hope 1.3.0
đź‘Ť 1
1.3.0-rc still doesn’t work
a
No it doesn't, I updated to RC today