title: AFNetworking and -[__NSCFBoolean length]: unrecognized selector sent to instance 0x1f54358
body: <p>I have some days now this strange problem <code>2014-03-24 16:50:56.097 MyApp[1610:4703] -[__NSCFBoolean length]: unrecognized selector sent to instance 0x1f54358</code>.</p>
  
  <p>I have debugging my library, which is a static library where I package as a .framework and distribute to developers.</p>
  
  <p>Debugging is little hard, in point of breakpoints, so I have added the static library .xcodeproj file to a sample client application and tried to work with it. After some research and trying to figure out where this is occur I have no other reason than believe that it's an AFNetworking problem!</p>
  
  <p>I have this code in my static library:</p>
  
  <p><strong>EDITED:</strong></p>
  
  <pre><code>// Selector parameter (NSData *)theData
  
      NSMutableURLRequest *aRequest = [[[NSMutableURLRequest alloc] initWithURL:theURL                                                                              cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f] autorelease];
  
              [aRequest setHTTPMethod:@"POST"];
              [aRequest setValue:key forHTTPHeaderField:@"Custom-Header"];
              [aRequest setValue:@"plain/text" forHTTPHeaderField:@"Content-Type"];
  
      NSMutableData *postData = [NSMutableData data];
              [postData appendData:theData];
              [aRequest setHTTPBody:postData];
  
      AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:aRequest];
  
                  [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
                      {
                      _pendingDispatchesCount --;
                      NSLog(@"%@, %ld", kServerRespondedMsg, (long)operation.response.statusCode);
                      BOOL statusCodeAcceptable = [[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)] containsIndex:[operation.response statusCode]];
                      dispatch_async(dispatch_get_main_queue(),
                          ^{
                              [delegate analyticsOperationCompleted:statusCodeAcceptable forData:analyticsData];
                          });
                      }
                  failure:^(AFHTTPRequestOperation *operation, NSError *error)
                      {
                      _pendingDispatchesCount --;
                      NSLog(@"%@, %ld", kServerRespondedMsg, (long)operation.response.statusCode);
                      dispatch_async(dispatch_get_main_queue(),
                          ^{
                              [delegate analyticsOperationCompleted:NO forData:analyticsData];
                          });
                      }];
  
                  [operation start];
  </code></pre>
  
  <p>If I just comment the <code>[operation start];</code> the sample client starts properly. If I let the operation to start I get the <code>2014-03-24 16:50:56.097 MyApp[1610:4703] -[__NSCFBoolean length]: unrecognized selector sent to instance</code>.</p>
  
  <p>Drives me crazy at the moment, because this error occurs only to one developer where he reported it and he actually created a sample that reproduces it.</p>
  
  <p><strong>EDIT:</strong>
  Found a way to get the stacktrace and it seems that this is not caused by my application:</p>
  
  <p>Backtrace:</p>
  
  <pre><code>0   CoreFoundation                      0x000000010201c495 __exceptionPreprocess + 165
      1   libobjc.A.dylib                     0x0000000101d7b99e objc_exception_throw + 43
      2   CoreFoundation                      0x00000001020ad65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
      3   CoreFoundation                      0x000000010200dd8d ___forwarding___ + 973
      4   CoreFoundation                      0x000000010200d938 _CF_forwarding_prep_0 + 120
      5   CoreFoundation                      0x000000010200e9d1 CFURLCreateStringByAddingPercentEscapes + 81
      6   CFNetwork                           0x0000000103fdf1ab _ZL13appendEscapedP10__CFStringPKS_ + 40
      7   CFNetwork                           0x0000000103fdef69 _ZL25initializeUserAgentStringv + 124
      8   libsystem_pthread.dylib             0x00000001026d58d6 __pthread_once_handler + 65
      9   libsystem_platform.dylib            0x00000001025e3156 _os_once + 73
      10  libsystem_pthread.dylib             0x00000001026d5875 pthread_once + 57
      11  CFNetwork                           0x0000000103fdeb23 cleanUpRequest + 105
      12  CFNetwork                           0x0000000103fde824 _ZN17HTTPNetConnection19prepareTransmissionEP17HTTPNetStreamInfoP17__CoreWriteStream + 1224
      13  CFNetwork                           0x0000000103fdda65 _ZN13NetConnection7enqueueEPvh + 539
      14  CFNetwork                           0x0000000103fdd7e4 _ZN17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 88
      15  CFNetwork                           0x000000010403c295 _ZThn120_N17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 13
      16  CFNetwork                           0x0000000103fbdfc2 _ZN14CoreStreamBase21_streamInterface_OpenEv + 80
      17  CFNetwork                           0x0000000103fdd057 _ZN12HTTPProtocol10openStreamEv + 255
      18  CFNetwork                           0x0000000104048c41 _ZN12HTTPProtocol26useNetConnectionForRequestEP13NetConnectionP15__CFHTTPMessageh + 1753
      19  CFNetwork                           0x0000000103fdc268 _ZN24HTTPConnectionCacheEntry28dispatchConnectionToProtocolEP13NetConnectionP12HTTPProtocolP18HTTPRequestMessageh + 276
      20  CFNetwork                           0x0000000103fdc027 _ZN24HTTPConnectionCacheEntry34notifyNextProtocolOfOpenConnectionEP13NetConnectionh + 301
      21  CFNetwork                           0x0000000103fd9230 _ZN24HTTPConnectionCacheEntry25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 650
      22  CFNetwork                           0x0000000103fd8bf0 _ZN19HTTPConnectionCache34_onqueue_enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 178
      23  CFNetwork                           0x000000010404e843 ___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 26
      24  CoreFoundation                      0x0000000101fc2f74 CFArrayApplyFunction + 68
      25  CFNetwork                           0x0000000103fd43e7 _ZN19RunloopBlockContext7performEv + 133
      26  CFNetwork                           0x0000000103fd4217 _ZN17MultiplexerSource7performEv + 247
      27  CFNetwork                           0x0000000103fd403a _ZN17MultiplexerSource8_performEPv + 72
      28  CoreFoundation                      0x0000000101fabd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      29  CoreFoundation                      0x0000000101fab5f2 __CFRunLoopDoSources0 + 242
      30  CoreFoundation                      0x0000000101fc746f __CFRunLoopRun + 767
      31  CoreFoundation                      0x0000000101fc6d83 CFRunLoopRunSpecific + 467
      32  Foundation                          0x000000010193089c +[NSURLConnection(Loader) _resourceLoadLoop:] + 348
      33  Foundation                          0x00000001019832df __NSThread__main__ + 1167
      34  libsystem_pthread.dylib             0x00000001026d4899 _pthread_body + 138
      35  libsystem_pthread.dylib             0x00000001026d472a _pthread_struct_init + 0
      36  libsystem_pthread.dylib             0x00000001026d8fc9 thread_start + 13
  </code></pre>
  
  <p><strong>EDITED:</strong>
  Link with the full PLCrashReporter crash report symbolicated. <a href="https://drive.google.com/file/d/0B_4YDWJioTI1c0hia25NSXFTWVk/edit?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B_4YDWJioTI1c0hia25NSXFTWVk/edit?usp=sharing</a></p>
  
  <p>Any help or thought appreciated, thanks in advance.</p>
  
  <p>Regards.</p>