Why can't MonoDroid find my assemblies? - c#

I made a simple Android HelloWorld app using Xamarin Studio 4.2.3 that doesn't do anything except it prints out some message if a random number is greater than 0.5. It works just great on a Nexus 4 and a Nexus 5.
The next thing I'm doing is to extract the .dll with the code from the app's apk (from the assemblies folder) using 7Zip. Using .Net Reflector and Reflexil I'm modifying a single instruction, usually the brfalse.s that gets generated by the IF statement in "if(rand.nextDouble()>0.5){doStuff()}" such that it branches to the instruction right in front of the call to doStuff(), thereby effectively making the IF statement useless and ensuring the method always gets called.
Next I'm saving the patched .dll, replacing the original one in the .apk with the patched one, sign and zipalign the .apk and finally I'm installing it using adb.
When I'm launching the app on my phones it crashes directly and LogCat shows the following:
03-20 10:12:08.709: I/ActivityManager(764): Start proc HelloMonoLVL.HelloMonoLVL for activity HelloMonoLVL.HelloMonoLVL/hellomonolvl.hellomonolvl.TrialSplashScreen: pid=23099 uid=10128 gids={50128}
03-20 10:12:08.729: D/dalvikvm(23099): Trying to load lib /data/app-lib/HelloMonoLVL.HelloMonoLVL-1/libmonodroid.so 0x427154a0
03-20 10:12:08.729: D/dalvikvm(23099): Added shared lib /data/app-lib/HelloMonoLVL.HelloMonoLVL-1/libmonodroid.so 0x427154a0
03-20 10:12:08.739: W/libc(23099): WARNING: generic atexit() called from legacy shared library
03-20 10:12:08.759: W/monodroid-gc(23099): GREF GC Threshold: 46800
03-20 10:12:08.769: A/monodroid-assembly(23099): Coult not load assembly 'HelloMonoLVL' during startup registration.
03-20 10:12:08.769: A/monodroid-assembly(23099): This might be due to an invalid debug instalation.
03-20 10:12:08.769: A/monodroid-assembly(23099): A common cause is to 'adb install' the app directly instead of doing from the IDE.
03-20 10:12:08.789: I/ActivityManager(764): Process HelloMonoLVL.HelloMonoLVL (pid 23099) has died.
03-20 10:12:08.789: W/ActivityManager(764): Force removing ActivityRecord{42752a50 u0 HelloMonoLVL.HelloMonoLVL/hellomonolvl.hellomonolvl.TrialSplashScreen t238}: app died, no saved state
Since this didn't work I used the C# port of the LVL. Built the LVL sample app, deployed and it works on the phones. I again extracted the .dll with the license verification code, using Reflexil I changed the code of a method, injected the patched .dll in the apk, signed and zipaligned the apk. Again it doesn't work but crashes on launch and I now get:
03-20 10:21:19.049: D/dalvikvm(23507): Trying to load lib /data/app-lib/de.marius.lvl-1/libmonodroid.so 0x42711448
03-20 10:21:19.049: D/dalvikvm(23507): Added shared lib /data/app-lib/de.marius.lvl-1/libmonodroid.so 0x42711448
03-20 10:21:19.069: A/MonoDroid(23507): No assemblies found in '/data/data/de.marius.lvl/files/.__override__' or '/storage/emulated/0/Android/data/de.marius.lvl/files/.__override__'. Assuming this is part of Fast Deployment. Exiting...
03-20 10:21:19.079: I/ActivityManager(764): Process de.marius.lvl (pid 23507) has died.
03-20 10:21:19.079: W/ActivityManager(764): Force removing ActivityRecord{42bc3c60 u0 de.marius.lvl/.TrialSplashScreen t239}: app died, no saved state
It doesn't seem to make any difference if I'm using the apk that Xamarin generates in Release mode or Debug mode. I tried both using the apk versions from the bin folder of the project and the ones I pulled from the phone with adb pull.
I'm new to Xamarin so maybe my approach is naive. Is there something like a hash check that my patched .dlls don't pass? I saw that Reflexil has an option to remove StrongNames, I tried that but it didn't seem to make any difference (but I must admit I don't really know how those work).
Is it even possible what I'm trying to do?
Any help is much appreciate.

Uninstall all the packages installed in your project including android support libraries like Android.Support.v4 support libraries and clean the solution.
Then again reinstall all the required packages and support libraries and rebuild your solution. It may help you sort out your query.

Related

Why does using SQLite in Azure Functions give me a DLLNotFoundException?

I'm trying to write a timer-triggered Azure Function that downloads a bunch of data and processes it into a SQLite database. I've written code that does this and runs fine on my own machine. But, the same code in Azure yields a DllNotFoundException, complaining that the system can't load "e_sqlite3."
Here is the full error message (for the inner exception):
Exception while executing function: FnordFunction
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception
while executing function: FnordFunction --->
System.TypeInitializationException : The type initializer for
'SQLite.SQLiteConnection' threw an exception. --->
System.DllNotFoundException : Unable to load DLL 'e_sqlite3': The
specified module could not be found. (Exception from HRESULT:
0x8007007E)
at
SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number()
at
SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()
at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)
at SQLitePCL.Batteries_V2.Init()
at SQLite.SQLiteConnection..cctor()
End of inner exception
Here are the steps to reproduce:
In Visual Studio 2017, I created an Azure Function project using the latest template.
I added my code files to the project, and edited the "Run" method to call the code.
Using NuGet, I added sqlite-net-pcl, and some other libraries I need. (I've also tried this with EntityFrameworkCore, using SQLite; that didn't work either).
Build
Publish
Run. Failure.
The problem might be that my code is wrong--but it works fine when I just make a console .exe.
The problem might be that VS2017 is not bundling the correct dll for SQLite when it builds. I'm not sure how to fix that. I've seen from other searches that the same error message pops up when the platform target is set to "Any CPU," but changing that to x86 or x64 does not fix the problem.
The problem might be that the SQLite libraries I have tried won't run in the Azure Functions sandbox. If so, are there any simple SQLite libraries that will run in the sandbox?
Thanks in advance...
The problem is that when running in a Function App, native binaries can't be automatically loaded from your bin folder, so it's not finding the DLL.
One way to solve this is to drop it in your D:\home\site\tools folder (e.g. using Kudu Console), as that folder is automatically place on the PATH.

Azure Function referencing mixed-mode assembly

TL;DR: Is it possible to use mixed-mode assemblies in Azure Functions?
Details: I have an in-house mixed-mode assembly that I'm trying to use in an Azure Function. When I try to build, I get the following error:
------ Build started: Project: AzureDemo, Configuration: Debug x64 ------
AzureDemo -> C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll
C:\Users\hugh\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'file:///C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Done building project "AzureDemo.csproj" -- FAILED.
For clarity, the in-house library is x64 and my demo project is also x64, so it's not an x86/x64 problem.
Also, when I take the code out of the Azure Function project and put it in a plain old .NET Core 2.0 project, it builds just fine. edit: it builds fine, but it still doesn't run (System.EntryPointNotFoundException: A library name must be specified in a DllImport attribute applied to non-IJW methods.). So I may be in deeper water than I thought.
I'm kind of afraid Azure Functions won't work with mixed-mode assemblies... but I haven't found any definitive statement to that effect.
I'm also a little concerned that the fact that it's using netstandard1.0 might have something to do with it.
The error is happening at build time when the SDK launches the build task to generate the build artifacts/function metadata.
I've opened this issue with the details to track the bug: https://github.com/Azure/azure-functions-vs-build-sdk/issues/131
Actual x64 CLI releases would also be required for successful local testing, and this is tracked here: https://github.com/Azure/azure-functions-cli/issues/117

Error when building uwp app in Release mode

I have this app, that builds and runs successfully in Debug mode, on both my local computer and on my Windows Phone device, when trying with the Release mode, I get these 3 errors :
Error Internal compiler error: One or more errors occurred.
The non-generic type 'PInvoke.NTSTATUS.Code__PInvoke_Windows_Core'
cannot be used with type arguments
...obj\x64\Release\ilc\intermediate\Liberte.Windows.Interop\SafeTypes.g.cs 333
The type or namespace name 'Value' could not be found (are you missing
a using directive or an assembly
reference?) ...obj\x64\Release\ilc\intermediate\Liberte.Windows.Interop\SafeTypes.g.cs 333
The actual code where the two last errors are detected is an auto generated code under a file named SafeTypes.g.cs and the line where the errors is raised is :
namespace PInvoke
{
[global::System.Runtime.InteropServices.McgRedirectedType("PInvoke.NTSTATUS,PInvoke.Windows.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a")]
public unsafe partial struct NTSTATUS__PInvoke_Windows_Core
{
public global::PInvoke.NTSTATUS.Code__PInvoke_Windows_Core <Value>k__BackingField;
}
}
I don't have any idea what does this mean, nor what should I do, any explanation and solution to this ?
Update :
Tried to Close VS, then Delete the Obj and the Bin content, rebuild again, but stuill have the same error.
I should mention maybe that I have reference to 2 other projects, one of them is a PCL project that uses PCLCrypto library, and the other one is a Universal App library that uses EntityFramework 7 pre-release with sqlight.
Update 2:
I tried to disable compilation with .Net native just to see what goes on, the release build succeeds, but the App crashes and quits just after startup.
Update 3:
I just discovered that the PCLCrypto library that I use in one of the two project I'm referencing, references two libs that are causing the problem, and they are mentioned in the errors above, I found this out when trying to uninstall the library to see if it is the cause of the problem :
I tried to rollback to a previous stable version, compiled in Debug mode, everything worked perfectly, when I try again Release mode with .Net native, I encounter a new problem : Out of memory.
Concerning Update 3, it seems to be a bug with .NET Native tool chain, I opened an issue on PCLCrypto repo that was moved to corert repo

Application-internal exception in Windows.UI.Xaml.dll

I'm working on a Windows 10 Store Windows Universal app using Visual Studio 2015 Community, c#, and XAML. It is decompressing a compressed file and displaying images found therein.
The build provides 0 warnings.
The debug version runs fine regardless of input file size.
The release version runs fine with typical input file sizes.
For large input file sizes (~100 1 megapixel images), the release build crashes consistently with 'Unhandled exception at 0x55E9A305 (Windows.UI.Xaml.dll) in appname.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x127DC468, 0x00000005).'
The crash occurs when the user tries to display the second image. All decompression is complete and all the bitmaps have been created by this time.
I've fiddled with the Build settings and narrowed down the difference to the option 'Compile with .NET Native Tool chain'. If that option is checked, the application crashes. If that option is unchecked, the application runs fine.
All told, the application is using about 400 MB of heap so although not small it isn't near the capacity of the machine.
"So uncheck the option!", I hear you cry. Unchecking the box leads to the certification failure shown below:
FAILED
Supported APIs
• Error Found: The supported APIs test detected the following errors:
-API OpenSemaphore in api-ms-win-core-synch-l1-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
-API CreateSemaphore in api-ms-win-core-kernel32-legacy-l1-1-0.dll is not supported for this application type. System.Threading.dll calls this API.
-API ExecuteAssembly in uwphost.dll is not supported for this application type. StupidTest.exe calls this API.
-API DllGetActivationFactory in uwphost.dll is not supported for this application type. StupidTest.exe has an export that forwards to this API.
An empty project suffers the same failure if Compile .Net Native tool chain is not selected.
So my questions:
Must Universal Apps use Compile .Net Native tool chain?
Is there any documentation on the meanings of the parameters in the internal exception or somewhere else I can turn to troubleshoot?
In short, any advice on getting out the "It doesn't work if selected, but you must select it to get certified" dilemma I find myself in?
I struggled with this issue also for the past few days, and I've found the answer!
So if you haven't updated Visual Studio 2015 to Update 1, do it. Because this error is a bug in the compiler and after the update you will be able to build the project with the Compile .Net Native tool chain option selected.
And yes, those four errors that the WACK tool picks up, is because of compiling your project without checking the .Net Native tool chain option in the Build menu of the Package.appxmanifest file.

GTK# + WebKit + Windows

I have developed a GTK# application that makes use of webkit-sharp to edit email templates. This application works in Linux but when it is run in Windows it does not work. I am using the webkit-sharp.dll from Linux in Windows. The error that I am getting is:
System.TypeInitializationException: The type initializer for 'WebKit.WebView' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'webkit-1.0': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at WebKit.Download.webkit_download_get_type()
at GtkSharp.WebkitSharp.ObjectManager.Initialize()
at WebKit.WebView..cctor()
--- End of inner exception stack trace ---
at WebKit.WebView..ctor()
at MainWindow..ctor()
I am guessing that webkit-sharp.dll only wraps the native libraries for WebKit. I do not know where to get "webkit-1.0". Is there a webkit-sharp.dll that is specific to Windows for GTK#?
I did exactly that. I guess the webkit windows dll does not use gtk as rendering engine.
What I did was install the libwebkit dll provided by the suse mingw32 port and all of its dependencies.
You can see a full list of dependencies here
At the time of doing it(1 year ago more or less) the rendering was not perfect, but it may have improved.
I'm also having this problem...
Not tried this, but at http://www.webkit.org/building/checkout.html
The site suggests:
Download webkit support libraries
Run the update-webkit script
Build webkit from source
I think this requires cygwin installed.
I'm just paraphrasing the site - not tried this yet.
Have you tried running the Hello World example app to make sure everything is set up correctly in your Windows environment?
http://mono-project.com/Mono_Basics
You can also try some of the other example programs to make sure they function without error.
http://www.mono-project.com/GtkSharpBeginnersGuide
Seems like a common installation issue requires the addition of an environment variable in windows to get the assemblies loaded correctly:
http://www.mono-project.com/FAQ:_General#Installation_Problems

Categories