"could not load type ... while decoding custom attribute"

Hi all,

I am getting the error from the title at runtime when calling DependencyService.Get<>() to access the iOS binding of a cross-platform interface.

It used to work fine with my ios app project, but because I need to be able to release several similar apps with different brandings, I created an iOS library project to contain the base code.

So my solution architecture changed from:

iOS "reader" binding library project
cross-platform project
ios app project referencing cross-platfom and binding, referencing the binding and containing interface implementation to the binding

to:

iOS "reader" binding library project
cross-platform project
iOS UI library project referencing cross-platform and "reader" binding library
ios app project referencing cross-platfom, referencing and containing interface implementation for the binding, as well as the UI library

(I hope that is clear enough...)

But calling DependencyService.Get() does not work anymore after trying to put my UI code in a library.
Here is what I tried so far to solve the issue:

-add [assembly: Xamarin.Forms.Dependency (typeof (MobileWallet.iOS.CardReader_iOS))] somewhere in the ios app (initially the Get returned null; after adding this to the ios app, I get "could not load type")
-setting the "don't link" option in the ios app configs
-add [Foundation.Preserve (AllMembers=true)] to the reader_ios implementing the interface (the class calling the reader binding)

None of this worked, has anyone an idea of what I am doing wrong?
thanks
Guillaume

Answers

  • guillaumechamplongguillaumechamplong USMember
    edited September 2015

    Research and trials have lead nowhere.

    I tried with a simple project. Basically it contains a PCL project with Forms, an iOS app project "xamTest.iOS.custom" and an iOS library project "xamTest.iOS.common". To create it, I simply used the template for a new Forms app (PCL option), then removed the android project, and added an iOS library project. I added an interface in the cross-platform as described in the guide to use DependencyService, and put the implementation in the "xamTest.iOS.common". I register my implementation with [assembly: Xamarin.Forms.Dependency (typeof (test_ios.Test))].

    My goal is to be able to create as many "iOS.custom" as I want in order to change app icons etc, and re-use "iOS.common" as well as the cross-platform code.

    This compiles but I get an error when calling DependencyService.Get<>(): "could not load type..."

    Am I missing something simple to make it work?
    Is this the right architecture to achieve app customization?
    If not, what is the way to create several similar apps with different branding but exact same code?

    If I can't do that easily I will probably not switch to Xamarin (I have currently my app running on Android and iOS), but I would love to have one code base for every platform (obviously!).

    Thanks
    Guillaume

    I wanted to attach a sample project to but was unable to attach a file (tried on firefox & safari)

  • The file was just too big, I cleaned it for smaller size.
    BTW, I'm using Xamarin Studio 5.9.7 build 9

  • guillaumechamplongguillaumechamplong USMember
    edited October 2015

    After a bug report, here is the answer:
    Calling DependencyService.Register<test_ios.Test> () after Forms.Init() in my app delegate fixed the issue.

Sign In or Register to comment.