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

MissingMethod exceptions on Xamarin Targets

Open glennawatson opened this issue 3 years ago • 36 comments

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

glennawatson avatar Nov 27 '21 01:11 glennawatson

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.

ericsink avatar Nov 29 '21 20:11 ericsink

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 avatar Nov 30 '21 01:11 glennawatson

@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 avatar Nov 30 '21 01:11 ericsink

@ericsink If it helps, the problem also happens on VS 2019 version 16.11.6.

Luiz-Franco avatar Nov 30 '21 11:11 Luiz-Franco

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.

ericsink avatar Nov 30 '21 15:11 ericsink

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.

ericsink avatar Nov 30 '21 15:11 ericsink

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 avatar Nov 30 '21 15:11 ericsink

@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.

Luiz-Franco avatar Nov 30 '21 19:11 Luiz-Franco

FWIW, I updated Visual Studio to 17.0.2 and it did not fix the problem.

ericsink avatar Dec 01 '21 21:12 ericsink

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.

ericsink avatar Dec 06 '21 18:12 ericsink

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).... Any news ?

Geronatsios avatar Dec 14 '21 17:12 Geronatsios

@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?

ericsink avatar Dec 14 '21 19:12 ericsink

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.

ericsink avatar Dec 14 '21 20:12 ericsink

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 avatar Dec 14 '21 21:12 rhinosafari

@rhinosafari Wow, I do hope that update resolves the problem for everybody. :-)

ericsink avatar Dec 14 '21 22:12 ericsink

https://developercommunity.visualstudio.com/t/Bug-in-Visual-studio-2022--Xamarin--Si/1528510

glennawatson avatar Dec 14 '21 22:12 glennawatson

I confirm in VS 2022 17.0.3 release it seems to have resolved the issue for me.

Geronatsios avatar Dec 14 '21 23:12 Geronatsios

VS 2022 17.0.3 fixed this issue for me as well.

EmmanVazz avatar Dec 14 '21 23:12 EmmanVazz

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.IEnumerable1[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.IList1[T] entriesToSave) <0x11f37c0d0 + 0x00040> in :0 at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges (Microsoft.EntityFrameworkCore.DbContext _, System.Boolean acceptAllChangesOnSuccess) <0x11f89f208 + 0x000de> in :0 at (wrapper delegate-invoke) System.Func3[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.Func3[T1,T2,TResult] operation, System.Func`3[T1,T2,TResult] verifySucceeded) <0x11f89ea00 + 0x00028> in :0 at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges (System.Boolean acceptAllChangesOnSuccess) <0x11f89e688 + 0x00074> in :0 at Microsoft.EntityFrameworkCore.DbContext.SaveChanges (System.Boolean acceptAllChangesOnSuccess) <0x11f2dec88 + 0x0022e> in :0 at Microsoft.EntityFrameworkCore.DbContext.SaveChanges () <0x11f2de348 + 0x00008> in :0 at BP.Mob.SalesExpress.ViewModels.Sincronizacao.UiSincronizacaoViewModel+<>c__DisplayClass23_1.<ExecTAsync>b__2 (BP.Mob.SalesExpress.ViewModels.Obj.ColaboradorViewModel item) [0x00509] in C:\Users\kizar\source\repos\messiassouza\BytePoucH\BP.Mob.SalesExpress\BP.Mob.SalesExpress\ViewModels\Sincronizacao\UiSincronizacaoViewModel.cs:282 }

messiassouza avatar Jan 06 '22 13:01 messiassouza

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.

BlueRaja avatar Feb 01 '22 01:02 BlueRaja

@glennawatson So are you folks over in Akavache land seeing a regression? Like it was fixed in 17.0.3 and then broken again?

ericsink avatar Feb 01 '22 15:02 ericsink

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

BlueRaja avatar Feb 05 '22 00:02 BlueRaja

I have VS 17.1.0 and in iOS only , blobcache is null not init

Geronatsios avatar Feb 17 '22 10:02 Geronatsios

any news ? for problem....in VS 17.1. @ericsink

Geronatsios avatar Feb 18 '22 12:02 Geronatsios

Haven't seen anything @ericsink

glennawatson avatar Feb 18 '22 12:02 glennawatson

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)

Geronatsios avatar Feb 18 '22 13:02 Geronatsios

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) when trying to insert an object in the cache...

            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 { }

Geronatsios avatar Feb 21 '22 21:02 Geronatsios

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.

ericsink avatar Feb 21 '22 22:02 ericsink

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)

Geronatsios avatar Feb 23 '22 13:02 Geronatsios

Forcing your project to use System.Memory, version 4.5.2 somehow works around the problem.

nemekzg avatar Mar 29 '22 07:03 nemekzg

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.

kkppstudios avatar Apr 18 '22 14:04 kkppstudios

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.

ericsink avatar Apr 18 '22 15:04 ericsink

This problem is maaaaaaybe related to xamarin/xamarin-macios#12416 ?

ericsink avatar Apr 18 '22 15:04 ericsink

Forcing your project to use System.Memory, version 4.5.2 somehow works around the problem.

Como?

messiassouza avatar May 30 '22 14:05 messiassouza