SQLitePCL.raw icon indicating copy to clipboard operation
SQLitePCL.raw copied to clipboard

Debug local iphone results in file is not a database

Open whann0205 opened this issue 1 year ago • 9 comments

The following packages are in use: PackageReference Include="sqlite-net-sqlcipher" Version="1.9.172" /> PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8" /> PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.8" /> It is a net maui application targetting .net8. Everything is kept up to date. Problem is that the app cannot access the database. The file get installs by using openfile OpenAppPackageFileAsync somewhere in the initialization section of the app. It is proven that the file is indeed here and accessible, have even copied the file via SMB to my File Server to check if it get installed correctly. The file is a sqllite4 format with encryption. It is working perfectly on android device, android emulator, ios emulator no matter which emulated device. it works on the mac itself, too. Not tried to deploy as a release yet. But when i try to debug the app on the iphone via hot restart (visual studio 2022 17.10.3) the file is there but i throws the exception "File is not a database". I really dont know where to start since i dont know if the problem is inside your library or praeclarum or where ? I am stuck do whatever it takes to solve that problem.

whann0205 avatar Jul 03 '24 12:07 whann0205

@whann0205 You need to disable hot restart under VS iOS Settings. When that feature is enabled it skips the native linking step within Xcode on the paired mac. That results in the application using the built-in SQLite which does not include encryption features.

sjlombardo avatar Jul 05 '24 19:07 sjlombardo

If i disable hot restart under Xamarin/IOS Settings i can no longer select IOS local devices and my iphone in order to debug the application. As i wrote this is the only problem i have. The Simulators all works without a problem. As i understand the local debug does not need to have a paired mac. Is there any other way to instruct VS not to link to the bultin-SQLite?

whann0205 avatar Jul 07 '24 18:07 whann0205

@whann0205 I'm not aware of any.

One option would be to plug your iOS device into the paired mac, and then debug it that way.

If you don't have a paired mac, then you could run your "debug" profile without encryption.

sjlombardo avatar Jul 08 '24 14:07 sjlombardo

That helped me in July, again thank you! Came across that annyoing problem again. Who should be informed of that problem dotnet maui, ios repository, visual studio bug reporting?

whann0205 avatar Oct 04 '24 06:10 whann0205

@whann0205 I'm not really sure who it would be best to report this too. While it's not ideal, I believe this is actually working "as intended" given that the hot restart functionality using the local development environment where it is not even possible to link native libraries. Out of curiosity @ericsink, do you think this warrants being reported as a bug somewhere?

sjlombardo avatar Oct 04 '24 17:10 sjlombardo

i tried to create a release version with visual studio code and there seem to be the problem again. Unfortunealy i dont know how to solve that with vs code since there is no setting to disable hot restart is there?

whann0205 avatar Oct 22 '24 19:10 whann0205

Ooops -- just noticed the question from @sjlombardo that I failed to see earlier.

But the answer is that I don't know. I know little (maybe nothing) about hot restart. :-(

ericsink avatar Oct 22 '24 20:10 ericsink

If you look at https://www.zetetic.net/sqlcipher/sqlcipher-for-dotnet/ there it says "or iOS, it is important to ensure that the linker does not operate on the packaged assemblies. The easiest and recommended way do this is to set the project Linker Behavior to either Link SDK assemblies only or Don't Link. Using Link all assemblies can result in runtime failure. If you use Link all assemblies for the smallest possible executable size, then configure a linker description file to exclude all SQLCipher assemblies from linking. You will also need to call one additional method, SQLitePCL.lib.embedded.Init(), to instruct the linker to properly bundle SQLCipher, i.e." So these guys are aware of the problem, too. Is that useful for us here too? If so how can i setup these things in vscode?

whann0205 avatar Oct 23 '24 04:10 whann0205

So is it possible to make an IOS release with VSCode with that library if your database is encrypted? I need to create a test version for a customer and that blocks me from going on, is there anybody who can help me out?

whann0205 avatar Oct 28 '24 10:10 whann0205