question

noobsoftware-5390 avatar image
0 Votes"
noobsoftware-5390 asked noobsoftware-5390 answered

System.ArgumentNullException: Value cannot be null in Microsoft.Data.Sqlite when compiling with .Net native toolchain

Everything works without .Net native toolchain then I was getting this error when building with .net native toolchain:

Error RHBIND : error RHB0011: Internal error: 'pchTypeNameEnd[0] == L'>'' at 'f:\dd\ndp\rh\src\tools\rhbind\makepdb.cpp:968' appname.UWP Error ILT0005: '...\packages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\tools\x86\ilc\Tools\rhbind.exe @"...\obj\x86\Release\ilc\intermediate\rhbindargs.appname.UWP.rsp"'

I was able to fix that by altering default.rd.xml by removing <Assembly Name="*Application*" Dynamic="Required All">
And adding assemblie references by hand and adding DoNotOptimize="True" for example:

<Assembly Name="System" Dynamic="Required All" DoNotInline="true" DoNotOptimize="true" />

After doing that i keep getting this error with Sqlite:

System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Reflection.IntrospectionExtensions.GetTypeInfo(Type) + 0x7b
at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize() + 0xb3
at Microsoft.Data.Sqlite.SqliteConnection..cctor() + 0x8
at System.Runtime.CompilerServices.ClassConstructorRunner.Call(IntPtr) + 0x89
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x247

--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x351
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstruction(Void*, StaticClassConstructionContext*) + 0x17
at Microsoft.Data.Sqlite.SqliteConnection..ctor(String) + 0x44
at noobcloud.local_data.init(String) + 0x19e

connection was null.

I've noticed that i get:

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
With e_sqlite3, but it's copied to the output directory. Maybe that's related to this issue.


I've tried adding assemblies to Xamarin.Forms.Init(e, assemblies) and adding assemblies to default.rd.xml without success. My first thoughts since the type is null is that the assembly is not getting loaded correctly, but i have no idea how to confirm that and it seems to make no difference if i include Microsoft.Data.Sqlite in default.rd.xml or not.

Any help is appreciated. Thanks.

dotnet-xamarinwindows-uwp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@noobsoftware-5390 Based on the above information, there is no way could reproduce it. Therefore, my suggestion is that you could try to enable the .Net native toolchain in Debug mode to test it and find where the error occurred? Such as the specified code or some steps.

0 Votes 0 ·

I have tried it in debug and the "connection was null" error occurs when trying to perform an Sqlite query.. The Value cannot be null exception occurs when trying to establish an sqlite connection:

this.connection = new SqliteConnection("Data Source="+path); this.connection.Open();

I can create a test-project reproducing the error and share it on github if you find that helpful. The steps to reproduce: Add Microsoft.Data.Sqlite nuget package to Xamarin.Forms project and UWP project, add PeachPie.Library and PeachPie.Runtime nugets to both projects, add SQLitePCLRaw.provider.e_sqlite3.uwp to UWP project. Create a sqlite connection and try a dummy query in debug or release without .net native toolchain enabled, then enable .net native toolchain observe RHBIND error. Then change default.rd.xml by removing the application assembly reference than add by hand to default.rd.xml. i'll upload a project soon and send it as well.

0 Votes 0 ·

1 Answer

noobsoftware-5390 avatar image
0 Votes"
noobsoftware-5390 answered

I was able to fix the original issue by moving all php files out of directories and to the root of the project in my peachpie library project.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.