SQLitePCL.raw
SQLitePCL.raw copied to clipboard
MissingMethod exceptions on Xamarin Targets
This seems to happen with later versions of VS2019 and VS2022
But when moving the same app with no modification on VS 2022, I get a
System.MissingMethodException: Method not found: int SQLitePCL.raw.sqlite3_bind_blob(SQLitePCL.sqlite3_stmt,int,System.ReadOnlySpan1)'
It wasn't happening before then. Only happens on certain Xamarin targets.
Here are some other links to repos where the issue is happening https://github.com/praeclarum/sqlite-net/issues/1074 https://github.com/reactiveui/Akavache/issues/735
There is a minimal repro in this closed issue which was a duplicate https://github.com/reactiveui/Akavache/issues/738
I've released a new version of Akavache with all the latest libraries and built with VS2022 but doesn't seem to help users
When building the repro project, I see a bunch of warnings about conflicting versions of SQLitePCLRaw stuff.
It is interesting to note that the new Akavache release mentioned above seems to have resolved another issue here, #461
Overall, it seems likely that the problem here is related to multiple versions of SQLitePCLRaw in play, but (1) I am not yet certain of that, and (2) I don't yet see how the change from VS 2019 -> 2022 would trigger the problem.
I wonder if Microsoft is including sqliteraw as part of the IDE build now or something and that's overriding it. Will investigate that one today
@glennawatson FWIW, I sort of doubt that path of investigation will be fruitful.
SQLitePCLRaw is indeed part of the IDE, as it is used by the Roslyn compiler. But that has been true for years, well before VS 2022 came on the scene, and I have never seen a problem where Roslyn's use of the package interfered with the assembly references for user projects.
My guess is that switching to VS 2022, which involves the .NET 6 SDK, is perhaps bringing in some aspect of the new style Xamarin workloads.
I've tested with .NET 6 and everything is fine, but I know I have issues yet to be fixed with the new Xamarin workloads, but^2 it was my understanding that these wouldn't come into play until MAUI, which was delayed. But if that last clause is not true and more Xamarin-y things changed with .NET 6 than I thought, then that is a likely source of problems.
I do plan to look into this soon, but I had meetings scheduled for today and wasn't able to make much progress yet.
@ericsink If it helps, the problem also happens on VS 2019 version 16.11.6.
Earlier I said:
it seems likely that the problem here is related to multiple versions of SQLitePCLRaw in play
but I think I was mistaken. The warnings I mentioned were caused by a glitch that was specific to my machine.
OK, The missing method should be in SQLitePCLRaw.core.dll, so I decided to find that assembly in the build output and confirm that it is there.
But I haven't done Android in a while, and I couldn't find the build output in the bin directory.
So I built an APK archive and unzipped it. The file I wanted was in the assemblies directory, but it's the wrong size. And ILSpy says it's not even an assembly. So that's weird.
I'm using the repro project mentioned above, in VS 2022. I've updated the Akavache nuget package. I'm using a default-ish Android emulator, a Pixel 5, API 30, which Visual Studio offered to setup for me yesterday.
When I run the app in Debug, I see the MissingMethod exception.
When I run it in Release, it seems to work fine, with no exception.
Anybody else seeing this?
@ericsink As far as I was able to verify, the error only happens on debug. The release versions builded through azure pipelines did not report the error. Since then I downgraded VS from 16.11.6 to 16.10.4 to continue debugging without issues.
FWIW, I updated Visual Studio to 17.0.2 and it did not fix the problem.
Here's a content-free update just to say that I have not forgotten this issue but so far I am stumped.
It's possible this is a bug in Xamarin tooling. After all, things worked, and then they stopped, and it was Visual Studio that changed, not SQLitePCLRaw. If the bug is in Xamarin, it seems likely that other projects might be suffering from similar symptoms.
It's also possible that the problem is in my code. For example, perhaps I've been doing something "wrong" all along, and until recently, Visual Studio was choosing to overlook my transgression, but now it is stricter.
I am getting the same error in my project (VS 2022 17.0.1)
System.MissingMethodException: Method not found: int SQLitePCL.raw.sqlite3_bind_blob(SQLitePCL.sqlite3_stmt,int,System.ReadOnlySpan`1
@Geronatsios Do all of the details of your situation match the others here?
It happens on Android?
Does it happen on any other platform?
It only happens on debug builds?
Akavache is involved?
Note (mostly to myself):
If in fact
praeclarum/sqlite-net#1074
is the same issue, then the problem is NOT specific to Android, and may not be specific to situations involving Akavache.
Right now it feels like I'm missing something fairly obvious, and I'm going to feel really stupid when I realize it.
Visual Studio 2022 17.0.3 just released, and it seems to have resolved the issue for me. I noticed an issue in the release notes, Bug in Visual studio 2022 + Xamarin + SignalR (method not found), that seems to have been the culprit.
@rhinosafari Wow, I do hope that update resolves the problem for everybody. :-)
https://developercommunity.visualstudio.com/t/Bug-in-Visual-studio-2022--Xamarin--Si/1528510
I confirm in VS 2022 17.0.3 release it seems to have resolved the issue for me.
VS 2022 17.0.3 fixed this issue for me as well.
VS 2022 17.0.4 Not Working.
{Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.MissingMethodException: Method not found: int SQLitePCL.raw.sqlite3_bind_blob(SQLitePCL.sqlite3_stmt,int,System.ReadOnlySpan1<byte>) at Microsoft.Data.Sqlite.SqliteValueBinder.Bind () <0x114452128 + 0x000d6> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteParameter.Bind (SQLitePCL.sqlite3_stmt stmt) <0x114442830 + 0x000b8> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteParameterCollection.Bind (SQLitePCL.sqlite3_stmt stmt) <0x114441da8 + 0x0003c> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteCommand+<GetStatements>d__54.MoveNext () <0x113fcc7e0 + 0x000a8> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteDataReader.NextResult () <0x113fcb6c0 + 0x00246> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader (System.Data.CommandBehavior behavior) <0x113fc34d8 + 0x0014e> in <40b83140d09f43f4b6250353f77e03ed>:0 at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReader (System.Data.CommandBehavior behavior) <0x1125e26f0 + 0x0000a> in <40b83140d09f43f4b6250353f77e03ed>:0 at System.Data.Common.DbCommand.ExecuteReader () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Data.Common/src/System/Data/Common/DbCommand.cs:110 at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader (Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject) <0x1125d8be8 + 0x00234> in <53c13ae0c80f4b2784ab381628f2ecf7>:0 at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute (Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) <0x11faa1f50 + 0x0008a> in <53c13ae0c80f4b2784ab381628f2ecf7>:0 --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute (Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) <0x11faa1f50 + 0x0012c> in <53c13ae0c80f4b2784ab381628f2ecf7>:0 at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute (System.Collections.Generic.IEnumerable
1[T] commandBatches, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) <0x11f3722f8 + 0x0020e> in <53c13ae0c80f4b2784ab381628f2ecf7>:0
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges (System.Collections.Generic.IList1[T] entries) <0x11f37c728 + 0x0007c> in <53c13ae0c80f4b2784ab381628f2ecf7>:0 at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges (System.Collections.Generic.IList
1[T] entriesToSave) <0x11f37c0d0 + 0x00040> in 3[Microsoft.EntityFrameworkCore.DbContext,System.Boolean,System.Int32].invoke_TResult_T1_T2(Microsoft.EntityFrameworkCore.DbContext,bool) at Microsoft.EntityFrameworkCore.Storage.NonRetryingExecutionStrategy.Execute[TState,TResult] (TState state, System.Func
3[T1,T2,TResult] operation, System.Func`3[T1,T2,TResult] verifySucceeded) <0x11f89ea00 + 0x00028> in
I am on VS 2022 17.0.5 and the issue is happening for me on iOS.
Disabling Hot Reload, as suggested in one of the above links, does not work :(
It also does not work in Release mode.
@glennawatson So are you folks over in Akavache land seeing a regression? Like it was fixed in 17.0.3 and then broken again?
On this page another user discovered that installing System.Memory 4.5.2
via Nuget fixes this issue. The issue appears in 4.5.3
I have VS 17.1.0 and in iOS only , blobcache is null not init
any news ? for problem....in VS 17.1. @ericsink
Haven't seen anything @ericsink
Extra details :
- It happens on Android? No
- Does it happen on any other platform? yes in iOS only in the real DEVICES , in emulators it works
- VS 17.1
- I can't downgrade System.Memory 4.5.3 (akavache version 8.1.1 depends >= 4.5.3)
I have VS 17.1
Only in iOS devices I am getting this error :
Method not found: int SQLitePCL.raw.sqlite3_bind_blob(SQLitePCL.sqlite3_stmt,int,System.ReadOnlySpan`1
Akavache.Registrations.Start("AppName");
BlobCache.ApplicationName = "AppName";
BlobCache.EnsureInitialized();
//register:
var cacheInstanceHelper = DependencyService.Get<IBlobCacheInstanceHelper>();
Locator.CurrentMutable.Register<IBlobCacheInstanceHelper>(() => cacheInstanceHelper);
cacheInstanceHelper.Init();
Cache = cacheInstanceHelper.LocalMachineCache;
Profile profile = new Profile() { name = "Bill" };
try {
Cache.InsertObject("myProfile", profile);
catch(Exception ex){
}
public class PlatformBlobCacheInstanceHelper : IBlobCacheInstanceHelper
{
private IFilesystemProvider _filesystemProvider;
public PlatformBlobCacheInstanceHelper() { }
public void Init() {
_filesystemProvider = Locator.Current.GetService<IFilesystemProvider>();
GetLocalMachineCache();
}
public IBlobCache LocalMachineCache { get; set; }
private void GetLocalMachineCache() {
var localCache = new Lazy<IBlobCache>(() => {
_filesystemProvider.CreateRecursive(_filesystemProvider.GetDefaultLocalMachineCacheDirectory()).SubscribeOn(BlobCache.TaskpoolScheduler).Wait();
return new SQLitePersistentBlobCache(Path.Combine(_filesystemProvider.GetDefaultLocalMachineCacheDirectory(), "blobs.db"), BlobCache.TaskpoolScheduler);
});
this.LocalMachineCache = localCache.Value;
}
}
Do you plan to resolve this error @ericsink ?
I have already this class in iOS and Android
public static class LinkerPreserve { static LinkerPreserve() { //throw new Exception(typeof(SQLitePersistentBlobCache).FullName); var persistentName = typeof(SQLitePersistentBlobCache).FullName; var encryptedName = typeof(SQLiteEncryptedBlobCache).FullName; } } public class PreserveAttribute : Attribute { }
It is my understanding that this problem is due to a bug in Mono. The following link (also posted in a comment above) contains more information:
https://developercommunity.visualstudio.com/t/Bug-in-Visual-studio-2022--Xamarin--Si/1528510
In terms of "things that might make the bug go away", that page mentions some people having success with turning off XAML Hot Reload?
I don't currently know of any way I could even do a workaround.
Some latest news for my problem :
- I buld iOS in mac book and visual studio 2019 for mac and i don't have the previous problem. (In Real device iphone)
Forcing your project to use System.Memory, version 4.5.2 somehow works around the problem.
I'm running into this same System.MissingMethodException. I'm unable to downgrade System.Memory due to another package dependency. Any progress on this issue?
Btw, works on Android. I'm using VS 2022 17.1.4. Xamarin Forms 5.0.0.2401. Hot Restart to deploy from PC to iPhone 7.
No progress that I know of. All indications are that this is a bug in the .NET/iOS code. It affects other projects, not just SQLitePCLRaw. To make progress, what probably needs to happen is a well-written bug report in the https://github.com/xamarin/xamarin-macios repo. AFAIK, that hasn't happened yet.
This problem is maaaaaaybe related to xamarin/xamarin-macios#12416 ?
Forcing your project to use System.Memory, version 4.5.2 somehow works around the problem.
Como?