I'm creating a Windows 8 Store App. The front-end (main project) of this app is in HTML5/Javascript. And I'm following this guide by Tim Heuer to create a C# WinRT component that wraps SQLite calls and behave as a controller. The front-end calls this component via Javascript, to update data, and get presentation content.
So there are 2 projects in my solution, 'main' in javascript, and 'db' in C#. I've managed to get SQLite working according to the guide. The reason I have this structure is that I'm trying to port an app from iOS to Win8. The 'controller' part is an isolated component from the get-go, and it's already ported to C#.
However, there is one caveat. Because of this known problem, I have to remove the reference to C++ Runtime v11 from the 'db' project to make it compilable. Though it runs fine in the development machine.
Then I got this test machine (samsung xe700t1a to be exact, Intel i5), I discovered that when 'debugging remote' on this test machine, Visual Studio won't deploy SQLite3. As a result, my SQLite calls fail with error: "Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)".
According to the guide I mentioned previously, the point SQLite was made available via WinRT extension, is to make deployment automatic.
I'm wondering why this happens and how to make it correct? I'm also wondering if there's any certification problems for Windows Store for apps in this structure?
I also came across this post and this post suggesting that it's currently not possible to use SQLite in a WinRT component. But it's too late for me to change now, and this project won't be possible without a hybrid structure.
I found the solution. I used the hint from this post, and it's very straightforward.
What I have to do, is to create another project in the solution, with Output Type set to C# Class Library. Move the reference to SQLite for WinRT, and sqlite-net (nuget) wrapper to this new project. After that, I have to manually go through classes in sqlite-net, and change all the 'internal' classes to 'public'.
For the original controller project, I add using myclasslib; so that class definitions are found.
Apparently this workaround will work flawlessly. SQLite3 is deployed, and there's no warning against missing reference.
Related
I develop applications targeting the Hololens 2 platform (mixed reality).
The general idea of the application I am trying to build is using a point cloud registration algorithm, which targets a previously scanned model on one hand and the visible point cloud generated by the Hololens' SceneUnderstanding ability on the other.
My main problem is that all the different implementations that I found of the algorithm are using libraries (DLLs) that:
Uses a lower-level language (C++) than the C# scripting language used in Unity's scripts.
Are not targeting the needed configuration and architecture needed for deploying an application on the Hololens 2 (Master configuration, ARM64 architecture).
In the process of trying to generate that kind of library myself (using visual studio 2019 to build "Dynamic-Link Library with Exports [DLL]"),
I created the simplest library in C++ - A single function that returns an integer (without the dependency of any other library). Obviously, when targeting the Unity Editor application it was easy to use the library's function from the C# script attached to the Unity project, but when I try to convert the solution's configuration and architecture to Master ARM64, building a Visual Studio solution and deploying the application on the Hololens 2 generates a script error: "Unable to load DLL '<dll_name>': The specified module could not be found."
I can think of two major reasons that will cause this problem:
The program can not find the library needed for function execution,
JUST BECAUSE the location of the library is not correct (I have NO IDEA
where the library should be placed in the solution hierarchy).
I am probably not using the right technique for converting the library to the correct target solution properties (in addition of the previous scenario)
(and as well, I have no idea what is the correct procedure for achieving correct targeting properties)
Using: Visual Studio 2019, Unity 2019.4.1f1, Hololens 2nd generation
It would mean a lot to hear from anyone who have encountered any sort of similar problem, thank you in advance!
To add a custom DLL to a Unity project for HoloLens 2, you have to copy the DLL to a folder called Assets/Plugins/WSAPlayer/ARM64 in your project hierarchy in Unity. Then, you should also make sure that the correct Platform settings are specified for the Plugin in the Inspector, i.e., SDK should be set to UWP and CPU to ARM64:
This git repo has an example of this (DLL and Unity project).
Note that the DLL has to be compatible with Universal Windows Platform (UWP), so when creating a new library with Visual Studio, you should select either the DLL (Universal Windows) or Windows Runtime Component project templates as your starting point.
If you add any dependencies to your DLL, e.g., for point cloud registration, you will also have to build those libraries for UWP / ARM64, and add those DLLs to the same folder as well!
I have an proprietary Android app (created with Android Studio) and I need to add some functionality which requires to use a C# DLL.
The app is connecting wirelessly to a development board that does some sensor measurements. Normally on windows apps the dll is used to do some complex calculations of calibration coefficients for the measuring.
My problem is:
I don't have the the source code of the DLL and most likely I won't be approved to access it.
I've read that you can use xamarin to make android apps and use C# dlls but I can't rewrite the whole app for xamarin just to use the dll (also I've never used xamarin)
So far I had the idea to build a simple http server with C# that gets parameters with a GET request, runs them through the dll and returns the results. However it's not an ideal solution because it requires a separate pc to run the server and the adndroid device to have a network connection to it.
My second idea is to build a separate app with xamarin that uses the dll and make my main app start it just to calculate the coefficients and get the results. Perhaps make the second app not visible in the launcher and somehow distribute the two apps together.
Since I am not experienced with android development and especially xamarin and I don't have a lot of time to waste on this project I want to know if my idea is feasible or if there is a better alternative.
Can you suggest some useful tutorials for xamarin and using dlls with it?
===============================================
Edit
I have managed to get the source code of the dll project which is in C++ (and full of windows only stuff) and now I'm trying to use NDK to compile it and JNI with Android studio to use the native functions. Unfortunately almost every step has it's own quirks and problems and it's far from smooth :/ I wouldn't recommend it to beginners like me!
I know this answer is late, but I'm in a similar situation right now.
This project here helped me setup a native Android Studio build with an embedded C# lib:
https://github.com/royd/KotlinAppWithXamarinDependency
The only issue I'm facing right now, that I can't get the R8 obfuscation/optimization to work without breaking the app.
We have a Xamarin cross-platform app that is using a custom Portable Class Library to interface with our company's API. The issue we are experiencing is that when we make a request through the PCL using the app on the iOS Simulator, everything works as expected, but when we try to do the same thing on an actual device, we get a "Bad Request" error code back from our API.
We have been able to determine that when the app is running on the device, the body parameters in the post we are making are null, but when we do the same thing on the simulator, the parameters have the values we have passed in.
Our PCL is using System.Net.HttpClient, so we thought that this answer might help: HttpClient failing
Sadly, this didn't work because it appears that Xamarin apps don't use an app.config file anyway.
We have tried checking to make sure that both our PCL and our iOS project are referencing the same version of System.Net.HttpClient, but this doesn't seem to fix the issue either.
We also tried the workarounds in the following bug report to no avail: https://bugzilla.xamarin.com/show_bug.cgi?id=20589
This article had helped us in the past, but it doesn't seem to be helping this situation:
HttpClient missing from .Net portable subset while creating PCL in Xamarin
There are several differences when an application runs on the simulator and on a device.
One of them is that the managed linker is disable on simulator builds (it's faster when the JIT is used) while it's enabled for device builds (same logic: it's faster for AOT builds).
It's possible that your application uses reflection (directly or indirectly) and needs to preserve some members (e.g. serialization).
You can try this by either enabling the managed linker on the simulator build (or disabling it on device builds). That will tell you if your issue is related to the managed linker (or not).
I try to reference facebook.dll - wp8 branch - within an app of type "Windows Phone Direct3D App (Native only)" project under Visual C++ VS2012, and I get the error:
a reference to [dllname] cannot be added because the two projects
target different runtimes.
The restriction is that I cannot change the architecture of the application, so the main entry-point must be in the C++ project, and from here to call somehow the code written in C# for facebook.
Based on http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714080(v=vs.105).aspx , I tried also to reference the C# dll indirectly through a Visual C++ "Windows Phone Runtime Component" but again I get the same error. I tried to change some project settings and nothing worked. Trying to consume C# dll in C++, in all samples and demos which I found on the web, for wp8, the main entry-point is always in C#. Only some hints regarding windows store apps seem to indicate that could be possible to consume C# from C++, but I don't find any reference saying explicitly that my scenario on wp8 is possible or impossible.
How can I use facebook SDK from my WP8 app? Or what options I have?
Thanks in advance to anybody which shares the solution or any suggestion
C++ projects can't just invoke any C# DLL in WP8. You'll have to change how the class is built. Start a new C# XAML + C++ D3D project and have a look at IDrawingSurfaceManipulationHandler and Direct3DInterop. Basically you'll have to recreate and recompile the Facebook C# SDK to use it in WP8 C++.
However, installing and using the Facebook SDK on WP8 C# projects works OK on my machine. Have you considered usign a mixed C# and C++ project? It does have a small perf hit, but as long as you use DrawingSurfaceBackgroundGrid you should still have relatively good perf.
I am new to Windows 8 App Store development and have bumped into something strange.
If I create a normal .net library (signed library) and attempt to add it to my Windows Store application, Visual Studio 2012 moans that I can't add this project. Both projects are in the same solution.
This project contains a reference to the System.Net assembly, as I use some of the types from there. I know that System.Net is not a fully supported namespace. TcpClient, NetworkStream, etc have all been removed. I also know that StreamSocket, DataReader and DataWriter in the Windows.Networking namespace is the alternative.
Before I loose you, let me get to the point. Instead of adding the compiled assembly from this project as a project reference to the Windows Store application, I browse for the compiled assembly on my hard drive and reference the assembly directly.
To my surprise, this worked! This leads me to the following questions:
Why? That doesn't make sense to me. Someone please explain.
Also, if I use this library, will the Windows Store reject my application? Answering the second question myself... Answer is YES! Windows Certification App, no longer recognises this as a Windows Store App if the mentioned library is referenced.
There are a couple ways to add an assembly reference to a project:
Add assembly reference to a project in same solution.
Browse for an assembly somewhere on your hard drive.
In Visual Studio 2012, if you add a non compliant WinRT assembly reference to a WinRT project, Visual Studio 2012 won't allow it.
However, if you add the same assembly to the WinRT project by browsing on your hard drive, the assembly is referenced successfully. This only works if the referenced assembly is signed with a strong key. I'm not sure if this is a flaw in the product or intentional.
Microsoft makes up for this flaw (if it infact is one) later on when passing your Windows Store App through certification. Certification fails because it recognises that an assembly has been referenced in the project which is not appropriate for a Windows App Store product.
So in summary, you can NOT reference WinRT assemblies in your WinRT projects. The drawback with doing this is that your app will fail Windows App Store validation. The advantage with this is if you are not developing a Windows App Store product, you can re-use work you've already done.