mvvmcross app singleton lifecycle - mvvmcross

I have a service (Foreground, STICKY), and an activity (LaunchMode.SingleTask) in the same app.
There are 2 mvvmcross setup scenarios:
Service is started from boot, mvvmcross is initialized with the 'setup.EnsureInitialized' method
Service is started from the Activity, and mvvmcross is initialized the 'classic' way
Sometimes because of low memory pressure, or unexpected exception, my service is killed or dies.
I tap then on my launcher,
10-13 01:05:06.699 497 507 I ActivityManager: START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=LoneWorker.Client.Android.App/loneworker.client.android.app.TrialSplashScreen bnds=[240,223][360,379] u=0} from pid 11747
10-13 01:05:06.769 497 7269 I ActivityManager: Start proc LoneWorker.Client.Android.App for activity LoneWorker.Client.Android.App/loneworker.clientandroid.app.views.HomeView: pid=11980 uid=10081 gids={3003, 1015, 1023, 1028}
but then the splash screen doesn't appear like a normal app start, and the application fails right away.
10-13 01:05:07.959 11980 11980 I MonoDroid: UNHANDLED EXCEPTION:
10-13 01:05:07.969 11980 11980 I MonoDroid: System.NullReferenceException: Object reference not set to an instance of an object
10-13 01:05:07.969 11980 11980 I MonoDroid: at Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.Plugins.Messenger.IMvxMessenger> () <0x00038>
10-13 01:05:07.969 11980 11980 I MonoDroid: at LoneWorker.ClientAndroid.App.Views.HomeView..ctor () <0x0002f>
10-13 01:05:07.969 11980 11980 I MonoDroid: at (wrapper dynamic-method) object.ee0d83da-1657-4884-bf34-4fc266ad42f0 (intptr,object[]) <0x0003f>
10-13 01:05:07.969 11980 11980 I MonoDroid: at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x00283>
10-13 01:05:07.969 11980 11980 I MonoDroid: at (wrapper dynamic-method) object.2fd07179-5f93-420a-8653-1fbe1c8a2f2e (intptr,intptr,intptr,intptr,intptr,intptr) <0x0006b>
In the log I have just an exception because the messenger couldn't be resolved by the Mvx container.
=> It can't be resolved simply because the setup process doesn't start.
It behaves like the app was already initialized...
So does the previous app singleton from the previous crashed service is still up somewhere ?
Can I force the app to reinitialize ?
I'm a bit confused by this strange behavior...

The stack trace shows that your app is being created in a "new" process, but is being launched via HomeView.
Your code is then calling Mvx.Resolve within its constructor.
10-13 01:05:07.969 11980 11980 I MonoDroid: at Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.Plugins.Messenger.IMvxMessenger> () <0x00038>
10-13 01:05:07.969 11980 11980 I MonoDroid: at LoneWorker.ClientAndroid.App.Views.HomeView..ctor () <0x0002f>
The exception is then caused inside:
public static object Resolve(Type serviceType)
{
var ioc = MvxSingleton<IMvxIoCProvider>.Instance;
return ioc.Resolve(serviceType);
}
This will be because MvxSingleton<IMvxIoCProvider>.Instance is null (https://github.com/MvvmCross/MvvmCross/blob/3.2/CrossCore/Cirrious.CrossCore/Mvx.cs#L36)
Because of Android's lifecycle, MvvmCross doesn't check that Setup has been done during the construction of a view - but instead during the OnCreate method.
I'd suggest you move your code out of the View constructor and into OnCreate - somewhere after the base.OnCreate call.
Note, that in these situations - if you are running Setup on the UI thread during the activity/view creation, then the UI can appear to "pause" to users.

Related

Javascript error when executed under idm environment

I got very wired problem. Scripts work all fine but when I ran this under ForgeRock idm it get error. I am not sure what that error is.
100] Jun 14, 2020 5:18:24.214 PM org.forgerock.openidm.servlet.internal.ServletConnectionFactory$3 lambda$handleRequestWithLogging$8
WARNING: Resource exception: 500 Internal Server Error: "onCreate script encountered exception"
org.forgerock.json.resource.InternalServerErrorException: onCreate script encountered exception
at org.forgerock.openidm.managed.ManagedObjectSet.lambda$execScript$3(ManagedObjectSet.java:517)
at org.forgerock.openidm.metrics.MetricsCollector.time(MetricsCollector.java:51)
at org.forgerock.openidm.metrics.MetricsCollector.time(MetricsCollector.java:68)
at org.forgerock.openidm.managed.ManagedObjectSet.execScript(ManagedObjectSet.java:495)
at org.forgerock.openidm.managed.ManagedObjectSet.execScriptHook(ManagedObjectSet.java:474)
at org.forgerock.openidm.managed.ManagedObjectSet.createInstance(ManagedObjectSet.java:959)
at org.forgerock.json.resource.InterfaceCollectionHandler.handleCreate(InterfaceCollectionHandler.java:35)
at org.forgerock.json.resource.Router.handleCreate(Router.java:265)
at org.forgerock.openidm.managed.ManagedObjectService$ManagedObjectSetRequestHandler.handleCreate(ManagedObjectService.java:259)
at org.forgerock.json.resource.FilterChain$Cursor.handleCreate(FilterChain.java:65)
Caused by: javax.script.ScriptException: TypeError: Cannot call method "replace" of undefined
at org.forgerock.openidm.script.javascript.RhinoScriptEngine$3.newScriptException(RhinoScriptEngine.java:499)
at org.forgerock.openidm.script.javascript.RhinoScript.eval(RhinoScript.java:261)
at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.forgerock.openidm.script.registry.ScriptRegistryImpl$LibraryRecord.invoke(ScriptRegistryImpl.java:539)
at com.sun.proxy.$Proxy55.eval(Unknown Source)
at org.forgerock.openidm.script.registry.ScriptRegistryImpl$ScriptImpl.eval(ScriptRegistryImpl.java:814)
at org.forgerock.openidm.script.registry.ScriptRegistryImpl$ScriptImpl.eval(ScriptRegistryImpl.java:825)
at org.forgerock.openidm.managed.ManagedObjectSet.lambda$execScript$3(ManagedObjectSet.java:509)
... 150 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "replace" of undefined (file:/opt/openidm/script/generateSamAccountName.js#24)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3693)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3712)
at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3731)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2258)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2251)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41._c_replaceString_4(file:/opt/openidm/script/generateSamAccountName.js:24)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41.call(file:/opt/openidm/script/generateSamAccountName.js)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41._c_generateSamAccountName_5(file:/opt/openidm/script/generateSamAccountName.js:39)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41.call(file:/opt/openidm/script/generateSamAccountName.js)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41._c_anonymous_1(file:/opt/openidm/script/generateSamAccountName.js:6)
at org.mozilla.javascript.gen.file__opt_openidm_script_generateSamAccountName_js_41.call(file:/opt/openidm/script/generateSamAccountName.js)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
at org.mozilla.javascript.gen._1E59BF9390C34C7ACCB99E616798559AD7DDD85B_15._c_script_0(1E59BF9390C34C7ACCB99E616798559AD7DDD85B:2)
at org.mozilla.javascript.gen._1E59BF9390C34C7ACCB99E616798559AD7DDD85B_15.call(1E59BF9390C34C7ACCB99E616798559AD7DDD85B)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._1E59BF9390C34C7ACCB99E616798559AD7DDD85B_15.call(1E59BF9390C34C7ACCB99E616798559AD7DDD85B)
at org.mozilla.javascript.gen._1E59BF9390C34C7ACCB99E616798559AD7DDD85B_15.exec(1E59BF9390C34C7ACCB99E616798559AD7DDD85B)
at org.forgerock.openidm.script.javascript.RhinoScript.eval(RhinoScript.java:231)
Does any one know why I am not able to run this ?
function replaceString(string) {
string = string.replace("รถ", "oe");
return string;
}

System.AggregateException: One or more errors occurred on Xamarin

Help Guys,
I am new on using Xamarin Android. I am trying to connect a MySQL database to my app. It stops at the con.Open(); line and I am not really sure what is wrong.
string myConnectionString = "Server=db4free.net;Port=3306;Database=*******;Uid=*******;Pwd=*******";
MySqlConnection con = new MySqlConnection(myConnectionString);
if (con.State == ConnectionState.Closed)
{
con.Open(); //error here
}
I have already added the library
using System.Data;
using MySql.Data.MySqlClient;
I also imported the MySQLConnector Nugget package.
I im still on the connection part as I did not do anything yet.
Note that the credentials are correct as I was able to connect in the DB using a php page. Any Ideas?
Edit
got this error on my Catch()
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:100000f0:SSL routines:OPENSSL_internal:UNSUPPORTED_PROTOCOL
at /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/external/boringssl/ssl/handshake_client.c:808
at Mono.Btls.MonoBtlsContext.ProcessHandshake () [0x00038] in <5a97d41d36694fb19855c17429527b10>:0
at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus status) [0x0003e] in <5a97d41d36694fb19855c17429527b10>:0
at (wrapper remoting-invoke-with-check) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus)
at Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus status) [0x00006] in <5a97d41d36694fb19855c17429527b10>:0
at Mono.Net.Security.AsyncProtocolRequest+<ProcessOperation>d__24.MoveNext () [0x000ff] in <5a97d41d36694fb19855c17429527b10>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Mono.Net.Security.AsyncProtocolRequest+<StartOperation>d__23.MoveNext () [0x0008b] in <5a97d41d36694fb19855c17429527b10>:0
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Mono.Net.Security.MobileAuthenticatedStream+<ProcessAuthentication>d__47.MoveNext () [0x00254] in <5a97d41d36694fb19855c17429527b10>:0 }
base: {System.SystemException}

java.lang.AssertionError: Instance must be configured before use in VimeoSdl library

using this https://github.com/vimeo/vimeo-networking-java for vimeo video player.using compile
com.vimeo.networking:vimeo-networking:1.0.1
in build.gradle but still error
Getting error:
FATAL EXCEPTION: main
Process: com.sample.vimeosdkapplication, PID: 2113
java.lang.AssertionError: Instance must be configured before use
at com.vimeo.networking.VimeoClient.getInstance(VimeoClient.java:94)
at com.sample.vimeosdkapplication.MainActivity.<init>(MainActivity.java:28)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
07-22 16:56:57.000 2113-2120/com.sample.vimeosdkapplication W/art: Suspending all threads took: 10ms
You'll need to initialize the VimeoClient class. You can find out how to do it in this section of the README.
You'll need to build the builder with the options you want for the library and then call initialize.
Here is an example of a builder:
Configuration.Builder configBuilder =
new Configuration.Builder(clientId, clientSecret, SCOPE,
testAccountStore, new AndroidGsonDeserializer())
.setCacheDirectory(this.getCacheDir())
Then you statically call initialize here:
VimeoClient.initialize(<your builder here>);

ESB Mule Client staring with xml-properties fails

I use Mule 3.x
I have a code that tests MuleClient connectivity.
This test is ok and works proper way:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
But this tes is not ok - it fail with an connection exceptions:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
The 'mule-config-test.xml' is used in both tests, the path for this file is ok, i checked.
This is error message I have in the end:
Exception stack is:
1. Address already in use (java.net.BindException) java.net.PlainSocketImpl:-2 (null)
2. Failed to bind to uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.net.BindException: Address already in
use at java.net.PlainSocketImpl.socketBind(Native Method) at
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at
java.net.ServerSocket.bind(ServerSocket.java:328)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
[10-05 16:33:37] ERROR HttpConnector [main]:
org.mule.transport.ConnectException: Failed to bind to uri
"http://127.0.0.1:8080/hello" [10-05 16:33:37] ERROR ConnectNotifier
[main]: Failed to connect/reconnect: HttpConnector {
name=connector.http.mule.default lifecycle=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=false
supportedProtocols=[http] serviceOverrides= } . Root Exception
was: Address already in use. Type: class java.net.BindException [10-05
16:33:37] ERROR DefaultSystemExceptionStrategy [main]: Failed to bind
to uri "http://127.0.0.1:8080/hello"
org.mule.api.lifecycle.LifecycleException: Cannot process event as
"connector.http.mule.default" is stopped
I think the problem is in what you're not showing: testHello_with_Spring() is probably executing while Mule is already running. The second Mule you're starting in it then port-conflicts with the other one.
Are testHello() and testHello_with_Spring() in the same test suite? If yes, seeing that testHello() relies on an already running Mule, I'd say that would be the cause of port conflict for testHello_with_Spring().

Get FileNotFoundException error when call a ActiveX in SSIS script task

I need call a ActiveX in my SSIS package, so I use script task and write the following C# script:
public void Main()
{
clsAptFdbReader objFdbReader = new clsAptFdbReader("UnitedStates20000830.fdb");
objFdbReader.OpenFdb(false);
Dts.TaskResult = (int)ScriptResults.Success;
}
Get a error:
Error:
System.Reflection.TargetInvocationException:
Exception has been thrown by the
target of an invocation. --->
System.IO.FileNotFoundException: Could
not load file or assembly
'Interop.APTFDBReader,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its
dependencies. The system cannot find
the file specified. File name:
'Interop.APTFDBReader,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' at
ST_320325ad8e2543f09ee688d809f58ee7.csproj.ScriptMain.Main()
=== Pre-bind state information === LOG: User = SHINETECHCHINA\xugy LOG:
DisplayName = Interop.APTFDBReader,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///C:/Program
Files/Microsoft SQL
Server/100/DTS/binn/ LOG: Initial
PrivatePath = NULL Calling assembly :
(Unknown).
=== LOG: This bind starts in default load context. LOG: Using application
configuration file: C:\Program
Files\Microsoft SQL
Server\100\DTS\binn\DtsDebugHost.exe.Config
LOG: Using machine configuration file
from
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to
reference at this time (private,
custom, partial, or location-based
assembly bind). LOG: Attempting
download of new URL file:///C:/Program
Files/Microsoft SQL
Server/100/DTS/binn/Interop.APTFDBReader.DLL.
LOG: Attempting download of new URL
file:///C:/Program Files/Microsoft SQL
Server/100/DTS/binn/Interop.APTFDBReader/Interop.APTFDBReader.DLL.
LOG: Attempting download of new URL
file:///C:/Program Files/Microsoft SQL
Server/100/DTS/binn/Interop.APTFDBReader.EXE.
LOG: Attempting download of new URL
file:///C:/Program Files/Microsoft SQL
Server/100/DTS/binn/Interop.APTFDBReader/Interop.APTFDBReader.EXE.
--- End of inner exception stack
trace --- at
System.RuntimeMethodHandle._InvokeMethodFast(Object
target, Object[] arguments,
SignatureStruct& sig, MethodAttributes
methodAttributes, RuntimeTypeHandle
typeOwner) at
System.RuntimeMethodHandle.InvokeMethodFast(Object
target, Object[] arguments, Signature
sig, MethodAttributes
methodAttributes, RuntimeTypeHandle
typeOwner) at
System.Reflection.RuntimeMethodInfo.Invoke(Object
obj, BindingFlags invokeAttr, Binder
binder, Object[] parameters,
CultureInfo culture, Boolean
skipVisibilityChecks) at
System.Reflection.RuntimeMethodInfo.Invoke(Object
obj, BindingFlags invokeAttr, Binder
binder, Object[] parameters,
CultureInfo culture) at
System.RuntimeType.InvokeMember(String
name, BindingFlags bindingFlags,
Binder binder, Object target, Object[]
providedArgs, ParameterModifier[]
modifiers, CultureInfo culture,
String[] namedParams) at
System.Type.InvokeMember(String name,
BindingFlags invokeAttr, Binder
binder, Object target, Object[] args,
CultureInfo culture) at
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
You can generate the interop as part of your build using TLBIMP.EXE, and give it arguments to build a strong name.
I'm not sure if it's wise to install that interop into the GAC, though, if it's based on a third-party COM server?