WCF on iOS TypeInitializationException Error - wcf

I have a cross-platform forms app which runs the following WCF code in the PCL without issue, but on iOS it throws a TypeInitializationException error. Looking at the parameters being passed in, the queryDevices parameter is shown as "System.TypeInitializationException: The type initializer for 'System.Data.Services.Client.TypeSystem' threw an exception."
IR_context = new IdentityServices.identityrelationships_dbEntities(svcUri);
DataServiceQuery<IdentityServices.Device> queryDevices = (DataServiceQuery<IdentityServices.Device>)(from device in IR_context.Devices where device.MAC == DeviceID select device);
try
{
// Begin query execution, supplying a method to handle the response
// and the original query object to maintain state in the callback.
queryDevices.BeginExecute(OnDeviceQueryComplete, queryDevices);
}
How do I enable the initialization?

It appears that you need to set iOS Build Linker Behavior of the iOS project to "Off" in VS to enable the proper linking.

Related

React: Calling JS function after bridge has been destroyed --- How to find which function

I'm working on an update for our app. I've added a HeadlessTask and I've started seeing this warning in the console:
React: Calling JS function after bridge has been destroyed
How can I get the name of the function being executed?
From the error message I assume you're in java (react-native Android):
When you reload on react-native, what happens behind the scenes is that the react context is getting destroyed, and a new one is being created.
That error get's thrown whenever a react-native Native Module is trying to do work, by using the old react context (the one that was valid before the reload).
The last time I saw that error it also included an explanation as to which module tried to do work by using the old context. Typically it's the RCTDeviceEventEmitter module trying to send a message to javascript.
You'll have to open logcat on Android studio and read the full error message.
p.s: If you're using react-native-navigation in your project, (after you discover which module is the trouble maker by using the logcat), make sure to search on their issues as they are heavily using the native side of react-native android, and I've seen lot's of similar issues so far.
Never found a good solution to this until recently, so thought I'd put this here in case it helps someone else. I finally got around this error by doing the following:
public class RNMyNativeModule extends ReactContextBaseModule {
private ReactApplicationContext currentContext;
public RNMyNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
currentContext = reactContext;
}
public void myEmitFn(String emitMe) {
currentContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("RNMyNativeModuleEvent", emitMe);
}
}
Basically, in your module constructor, make sure you capture the currentContext in it's own variable, and just use that whenever you need it. Otherwise it gets overwritten and destroyed whenever a live reload happens, and getReactApplicationContext() is not actually giving you the current context.

Confusing Swift type annotations for React Native Promises

I'm playing around with React Native and attempting to write some native code that communicates over bluetooth. I'm confused by the type annotations that I need to use in order for it to work. Could someone please explain why I have to have the "resolver" and "rejecter" bits in the following two code snippets? Is there a way to write this without those unused parts?
My implementation, MyAsyncModule.swift:
#objc(MyAsyncModule)
class MyAsyncModule: NSObject {
#objc func echoAsync(
input: NSNumber,
resolver resolve: RCTPromiseResolveBlock,
rejecter reject: RCTPromiseRejectBlock
) -> Void {
resolve(input)
}
}
From my bridge file, MyAsyncModuleBridge.m
RCT_EXTERN_METHOD(echoAsync:
(nonnull NSNumber *)input
resolver:(RCTPromiseResolveBlock *)resolve
rejecter:(RCTPromiseRejectBlock *)reject
)
I am coming from scripting land so types are foreign to me, but it seems too weird that React Native refuses to identify my the echoAsync method unless both the implementation and the bridge include the resolver and rejecter bits...
The resolver and reject calls are needed to have the framework generate a "promise". A promise can be thought of as a placeholder for a value that will be made available in the future. The resolver is called when the native code is done doing its work and is ready to pass the results back to the JavaScript land. reject is used when the native side detects an error and is used to report that error from native to JavaScript land.
To get a bit deeper, when you're JavaScript calls a native function, it doesn't pause and wait for native to finish up like a normal function call. It instead just goes on executing the next line of code (notice how React-Native prevents you from setting a return value for your exported functions meaning they are explicitly making sure you don't try and wait for a return value).
So then how does native code ever report the results back to JavaScript? There are two options
callbacks (in native these have the type RCTResponseSenderBlock) when called, cause a JavaScript function to run with the passed arguments
promises (with the types RCTPromiseResolveBlock and RCTPromiseRejectBlock) which causes you success handler to run with the passed arguments when resolver is called or causes your error handler to run when reject is called.
As for async function you MUST use promises.
For more info on JavaScript promises checkout:
http://www.html5rocks.com/en/tutorials/es6/promises/
https://facebook.github.io/react-native/docs/native-modules-ios.html#promises

XPCService not getting launched from app

I am trying a simple sample app on XPCServices, in which I am following below steps:
Step 1: Created a sample project and added target - XPCServices with name - HelperProcess to it. When the target is created XCode automatically generates below files:
HelperProcessProtocol.h
HelperProcess.h
HelperProcess.m
main.m
Step 2: In main.m added a log statement within implementation of ServiceDelegate:
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
NSLog(#"Log which is never displayed :(");
// Configure the connection.
// First, set the interface that the exported object implements.
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
HelperProcess *exportedObject = [HelperProcess new];
newConnection.exportedObject = exportedObject;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
return YES;
}
Step 3: In AppDelegate added below code in applicationDidFinishLaunching:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
_connectionToService = [[NSXPCConnection alloc] initWithServiceName:#"HelperProcess"];
_connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
[_connectionToService resume];
}
Problem is -
When I launch the app, neither the log added in
listener:shouldAcceptNewConnection: is displayed nor the helper
process appears in Activity Monitor :(
Here is the code: XPCShootOut
Note: I am trying this on XCode 6.0
Is there any additional setup which I need to do to make it working? Please suggest.
-- Update --
I tried to refer this sample from apple: AppSandboxLoginItemXPCDemo
When I tried to run it on XCode 6, it displayed error message - 'No signing identity found'. Since I don't have registered mac developer account, in build settings for - iDecide and iDecideHelper I changed 'Code Signing Identity' as 'Don't Code Sign'.
I got a warning for each of the targets:
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
This time when I compiled the build, it worked as expected.
Now I tried to follow the steps specified in its ReadMe.txt file, specifically I performed these steps in my sample app:
Step 1: Updated - Main App Target -> Capabilities Tab
Turned on 'App Sandbox'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 2: Updated - Helper Target -> Capabilities Tab
Turned on 'App Sandbox'
Enabled 'Outgoing Connections (Client)'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 3: Updated - Helper Target -> General Tab -> Bundle Identifier, added 'XYZ' prefix to it.
On running the app in console it displayed these messages:
10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.
10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013 { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." } (handleMessage()/appleEventsD.cp #2072) client-reqs-q
Neither app performed its intended function nor it displayed the log message added in listener:shouldAcceptNewConnection: delegate.
I am clueless. Kindly suggest if I am missing any thing? Is it possible to get XPC service sample app working without a registered mac developer account?
I don't think you can launch XPC services without having them signed.
Even for testing and debugging the code sign build infrastructure needs to be setup.
I think the Mac developer certificate is free you don't need a paid account for that.

How to Debug NinjectWebCommon.cs?

We are trying to debug through ninjectwebcommon.cs to find the binding for a respository.
In VS 2012, I am putting a Debugpoint on the kernel.bind but it doesnot hit anytime. Can someone sugggest me how to debug this?
I have NInject Version v4.0.30319
The not-so-simple and (obviously) temporary solution for me was to create a background thread in NinjectWebCommon.RegisterServices with the configuration I was debugging:
var thread = new System.Threading.Thread(() =>
{
while (!System.Diagnostics.Debugger.IsAttached)
{
System.Threading.Thread.Sleep(100);
}
// custom code, including kernel.Bind<>() calls here
});
thread.IsBackground = true;
thread.Start();
The idea here is to keep the thread you've created from executing the debuggable code until the debugger is actually attached. Setting the IsBackground property is important, because this allows the rest of the RegisterServices method to complete, which in turn allows the application to start and allows the debugger to attach.
Ninject is open source. You can download the entire project from their Github page at https://github.com/ninject. From there you can point Visual Studio to those projects instead of using the compiled assemblies.
Another option would be to use http://symbolsource.org as a Symbol Server. But it looks like they only have Ninject 3.

Visual Studio MVC 4 Internet Template & OpenAuth Throws JS Errors

I am trying to get the standard Visual Studio 2012 MVC4 Internet template and oAuth to work but it won't!
So here are the simple steps to recreate.
Create new MVC4 Inernet Application
In Package Manager console execute: update-package
Un-comment OAuthWebSecurity.RegisterGoogleClient() in file AuthConfig.cs (I was under the impression that the Google oAuth does not need a key so un-commenting this line in the AuthConfig.cs file would enable it.)
F5 to run app
at this point I see the following error:
Error when entering login page:
Unhandled exception at line 115, column 5 in http://localhost:63180/Scripts/jquery.unobtrusive-ajax.js
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'live'
Click the login link on home page
Click the Google Button
at this point I get this error:
ProtocolException was unhandled by user code
No OpenID endpoint found
The cause of the error and the solution
The cause is that jquery-unobtrusive-ajax.js who is in charge of supporting the unobtrusive ajax in ASP.NET MVC using jQuery live method. But this method was deprecated in jQuery 1.7 and has been removed in 1.9.
This method allowed an event associated with any DOM element present or future.
The method to be used in place of live currently is the method on.
However the syntax is a bit different, since the method has more uses on jQuery.
$ ("form [data-ajax = true].") live ("submit", function (e) { ... }
modify the call to live with a call to on.
For on act like we happen to live on 3 parameters:
The event (like live, will "submit")
A selector (elements "children") is based selector which must always exist
The handler function (like live).
In this case our line looks like:
$ ("body"). on ("submit", "form [data-ajax = true]", function (e) { ... }
I moved the selector to the second parameter of on and have made you a basic selector "body" (not the most optimal, but well I'm sure there always).
The idea is that the last function is associated with all current and future elements of type form [data-ajax = true] that are within the selector base (body).
For all other calls to live (there are 3 more) make the same substitution that we be as follows:
$ ("body"). on ("click", "form [data-ajax = true]: submit", function (e) { ... }
$ ("body"). on ("click", "a [data-ajax = true]", function (e) { ... }
$ ("body"). on ("click", "form [data-ajax = true] input [type = image]", function (e) { ... }
And ready! With this we have recovered ajax functionality MVC unobtrusive and your application should work properly again!
translated from: http://geeks.ms/blogs/etomas/archive/2013/01/18/jquery-1-9-y-el-unobtrusive-ajax-de-asp-net-mvc.aspx
The unobtrusive library in NuGet has not been updated and does not work with jQuery 1.9.
See Unobtrusive Ajax stopped working after update jQuery to 1.9.0