Reputation: 1129
I have a xamarin forms solution, where I have everything working, except for physical iOS devices. It works 100% on emulated iOS, Android, and physical Android devices, but not physical iOS devices.
Let me elaborate. The solution runs on physical iOS Devices and it goes to a login screen, where I then connect to my database and login. This works on everything except physical iOS devices.
The error that I get is:
The type initializer for 'Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators.Internal.SqlServerCompositeMethodCallTranslator' threw an exception.
The inner exception:
Value cannot be null.
Parameter name: key
This is the stack trace:
at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x00008] in <c4da4bcb0a614f31bf9f25261a36b747>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <c4da4bcb0a614f31bf9f25261a36b747>:0
at Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators.Internal.SqlServerDateAddTranslator..ctor () [0x000c5] in <841b527f2aa54cccaf5150a4cca376c9>:0
at Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators.Internal.SqlServerCompositeMethodCallTranslator..cctor () [0x00016] in <841b527f2aa54cccaf5150a4cca376c9>:0
I am using Entity Framework Core 2.1.2 and my target framework, on my data project, is .NET Standard 2.0
Why would a physical iOS Device be different from a emulated one?
What can I do to get past this error?
Is there anyway that I can find out what value it is finding to be null?
Edit
I found out that my problem is that I am not connecting to my database. Though I can't figure out what is wrong with my connection.
Is there anything wrong with this method of connecting to a sql server?
(Note: the dev and main DB are correct as everything else works just fine using those connection strings)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
//optionsBuilder.UseSqlServer(
// "System.Data.SqlClient",
// options => options.EnableRetryOnFailure(1, TimeSpan.FromSeconds(30), null));
string cn;
if(Debugger.IsAttached)
{
cn = devDB;
}
else
{
cn = mainDB;
}
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder();
cns.ConnectionString = cn;
optionsBuilder.UseSqlServer(cns.ConnectionString, options => options.EnableRetryOnFailure(1, TimeSpan.FromSeconds(60), null));
}
Upvotes: 2
Views: 1757
Reputation: 2119
Why would a physical iOS Device be different from a emulated one?
The answer is in your question :) At first - iOS uses Simulator, not emulator. :) The difference is that the simulator does not try to emulate the real performance of the device (clock speed, i/o, and etc). It would allocate the RAM of the device (like on iPhone 5S it would show you 512MB of maximum RAM, but in iPhone X 2 GB). But for everething else, it would use the full performance of your machine (like CPU or writing/reading speed).
Anyway, the main problem is that in order to run the app in the simulator you need all frameworks to be built for x86 architecture. That the problem. Sometimes people do not build the library for mobile or desktop architecture. You are very lucky that you did not face that problem so far :))) The difference in build process may introduce unpredictable bugs, so it's always a MUST to test on the device.
What can I do to get past this error?
It's hard to tell because the error message is so generic. I would personally begin by making sure that DB is present on the device and my code could at least open a connection to it.
Is there anyway that I can find out what value it is finding to be null?
It's something related to insert. Maybe, just maybe you were reading from a DB all that time, and only now try to insert. If yes, then your reading from your DB that is located in Bundle. You would need to copy it into documents folder in order to write to it.
Hope it helps!
Upvotes: 2