Repository navigation
C# to Java wrong translation for constructor #3490
Description
Activity
How do you reproduce the
java.lang.InstantiationExceptionerror? When I run your repro, I get aNullReferenceExceptionhere:provider = DependencyService.Get<IProviderService>(); provider.FindPeers(entry.Text);This is because the
DependencyServicecannot find anything that implementsIProviderService. In order for it to find yourProviderServiceclass the class needs to implementIProviderService.That is, this:
public class ProviderService : SAAgentneeds to be this:
public class ProviderService : SAAgent, IProviderService- addedneed-infoIssues that need more information from the author.Issues that need more information from the author.
on Aug 20, 2019 @jpobst thanks for looking into this issue first of all.
it is a bit complicated use-case, i will try to explain here step by step. so basically,-
I try to communicate samsung galaxy watch and Xamarin.Android companion app.
my repo project is the companion project installed on my phone. when you install this project, it is automatically opening a listener socket. Nothing needs to be done. So that button on Mainpage.xaml isnt needed at all. It is called Provider app. -
there is the consumer app also which is tizen.net application installed on the smart watch. Samsung has a great job for that and they have even simple hello world sample here as a zip. They explain also how it works between phone and watch. mine is number 1, Provider (Android) and Consumer (Gear).
-
so i downloaded this HelloAccessory_.NET.zip (838KB) and opened with VS, VS Can be connected using Tizen Device manager. and once it is installed on the watch, there is "connect" button appears as shown in the image. I click on "connect" and request is sent to the phone over the bluetooth but it crashes with this exception message.
For you to test it; You dont really need an actual Samsung Watch. there is emulator.
- you need to install tizen sdk, tizen visual studio extension and enable a watch emulator which will appear after installing the extension and sdk.
I created same ticket on Samsung developer portal as a support ticket. Samsung replied as they are reviewing but unfortunately so far no reply.
I believe that error is on xamarin side but Samsung Sdk is also not optimized. if they could enabled a parameterless constructor in their java sdk, it would solve the problem but probably for Java it isnt required for C# seems to be yes.-
With my noted change, the
ProviderServicecan be created and called, so I don't think that class is the problem. Can you post a full stacktrace for your exception?Our "Java Callable Wrapper" generation does not support reading IL to determine what
base(...)arguments were provided to create a Java equivalent. It only supports forwarding parameters.What you can do, to provide a default constructor, is use
ExportAttribute.SuperArgumentsString, e.g.partial class ProviderService : SAAgent { [Export (SuperArgumentsString="\"ProviderService\", ServiceConnection.class")] public ProviderService() : base("ProviderService", SASOCKET_CLASS)
This allows an appropriate Java-side default constructor to be generated, but at the cost of additional manual effort to ensure that your C# code and Java code are consistent with each other.
Reacted by Emil Alipiev@jonpryor thank you. this was really helpful. I could make it working with the link you shared. Documentation explains it really well. Such a shame that my google search didnt end up on this page.
I had to add Mono.Android.Export.dll reference, is there any disadvantage or performance downside using this dll. I would like to know because It will effect my main android app. so I have reevaluate if there is any cost.I had to add Mono.Android.Export.dll reference, is there any disadvantage or performance downside using this dll.
On methods, there is currently a performance disadvantage. On constructors, there is not.
- removedneed-infoIssues that need more information from the author.Issues that need more information from the author.
on Aug 22, 2019 - ghost locked as resolved and limited conversation to collaborators
on Jun 5, 2022
I am trying to create Samsung Tizen Companion app in Xamarin.Android. Samsung has an SDK called Samsung Accessory SDK. This is only available in jar. So I created a Java Binding Library.
Samsung also has a sample code in java how to handle communication between Tizen and Android (in this case xamarin.android).
So I tried to convert below attached java class(ProviderService.txt) into C# see the url
ProviderService.txt
Problem here is
below code constructor in C#
when I look at the obj folder of my xamarin.android project and find ProviderClass.java file generated
but it is supposed to be interpreted as below java code
in C# obviously no difference between 2 code pieces but in Java i think that there is difference because. Sdk request is failing with error telling me that
Repro:
https://github.com/EmilAlipiev/SamsungWearCompanion