System.TypeLoadException Could not load type CategoriesActivity

MojamHaqueMojamHaque USMember
edited January 2016 in Cross Platform with Xamarin

I am very new in Xamarin Application Development.

I have written an Activity class with following definition

[Activity(Label = "Courses", MainLauncher = true, Icon = "@drawable/icon")]
public class CategoriesActivity : ListActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Create your application here

string[] categoryTitles = {"Category 1", "Category 2", "Category 3" };

ListAdapter =
new ArrayAdapter(this, global::Android.Resource.Layout.SimpleListItem1,
categoryTitles);
}
}

The purpose of this activity class is to showing Category 1, Category 2, and Category 3 as List Items.

But when I run the application it returns me following exception:

01-23 14:27:19.157 E/MonoDroid( 2137): Could not load type 'Courses.Android.CategoriesActivity, Courses.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Skipping JNI registration of type 'md5ba6caf9a9061d0cbb25c0daaef535be4/CategoriesActivity'.
An unhandled exception occured.

01-23 14:27:20.371 I/art ( 2137): Thread[2,tid=2143,WaitingInMainSignalCatcherLoop,Thread*=0xaf478400,peer=0x12c00080,"Signal Catcher"]: reacting to signal 3
01-23 14:27:21.224 I/art ( 2137): Wrote stack traces to '/data/anr/traces.txt'
01-23 14:27:23.305 I/MonoDroid( 2137): UNHANDLED EXCEPTION:
01-23 14:27:23.526 I/MonoDroid( 2137): System.TypeLoadException: Could not load type 'Courses.Android.CategoriesActivity, Courses.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' from assembly ''.
01-23 14:27:23.526 I/MonoDroid( 2137): at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
01-23 14:27:23.527 I/MonoDroid( 2137): at System.Type.GetType (System.String typeName, Boolean throwOnError) [0x00011] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/corlib/ReferenceSources/Type.cs:57
01-23 14:27:23.527 I/MonoDroid( 2137): at Java.Interop.TypeManager.n_Activate (IntPtr jnienv, IntPtr jclass, IntPtr typename_ptr, IntPtr signature_ptr, IntPtr jobject, IntPtr parameters_ptr) [0x0007b] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:145
01-23 14:27:23.527 I/MonoDroid( 2137): at (wrapper dynamic-method) System.Object:90d2a13e-584b-4a05-a439-c9d6ba401669 (intptr,intptr,intptr,intptr,intptr,intptr)
01-23 14:27:23.644 W/art ( 2137): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
An unhandled exception occured.

01-23 14:27:24.452 E/mono ( 2137):
01-23 14:27:24.452 E/mono ( 2137): Unhandled Exception:
01-23 14:27:24.452 E/mono ( 2137): System.TypeLoadException: Could not load type 'Courses.Android.CategoriesActivity, Courses.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' from assembly ''.
01-23 14:27:24.452 E/mono ( 2137): at (wrapper dynamic-method) System.Object:90d2a13e-584b-4a05-a439-c9d6ba401669 (intptr,intptr,intptr,intptr,intptr,intptr)
01-23 14:27:24.452 E/mono ( 2137): at (wrapper native-to-managed) System.Object:90d2a13e-584b-4a05-a439-c9d6ba401669 (intptr,intptr,intptr,intptr,intptr,intptr)
01-23 14:27:24.453 E/mono-rt ( 2137): [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Courses.Android.CategoriesActivity, Courses.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' from assembly ''.
01-23 14:27:24.453 E/mono-rt ( 2137): at (wrapper dynamic-method) System.Object:90d2a13e-584b-4a05-a439-c9d6ba401669 (intptr,intptr,intptr,intptr,intptr,intptr)
01-23 14:27:24.453 E/mono-rt ( 2137): at (wrapper native-to-managed) System.Object:90d2a13e-584b-4a05-a439-c9d6ba401669 (intptr,intptr,intptr,intptr,intptr,intptr)
referenceTable GDEF length=670 1
referenceTable GSUB length=7202 1
referenceTable GPOS length=24560 1

Best Answer

Answers

  • MojamHaqueMojamHaque USMember

    Yes

  • @kentucker.4086, could you please explain a bit more how to make sure both dll and app are targeting the same version of Android?
    Thank you.

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    Could not load type 'Courses.Android.CategoriesActivity, Courses.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Skipping JNI registration of type 'md5ba6caf9a9061d0cbb25c0daaef535be4/CategoriesActivity'.

    I'm noticing that you probably have the word "Android" in your namespacing. Doing that confuses the Compiler because Xamarin.Android already contains a namespace "Android" and in my experience bad things happen when you do this. Change your Android namespace to something else like "Droid" and that should not confuse the compiler.

  • KenYeeKenYee USMember ✭✭

    Did renaming the namespace help? I'm hitting the same issue and my app is also Blah.Android for the namespace

  • KenYeeKenYee USMember ✭✭

    ok...I just renamed my namespace. Does NOT help. Bugger :-P

  • TomLinTomLin USMember ✭✭

    @DylanSchoenmakers said:
    I've encountered the same problem and in my case removing the application completely from the device solved it. Just find the app on your device or simulator and remove it, then rebuild and install.

    Works for me!

  • And for me, just remove app from device and rebuild

  • Felix.xFelix.x USMember ✭✭

    And> @DylanSchoenmakers said:

    I've encountered the same problem and in my case removing the application completely from the device solved it. Just find the app on your device or simulator and remove it, then rebuild and install.

    Worked for me.
    I manually deleted my app, the mono shared dll, and any other xamarin.android test apps on my phone.

  • muralim.1044muralim.1044 USMember

    Unhandled Exception:
    System.TypeLoadException: Could not load type 'AlarmAccount.Clients.UI.App' from assembly 'AlarmAccount.Clients.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'AlarmAccount.Clients.UI.App' from assembly 'AlarmAccount.Clients.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

    i am getting this error please help me

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    Removing the app and re-installing it may workaround the problem in a dev environment, but what if this happens in production when a paying customer tries to upgrade the app? How do we prevent that from happening?

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @kentucker - re. "Is the dll and app targeting the same version of android?"

    How to do you check this?

  • kentuckerkentucker USMember ✭✭✭✭

    right click on dll and show its properties. make sure it is not blocked. it might show what version of android is supported in properties. if it is not there decompile the dll with something like just decompile or ilspy and the version of android show there

  • ossentooossentoo GBMember ✭✭

    Worked for me.

    The issue was that I'd renamed the Android app class namespaces and the previously installed app was obviously conflicting with the new deployment that had different namespaces. Uninstalling previous app cleared the issue

Sign In or Register to comment.