Base solution for your next web application
Open Closed

Xamarin app fail on startup #5305


User avatar
0
Ricavir created

Hi,

I'm currently developing a basic Xamarin application (based on v5.1 template). Everything was working well.

I don't know why but know, my app fails when slash screen is displayed : the problem occurs at App.xaml.cs on InitializeComponent() method. Exception is "Specified cast is not valid". Do you know why a cast would be not valid ?

The stack trace is :

System.InvalidCastException: Specified cast is not valid. at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr) at Xamarin.Forms.OnPlatform1[T].op_Implicit (Xamarin.Forms.OnPlatform1[T] onPlatform) [0x00036] in D:\agent_work\2\s\Xamarin.Forms.Core\OnPlatform.cs:71 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f32579baafc1404fa37ba3ec1abdc0bd>:0

I came back to previous GIT commits, but still same issue...


8 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    close Visual Studio. delete all BIN & OBJ folders . test again with your previous working.

  • User Avatar
    0
    Ricavir created

    Thank you Alper .

    I've been trying to fix this issue from a while now. I have removed all bin and obj folders, cleaned up the solution and tested several times. I have upgraded my VS tooling I also tried from an other computer and I have same issue.

    The problem cames from my current project only ! because I tried from a fresh aspnetzero template and everything works.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @Ricavir could you create a new database from scratch (using migrations) for your existing app and try again ?

  • User Avatar
    0
    Ricavir created

    @ismcagdas : hi tried with a new fresh database using migrations. I still have same issue.

    If server side is not running, then I have a popup saying that No Internet connection to server is existing. Normal behavior. But when starting server side, App is stopped with following System.InvalidCastException


    07-01 08:42:42.962 D/Mono ( 6880): Found as 'java_interop_jnienv_throw'. An unhandled exception occured.

    [0:] * Unhandled Exception *: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr) at Xamarin.Forms.OnPlatform1[T].op_Implicit (Xamarin.Forms.OnPlatform1[T] onPlatform) [0x00036] in D:\agent_work\2\s\Xamarin.Forms.Core\OnPlatform.cs:71 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 --- End of inner exception stack trace --- at (wrapper dynamic-method) System.Object.79f518ee-155a-49e7-9fa1-0901474d0e7a(intptr,intptr,intptr) 07-01 08:42:45.390 E/mono-rt ( 6880): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. 07-01 08:42:45.390 E/mono-rt ( 6880): at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr) 07-01 08:42:45.390 E/mono-rt ( 6880): at Xamarin.Forms.OnPlatform1[T].op_Implicit (Xamarin.Forms.OnPlatform1[T] onPlatform) [0x00036] in D:\agent_work\2\s\Xamarin.Forms.Core\OnPlatform.cs:71 07-01 08:42:45.390 E/mono-rt ( 6880): at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) 07-01 08:42:45.390 E/mono-rt ( 6880): at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 07-01 08:42:45.390 E/mono-rt ( 6880): --- End of inner exception stack trace --- 07-01 08:42:45.390 E/mono-rt ( 6880): at (wrapper dynamic-method) System.Object.79f518ee-155a-49e7-9fa1-0901474d0e7a(intptr,intptr,intptr) 07-01 08:42:45.391 D/ ( 6880): HostConnection::get() New Host Connection established 0x8c6a2b00, tid 6880

  • User Avatar
    0
    alper created
    Support Team

    Looks like there's problem with one of the XAML files. The issue is with the OnPlatform tag. Check all the OnPlatform tags. Valid platform values: iOS, Android and UWP

    <OnPlatform x:TypeArguments="Thickness">
                     <On Platform="iOS" Value="0, 20, 0, 0" />
                    <On Platform="Android" Value="0, 0, 0, 0" />
                    <On Platform="UWP" Value="0, 0, 0, 0" />
     </OnPlatform>
    
  • User Avatar
    0
    Ricavir created

    @Alper : thank you for your explanation. I tried removing all OnPlatform tags but still same issue. I lost 3 days digging on this issue. I've tried a lot of things : coming back to previous commits, deleting all solution folders, cloning the solution on different folder, on different computers, cleaning everything BIN & OBJ... and still same issue.

    Right now, I'm trying to look at nuget packages and versions...

    But, honestly Xamarin is really confusing. I'm wondering if I can use it for a large project ! I can't imagine loosing days of work searching on stackoverflow and xamarin forums.

    I know you advice everybody about silly things thrown by Xamarin, but when you experiment it, it hurts ! :cry:

  • User Avatar
    0
    Ricavir created

    I can't explain why but I resolve this issue by updating my project from v5.1 to latest zero version v5.5.2.

  • User Avatar
    0
    alper created
    Support Team

    Welcome to the Xamarin world :)

    Sometimes updating Xamarin packages causes exception. If you update a Xamarin.Forms dependant package that's not supported by Xamarin.Forms it causes silly errors. Just update Xamarin.Forms DLL and it updates the related dependent packages. And you can check out my blog post about Xamarin development <a class="postlink" href="https://medium.com/volosoft/challenges-of-developing-xamarin-application-c2bfba6bbe49">https://medium.com/volosoft/challenges- ... bfba6bbe49</a>