Xamarin Binding .AAR Error : 'SecureString' does not implement interface member - xamarin

I am trying to bind a .AAR library getting the following error
CS0738 'SecureString' does not implement interface member 'ICharSequence.SubSequenceFormatted(int, int)'. 'SecureString.SubSequenceFormatted(int, int)' cannot implement 'ICharSequence.SubSequenceFormatted(int, int)' because it does not have the matching return type of 'ICharSequence'

This is a problem that occurs with binding Java methods with covariant return types.
There are two ways to fix this issue:
(1).Add a partial class declaration for SecureString and explicitly implement SecureString.SubSequenceFormatted(int, int).
(2).Remove the covariance from the generated C# code.
For more information, you can refer to this document https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/troubleshooting-bindings

Related

OMNeT++ issue with linking INET

During the build of my new OMNeT++ project I have encountered following error:
out/clang-debug//myUdp.o:(.rdata[_ZTI5myUdp]+0x10): undefined reference to 'typeinfo for inet::ApplicationBase'
I have already configured INET reference (Project "myUdp" -> Properties -> Project reference -> inet checkbox selected)
This is INET Makemake configuration: Target tab and Compile tab
This is Makemake configuration of my project (myUdp): Compile tab and Link tab
And the C++ code:
MyUdp.cc
#include <inet/applications/udpapp/UDPBasicApp.h>
class myUdp: public inet::UDPBasicApp {
};
Define_Module(myUdp);
MyUdp.ned
import inet.applications.udpapp.UDPBasicApp;
simple myUdp extends UDPBasicApp {
#class(myUdp);
}
Can somebody help me to solve this error?
That is probably because UDPBasicApp's methods are defined as virtual.
Compare the GCC infos on "vague linking" from http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html, for example this part:
type_info objects
C++ requires information about types to be written out in order to
implement dynamic_cast, typeid and exception handling. For
polymorphic classes (classes with virtual functions), the type_info
object is written out along with the vtable so that dynamic_cast can
determine the dynamic type of a class object at run time. For all
other types, we write out the type_info object when it is used: when
applying typeid to an expression, throwing an object, or referring
to a type in a catch clause or exception specification.
You would need to provide either a definition for the virtual functions in the base class (UDPBasicApp) or declare them pure, because the compiler (GCC or Clang in your case) is trying to determine the right method for the translation unit (where the vtable and typeinfo objects are then created) and it cannot determine it correctly apparently.

F# Entity Type Provider type scope

I'm trying to use SqlEntiyConnection to generate types from a MySql/MariaDb database using:
type UserService = SqlEntityConnection<Provider=provider, ConnectionString=connectionstring, Pluralize = true>
Where provider That declaration gives the following error message
"The provided types generated by this use of a type provider may not be used from other F# assemblies and should be marked internal or private. Consider using 'type internal TypeName = ...' or 'type private TypeName = ...'".
This seems to indicate that I will be unable to use any of the provided types outside the of the scope I declare it in. Is there a way to declare the type provider publicly so that I can use these types in public functions?
As per s952163's comment, I went with with SQLProvider instead of SQLEntityConnection.

Visual Studio UML Class Diagram & Modeling of Generic Types

I need to model a concrete generic class inheriting from a base generic class. First, see below:
ActivityFacade should be implemented this way:
public class ActivityFacade : BaseFacade<Activity, int>
{
}
How can I model this in a VS2012 UML class diagram? Looking at the diagram, it is obvious that ActivityFacade inherits from BaseFacade, but what's not obvious is the generic type parameters that it is passing in, namely: Activity and int.
You need to add a new binding class (BaseFacade <Activity, int>) connect it to your parameterized class (BaseFacade<T, TKey>) with a template binding connector and then specialize your child class (ActivityFacade) from the binding class.
From the OMG UML specification
"A template is a parameterized element ... used to generate other model elements using TemplateBinding relationships. The template parameters for the template signature specify the formal parameters that will be substituted by actual parameters (or the default) in a binding."
UPDATE:
The diagram I included is drawn using EA. The same concept can be modeled in Visual Studio UML tool. See the section "Template types: To use a template type" in msdn.

Calling a property on the const reference

I have C++/CLI class that defines a property:
public ref class AbstractOffer
{
public:
AbstractOffer();
property String^ Body;
};
In some function the AbstractOffer class is passed by const ref
foo(const AbstractOffer^ ao)
{
ao->Body;
}
When I call the property the method compiler gives the following error :-
error C2662: 'ivrworx::interop::AbstractOffer::Body::get' : cannot
convert 'this' pointer from 'const ivrworx::interop::AbstractOffer'
to 'ivrworx::interop::AbstractOffer %' 1> Conversion loses
qualifiers
It seems somehow connected to const. How can I call the Body property of the object if the object reference is passed by const?
The const qualifier is a problem in C++/CLI. It is only meaningful when it can be checked and that's not in general possible in .NET. It is of course not a problem when you only have one kind of compiler and that compiler follows strict language rules. Like C++. But .NET supports many languages, your method could be easily called from a Cobol.NET program for example. The odds of ever getting const-correctness added to the Cobol language are zero.
The compiler does compile code with const qualifiers and does make an effort to check when it can. Which is why you got the diagnostic. That can even work when the declaration exists in another assembly, as long as it was compiled with C++/CLI, the compiler emits modopt annotations in the metadata.
But there are limitations with that. Properties are one of them, you can't add the const qualifier to the getter, or a member function in general, you'll get slapped with C3842.
Best thing to do is to use C++/CLI for what it is good at, it is an interop language. And const qualifiers just don't work well in an interop scenario.
The only way I know to get round this is the cast away the const-ness. As long as you don't modify the object, it should be fine. (If you do modify it, I've no idea what the outcome will be).
i.e. change your function to be
void foo(const AbstractOffer^ ao)
{
const_cast<AbstractOffer^>(ao)->Body;
}

GetExportedTypes() on an assembly throws NotSupportedException

I'm having some serious troubles getting a Windows Phone 7.5 class library to load into the WP Unit Test Framework. It internally calls GetExportedTypes() on my assembly which throws a ReflectionTypeLoadException that doesn't contain any details. Its message is "ReflectionTypeLoadException" and its LoaderExceptions is null ("Could not evaluate expression"). The assembly is not using any 3rd party assemblies. If I create a separate WP7 app and do the same thing, I get the same results. I'm a very experienced Reflection user, but the lack of any detailed errors has brought my research to a complete halt. Just for completeness, it's the Windows Phone version of Fluent Assertions.
What about the Types array on the exception? Does it contain values? If so, does it also contain nulls? If so, you can find out which classes failed to load: You know all classes in the assembly and you know which classes loaded correctly. Those that are missing are the classes that couldn't be loaded. Maybe this info gives some clues.
This answer is based on the documentation, especially these bits:
From the Remarks of the LoaderExceptions property:
The LoaderExceptions property retrieves an array of type Exception that is parallel to the Types array. This array will contain null values whenever reflection cannot load a class.
And from the documentation of the Types property:
An array of type Type containing the classes that were defined in the module and loaded. This array can contain some null values.
I've found it! #GeertvanHorrik pointed me at a blog post he recently wrote. I was using an covariant interface (using the out parameter) which the runtime (!) doesn't support. Why the compiler does not protect me from that is a big mystery (and a huge disappointment) to me

Resources