AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

Unable to use AndroidX.Room type attributes

Open JaarBranix opened this issue 4 years ago • 13 comments

Xamarin.Android Version (eg: 6.0):

Operating System & Version (eg: Mac OSX 10.11): Mac OS Mojave 10.14.6

Support Libraries Version (eg: 23.3.0): AndroidX Core 1.2.0, Room 2.2.4

Describe your Issue: When I'm trying to make the Room Database I get this error.

Captura de Pantalla 2020-03-18 a la(s) 14 41 03

Steps to Reproduce (with link to sample solution if possible): X

Include any relevant Exception Stack traces, build logs, adb logs: X

JaarBranix avatar Mar 18 '20 21:03 JaarBranix

@JaarBranix

Thanks for the feedback, but I cannot reproduce. Please create minimal repro sample and submit it here.

Sidenote: Images are not useful for analysis. Textual messages, logs, files etc are preferred way for submitting issues. Thanks

moljac avatar Mar 19 '20 09:03 moljac

I am having the same issue using RoomDatabase where attribute "Entities" is an array of type Class but has issue recognizing it as valid attribute parameter type. I pushed project on GitHub: NoteDatabase.cs

VassiliKurman avatar May 23 '20 13:05 VassiliKurman

I am having the same issue using RoomDatabase

@VassiliKurman did you find a fix for this?

peter-mghendi avatar May 31 '20 00:05 peter-mghendi

I am having the same issue using RoomDatabase

@VassiliKurman did you find a fix for this?

@sixpeteunder I couldn't find the fix. I guess it's a binding issue in xamarin android.

VassiliKurman avatar Jun 01 '20 08:06 VassiliKurman

I am having the same issue using RoomDatabase

@VassiliKurman did you find a fix for this?

@sixpeteunder I couldn't find the fix. I guess it's a binding issue in xamarin android.

VassiliKurman avatar Jun 01 '20 08:06 VassiliKurman

@VassiliKurman @sixpeteunder I tried another workaround to create a custom class attribute that inherits the database attribute annotation and setting the entities values within the constructor on the custom class so I was trying to see if it will work with one entity table. public class DatabaseEntities : DatabaseAttribute { public DatabaseEntities() { Entities = new Class[] { Class.FromType(typeof(NoteList)) }; } }

[DatabaseEntities(Version = 1, ExportSchema = false)] //[Database(Entities = new Class[] { Class.FromType(typeof(ShoppingList)) }, Version = 1, ExportSchema = false)] public abstract class ShoppingListDatabase : RoomDatabase { //Room database definition }

The original database annotation I commented since it will produce entities is not a valid name attribute.

The only issue I experience using the custom data annotation attributes. The code compiles but fails when debugging. After implementing the custom attribute the debugger will produce this error Room + cannot find implementation DB + DB_Impl does not exist From there I can't go further on testing the room database library. I think it will require the original database annotation attribute for it work.

gabrieldwight avatar Jun 01 '20 10:06 gabrieldwight

@JaarBranix

Thanks for the feedback, but I cannot reproduce. Please create minimal repro sample and submit it here.

Sidenote: Images are not useful for analysis. Textual messages, logs, files etc are preferred way for submitting issues. Thanks

@moljac You have an example and there is a second issue that references this, but no one ever really gets a response from you. Are you still investigating/working on this? I'm trying to use Room since March.

besplash avatar Aug 24 '20 08:08 besplash

@besplash

You have an example and there is a second issue that references this,

That is not the sample. I have to create project and minimal repro sample and this takes time and I have to carefully manage my time.

but no one ever really gets a response from you.

I beg to disagree. Namely I maintain several repos (AndroidX, GooglePlayServices + Firebase) and have constant discussion and communication with nice helping people. I have to prioritise tasks based on several properties and one of them is quality of feedback and help. Sheer criticism without being constructive decreases motivation, so some tasks get lower priority.

Are you still investigating/working on this?

Not at this moment, but it is on my list.

Thanks

moljac avatar Aug 24 '20 08:08 moljac

@moljac

That is not the sample. I have to create project and minimal repro sample and this takes time and I have to carefully manage my time.

You got a minimal sample in this issue here, that perfectly shows the problem https://github.com/xamarin/AndroidX/issues/77#issuecomment-633059155

I beg to disagree. Namely I maintain several repos (AndroidX, GooglePlayServices + Firebase) and have constant discussion and communication with nice helping people. I have to prioritise tasks based on several properties and one of them is quality of feedback and help. Sheer criticism without being constructive decreases motivation, so some tasks get lower priority.

I'm sorry, there was probably a misunderstanding. I didn't mean to attack you regarding your entire work, I was just saying that we didn't get a reply on either issue after you were given a sample.

Not at this moment, but it is on my list.

Good to know, thanks for keeping track and thanks for the fast response.

besplash avatar Aug 24 '20 10:08 besplash

@besplash

I'm sorry, there was probably a misunderstanding. I didn't mean to attack you regarding your entire work, I was just saying that we didn't get a reply on either issue after you were given a sample.

It is OK, no need to be sorry. If I miss some reply it is not deliberately. We really try hard to keep up with everything. We are humans and we do make mistakes and we are sorry for them.

moljac avatar Aug 24 '20 11:08 moljac

Good Morning I tried to use Xamarin Room, but but this presents the same problem.

avilesmoralesdev avatar Sep 04 '20 15:09 avilesmoralesdev

I do not think AndroidX.Room is going to work if it requires using attributes like [Database]. The initial issue is that C# attributes can only support certain types which can be serialized into the assembly which are often only simple types, and not types like Java.Lang.Class: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0655.

After that, the issue is that annotating types with attributes in C# does not mean that the types get annotated in the Java wrappers that are generated. So the Java types will probably not have the needed annotations.

Finally, I don't know how these annotations are accessed. If Android is accessing them at runtime it would probably be fine (if all the other issues were fixes), but if it is accessing them at compile time to generate additional code then you would also need some sort of gradle process running to do that step.

If it is possible to use AndroidX.Room using only code and not attributes then that should work, but I don't see the attribute mechanism working any time soon.

jpobst avatar Oct 21 '20 19:10 jpobst

@jpobst Thank you for the new information.

peter-mghendi avatar Oct 21 '20 20:10 peter-mghendi

I am having the same issue (CS0655 for Entities). But you claim you can't reproduce. So does that means you have code that is working? If so, there must be something different in how you and us are coding this. I have not detected any difference as I am working of the sample here

I would appreciate it if you could provide guidance / solution to this matter. Thanks.

sammazza avatar Jul 08 '23 05:07 sammazza

Closing as stale and not planed

moljac avatar Sep 11 '23 22:09 moljac