"A type load exception has occurred." using DbContext with MySql connector with Mono - asp.net-mvc

I am trying to use the MySQL Database with the Entity Framework Version 4.1.0.0 and Mono 2.11.4 in a ASP.NET MVC 3 Project.
On my Local Windows system everything works great but when I publish it to my Ubuntu 12.04 LTS System I get a lot of errors.
First I get:
Could not load type 'System.Data.Entity.Infrastructure.DbUpdateException' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
when I press F5 I get different errors every time the page refreshes:
Could not load type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'System.Data.Entity.Infrastructure.DbCompiledModel' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'System.Data.Entity.Infrastructure.ReplacementDbQueryWrapper`1[TElement]' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'MySql.Data.VisualStudio.Editors.SqlEditor' from assembly 'MySql.VisualStudio, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
Could not load type 'MySql.Data.VisualStudio.WebConfig.WebConfigDlg' from assembly 'MySql.VisualStudio, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
A type load exception has occurred.
The last error occurred when I try to use the database with this code:
using (var db = new DefaultContext())
{
db.Persons.Add(new Person() { Name = "hallo", Address = "bllaaa" });
db.SaveChanges();
var persons = db.Persons.ToList();
return View(persons);
}
Did anybody have a similar problem and solved it? I do not know what to do.
P.S.: I use Code First Migration

From my understanding, Mono is bundling the open source version of Entity Framework, which is essentially yet-to-be-released v6.
http://weblogs.asp.net/scottgu/archive/2012/07/19/entity-framework-and-open-source.aspx
So it would seem you can't target EF v4.x, since the code has likely undergone major changes. Although, if you discover that the seemingly missing types are still there, you could attempt to work around the issue with an assembly redirect (just search for bindingRedirect).

I know why this happend.
I installed the mono-fastcgi-server4 through apt-get after i installed mono from source. So i had 2 mono versions installed and the older one was active. (2.10.8)
And the Entity Framework seems totally useless to me because only the new EF6 works with a database but there arent any provider who suppot EF6 and work with mono.

Related

EF Core JET: AccessViolationException when 'updating' changed objects in MS Access

I'm building a .NET Core 3 console app with EF Core 2.2.x and EntityFrameworkCore.Jet to perform some generic reading and writing from/to an access database (mdb). I'm compiling for x86 as the docs say. Goal is to migrate lost and lots of data from a legacy system to a newer system (syncing data).
I've scaffolded the database, and I can perfectly read from the database, but as soon as I go and update an entity, I'm getting access violation exceptions:
Code sample (shortened for abbrevity):
public void SetSynced(int id)
{
var item = _db.Products.Where(x => x.Id == id).Single();
item.NeedsSyncing = false;
_db.SaveChanges();
}
When this code is hit, the following Exception shows up (no innerexception)
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I don't understand why this is happening as I can perfectly read the database, it does this only on writing.
I've tried using the following connection strings (drivers) but both with the same end-result:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password;`
Provider=Microsoft.jet.oledb.4.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password;
When running on x64 reading works, but I'm getting the following exception:
System.Data.OleDb.OleDbException (0x80004002): No error message available, result code: E_NOINTERFACE(0x80004002).
I am lost and searching in the dark here. Does anyone have experience / ideas for me on where to look?
Update 02/02/2020:
I've tried manually connecting using OleDb and running the query to see where that brings me. The below code works. When I switch it out with the above code it fails again.
db = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password");
db.Open();
var command = new OleDbCommand($"UPDATE Products SET NeedsSyncing = 0 WHERE Id= 1", db);
var res = command.ExecuteNonQuery();
After setting up JetConfiguration.ShowSqlStatements = true I got the following stacktrace:
ExecuteDbDataReader==========
UPDATE [Products] SET [PictureName] = #p0
WHERE [Id] = #p1;
SELECT ##ROWCOUNT;
#p1(Int32) = 1
#p0(String) = 'notfound.jpg'
Fatal error. 0xC0000005
at System.Data.Common.UnsafeNativeMethods+ICommandWithParameters.SetParameterInfo(IntPtr, IntPtr[], System.Data.OleDb.tagDBPARAMBINDINFO[])
at System.Data.OleDb.OleDbCommand.ApplyParameterBindings(ICommandWithParameters, System.Data.OleDb.tagDBPARAMBINDINFO[])
at System.Data.OleDb.OleDbCommand.CreateAccessor()
at System.Data.OleDb.OleDbCommand.InitializeCommand(System.Data.CommandBehavior, Boolean)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(System.Data.CommandBehavior, System.Object ByRef)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(System.Data.CommandBehavior, System.String)
at System.Data.OleDb.OleDbCommand.ExecuteReader(System.Data.CommandBehavior)
at System.Data.OleDb.OleDbCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
at System.Data.Common.DbCommand.ExecuteReader(System.Data.CommandBehavior)
at System.Data.Jet.JetCommand.InternalExecuteDbDataReader(System.String, System.Data.CommandBehavior)
at System.Data.Jet.JetCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Diagnostics.DbCommandMethod, System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Microsoft.EntityFrameworkCore.DbContext, System.ValueTuple`2<System.Collections.Generic.IEnumerable`1<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch>,Microsoft.EntityFrameworkCore.Storage.IRelationalConnection>)
at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[[System.ValueTuple`2[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.ValueTuple`2<System.__Canon,System.__Canon>, System.Func`3<Microsoft.EntityFrameworkCore.DbContext,System.ValueTuple`2<System.__Canon,System.__Canon>,Int32>, System.Func`3<Microsoft.EntityFrameworkCore.DbContext,System.ValueTuple`2<System.__Canon,System.__Canon>,Microsoft.EntityFrameworkCore.Storage.ExecutionResult`1<Int32>>)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(System.Collections.Generic.IEnumerable`1<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch>, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(System.Collections.Generic.IReadOnlyList`1<Microsoft.EntityFrameworkCore.Update.IUpdateEntry>)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(System.Collections.Generic.IReadOnlyList`1<Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry>)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at Cashmaster.BackgroundWorker.Services.CashMasterService.Crash()
Nuget packages + versions (related to Jet):
Microsoft.EntityFrameworkCore 2.2.6
EntityFrameworkCore.Jet 2.2.0
System.Data.OleDb 4.7.0
Running this all on .NET Core 3.1.
The issue was tracked on GitHub by Migrate the x86 specific structures to AnyCPU for System.Data.OleDb #32509 and fixed with Fix x86 packing issues in System.Data.OleDb #33899 by a community member.
To fix the issue in your project, use the latest version of EF Core 3.1.x (currently 3.1.10) with the latest version of EntityFrameworkCore.Jet (currently prerelease 3.1.0-alpha.4) together with System.Data.OleDb release 5.0.0.

Using Quartz.NET with a custom connection provider

I'm trying to use Quartz.NET with ReliableDbProvider, to allow Quartz to connect to our Azure SQL databases without transient connection issues.
Here's the configuration I'm using (re-formatted for readability; I actually initialize them in a NameValueCollection...):
quartz.jobStore.dirverDelegateType: Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz
quartz.jobStore.tablePrefix: QRTZ_
quartz.dataSource.default.connectionString: Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Foo;Integrated Security=True
quartz.dataSource.default.connectionProvider.type: ReliableDbProvider.SqlAzure.SqlAzureProvider
quartz.jobStore.useProperties: true
When trying to create a scheduler, I get an exception
InvalidCastException: Unable to cast object of type ReliableDbProvider.SqlAzure.SqlAzureProvider to type Quartz.Impl.AdoJobStore.Common.IDbProvider.
I guess that's not so surprising - but how do I work around it? I took a look at the IDbProvider interface from Quartz, but it wasn't straightforward how to forward that to an instance of the ReliableDbProvider, as the latter did not implement all the features of the former.
What's the best way to use a custom connection provider that Quartz doesn't know about?
It is a QUART.NET IDbProvider....
Quartz.Impl.AdoJobStore.Common.IDbProvider
Not just the some/any standard microsoft one.
(Which you kinda make mention of, but at the same time, it doesn't look like it really clicked as to what that means)
Somebody (out there in internet land ... or you) has to WRITE a concrete that supports Azure. To my knowledge, it hasn't been done.
Here is the list:
https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/job-stores.html
Currently following database providers are supported:
SqlServer-20 - SQL Server driver for .NET Framework 2.0
OracleODP-20 - Oracle’s Oracle Driver
OracleODPManaged-1123-40 Oracle’s managed driver for Oracle 11
OracleODPManaged-1211-40 Oracle’s managed driver for Oracle 12
MySql-50 - MySQL Connector/.NET v. 5.0 (.NET 2.0)
MySql-51 - MySQL Connector/:NET v. 5.1 (.NET 2.0)
MySql-65 - MySQL Connector/:NET v. 6.5 (.NET 2.0)
SQLite-10 - SQLite ADO.NET 2.0 Provider v. 1.0.56 (.NET 2.0)
Firebird-201 - Firebird ADO.NET 2.0 Provider v. 2.0.1 (.NET 2.0)
Firebird-210 - Firebird ADO.NET 2.0 Provider v. 2.1.0 (.NET 2.0)
Npgsql-20 - PostgreSQL Npgsql
APPEND
Hmm. I found something interesting.
In the Quartz.Net source code, in this file:
\src\Quartz\Impl\AdoJobStore\Common\dbproviders.properties
or another place to see it
https://github.com/quartznet/quartznet/blob/master/src/Quartz/Impl/AdoJobStore/Common/dbproviders.properties
Database provider configuration data
Core information taken from Spring Framework .NET - All credits to their great work!
..
# SQL SERVER
quartz.dbprovider.SqlServer-20.productName=Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0
quartz.dbprovider.SqlServer-20.assemblyName=System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.connectionType=System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.commandType=System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterType=System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.commandBuilderType=System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterDbType=System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterDbTypePropertyName=SqlDbType
quartz.dbprovider.SqlServer-20.parameterNamePrefix=#
quartz.dbprovider.SqlServer-20.exceptionType=System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.useParameterNamePrefixInParameterCollection=true
quartz.dbprovider.SqlServer-20.bindByName=true
quartz.dbprovider.SqlServer-20.dbBinaryTypeName=Image
So it may be possible to try and do the above mappings for Azure items. No idea how close you might get.
I was expecting to see something like
public class SqlServer20 : Quartz.Impl.AdoJobStore.Common.IDbProvider
but that led me to find the "dbproviders.properties" file.

ESB 2.2 EsbImportUtil.exe The type initializer for 'Microsoft.Practices.ESB.Configuration.ConfigHelper' throw exception

when importing the itineries using ESB 2.2 EsbImportUtil.exe following error is displayed
I have EnterpriseLibrary 5 installed and GAC contain EnterpriseLibrary 4.1 dll also.
The type initializer for 'Microsoft.Practices.ESB.Configuration.ConfigHelper' threw an exception.[A]Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection cannot be cast to [B]Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection. Type A originates from 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Practices.EnterpriseLibrary.Common\5.0.414.0__31bf3856ad364e35\Microsoft.Practices.EnterpriseLibrary.Common.dll'. Type B originates from 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Practices.EnterpriseLibrary.Common\4.1.0.0__31bf3856ad364e35\Microsoft.Practices.EnterpriseLibrary.Common.dll'.
Thanks for the help
Have you made any changes to esb.config file. Added new orchestation, try removing it. I had similar issue; fixed by removing wrong configuration.
Check:-
http://social.msdn.microsoft.com/Forums/en-US/bf2446fd-87fb-462a-8b78-cde7026bfdf5/the-type-initialize-for-microsoftpracticesesbconfigurationconfighelper-threw-an-exception?forum=biztalkesb

Updating to last version of the monodroid and now the solution not builds

Today I update my monodroid to the its last version. Before this my solution works fine but no I got this errors:
MyProjectPath\Classes\Presentation Layer\Class Override\ImageLoaderListener.cs(15,15): Error CS0012: The type 'Java.Lang.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd'. (CS0012) (RPLAndroidApp)
and also this:
MyProjectPath\Class Override\ImageLoaderListener.cs(15,15): Error CS0012: The type 'Android.Runtime.IJavaObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd'. (CS0012) (RPLAndroidApp)
I tried to recompile my java library that I build by 'JavaBindingLibraryProject' and add them again to project but When I build them I get many errors.
I'm confused what should I do?
Rebuild all your projects with the new version of Mono for Android. You have to do this because of the changes in Assembly strongnames.

ASP.NET MVC 4 Beta Breaks Developer Preview Projects

After upgrading to my ASP.NET MVC 4 Developer Preview assemblies to the latest MVC 4 beta, the following exception occurs for my MVC 4 projects:
Could not load type 'System.Web.WebPages.DisplayModes' from assembly
'System.Web.WebPages, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.
...
Exception Details: System.TypeLoadException: Could not load type
'System.Web.WebPages.DisplayModes' from assembly 'System.Web.WebPages,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
How do I fix this?
Update: I installed the new MVC 4 Beta NuGet package, which added most of the right assemblies, but now I get the missing DisplayModes error on compile:
The name 'DisplayModes' does not exist in the current context.
For the following piece of code in Global.asax.cs:
DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ... });
2nd Update: Solved.
The DisplayModes syntax has changed to:
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
...
});

Resources