I'm wondering if it's possible for a Xamarin application (all the platforms : Android, iOS, Windows Phone) to detect and load assemblies at runtime.
This is the kind of thing that I already did in WPF, and I'd like to use those modules (maybe with some modifications) in a Xamarin app.
I've spent yesterday looking for info online, and today I tried to implement a solution, but without success.
Prism seemed to be a way to do it, but it works only in WPF.
The restriction which makes this difficult is that I don't know at compile time any information about the assemblies. No names, no versions, no classes.
I can put the name and the version in the filename, and maybe find the classes by reflection. Using an interface as entry point (Prism use this), I should be able to do it.
Do you have any thoughts about this challenge ?
Thank you very much !
iOS: No
Apple does not allow code that was not bundled into the app at signing time to be executed, thus no on-the-fly Jit'ing of CIL allowed. The only exception to this is Javascript code that is run via their Nitro JavaScript Engine.
Android: Yes
Google allows just about anything you can think of, for better or worse ;-)
Windows Phone: No
All code must be signed as part of the Microsoft Store' App Ingestion process and thus you can not dynamically load assemblies later
Note: If this is a hard requirement for your app, you should look at hybrid mobile apps, like Cordova/Ionic, where you can perform a hot push to roll out new features, bugs fixes, etc... Besides self-hosting those hot pushes, various vendors support hosting of those, even Microsoft Azure has a full versioning publication system for this. Of course you would most likely be coding in JavaScript (or some trans-compiled variant).
Related
I need help with a change of perspective.
Recently, due to the company's business needs, it is necessary to migrate the existing Win32 software to the UWP platform. Because the software involves multiple devices, different devices have their own specific interfaces.
If the released software package directly includes all devices, the software package will be too large. Therefore, we want to enable the main software framework to support the operation of the corresponding device by downloading or additional installation when the user's related equipment is identified.
From the information found so far, this method is somewhat similar to the Optional Package. However, the actual experiment found that it can only support the separation of the back-end logic code, but not the XAML Page into the optional package.
Is there any way to separate the XAML Page and load it dynamically?
I'm also currently looking at solutions to load XAML Page dynamically in UWP. While I don't have a working solution yet it looks like I'm on the right track.
It seems Windows Community Toolkit Sample App is loading XAML dynamically so all you should need is in that code base.
I thought up an idea for a website that would involve some video editing happening on the web server. Microsoft UWP has a library that does the video editing functions I'm looking to perform... Amazing!!
My problem is I don't know if it's possible to get my website to run UWP code on Azure. Web Jobs seem like what I'd prefer to use to kick off this code, but web jobs don't appear to be able to run UWP code and without UWP code I don't see a library that can perform the video editing I'd like to do. Does anybody know if it's possible to run UWP code on Azure? If so, how?
I don't think WebJobs are especially suited for this scenario. They are part of the WebApp platform as a service offering that abstracts the underlying operating system for you to be able to focus on building the code itself and deploy as easily as possible.
UWP on the other hand is a Windows-specific app platform which has many requirements including running on Windows 10. Because you don't know which concrete operating system the web app will run on, it is not easy to say if the APIs would work.
That said, you could theoretically use UWP APIs in a web app as well, because there is a UwpDesktop NuGet package that allows it mainly targeted for desktop apps. It is a long shot but you can certainly try it.
As a preferable solution, I would still look to find another library that suits your needs, as the choice on NuGet is pretty broad and one of those should be sufficient.
I would suggest taking a look at azure functions
These have about the same working as webjobs, however expand beyond the limitations of webjobs. These are also more versatile in what they can do and how they can be created.
webjobs vs functions
I've read that applications which are being developed using Mono are deployed with a MonoRuntime that works similar as ART, interprets the C# code, executes them etc. I assume Unity and Xamarin both does this.
What is strange for me is that theoretically I could write a runtime and ship it with my app? But that is supposed to be next to the runtime, below the application framework? How can the sandboxing let this happen?
I assume this might be the solution to my confusion, but I struggle understanding it.
What am I missing here?
Thanks in advance
First think about how NDK/JNI apps work on Android. They are launched from standard Android Java code run via ART/Dalvik and use JNI calls into C/C++ code. The process is still within the standard Android 'sandbox' but has additional lower level access to libraries provided by Android NDK headers. As that code is written in C/C++ it can be performant/cross system compatible.
So to answer:
But that is supposed to be next to the runtime, below the application framework?
I would argue no, at least you aren't really below the Android application framework. The MonoRuntime is started from Android and can use any of the 'Standard Libraries' which are exposed either via a JNI wrapper to the Android Java side or by a NDK header.
If you look at the below diagram you'll see 'Standard Libraries' which can be OpenGL ES which has a Android Java API and OpenSL ES which exposes more detail in NDK than the Android Java media api.
I could write a runtime and ship it with my app?
Yes you could, although you may want to define clearly what you mean by 'runtime'. If you are pre-compiled you can strip out unnecessary classes/modules which I believe Mono does.
How can the sandboxing let this happen?
You are still in the sandbox. Nothing prevents you from writing your own interpreter / Virtual Machine written in C/C++, interfacing the Android framework through standard JNI/NDK calls, and adding it to your own APK. Regardless you are still limited to what the Android framework/runtime allows for apps along with same process restrictions and limitations.
It seems to be a deliberate security of Windows 10 Store apps that assemblies not be allowed to be loaded at runtime. I think that this feature is massive overkill and stops UWP development dead in its tracks. However, if it is a rock solid design decision by Microsoft, there is nothing we can do to argue with it.
Instead, I'd like to ask the question, assuming that you were not deploying your UWP app to the store, would it still be impossible to load an assembly dynamically? If it's possible, how?
Please see this feature request: https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/18145291-dynamically-load-assembly
Regardless of what environment you deploy your UWP application to, the UWP API will be the same. Choosing to deploy your app internally instead of to the Windows Store will not enable non-supported API features, eg. Assembly.Load().
It seems as though the answer to this question is no.
The game has changed in UWP. UWP is a platform which is geared toward getting apps in to the store. It's a stripped down platform and doesn't appear to allow you to load assemblies at runtime. This was possible in .NET.
However, there does seem to be a way to run UWP style apps on top of the .NET runtime using the Desktop Bridge. I'm not really that familiar with it, but you can read more here as a starting my point. My guess is that if you want to load assemblies dynamically, the best approach would be to use this:
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-root
I am looking for a mobile automated testing tool and have found robotium. Will it work with C# android app? Can I add the robotium jar file to a .Net project?
While it is likely that, with some amount of work, Robotium could be made to work with Xamarin.Android, it is an amount of relatively complicated work that the Robotium project is unlikely to do. (the killer item probably being good IDE integration)
However, it appears that Xamarin has acquired a testing framework for mobile applications called Calabash. They have devoted a page to explaining it on their main site: http://developer.xamarin.com/guides/testcloud/calabash/introduction-to-calabash/. My instinct here (without having tried it) would be to try and make it work, as it is pretty likely that Calabash will be supported by Xamarin in the future.