You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Using 'System.Data.OleDb' on 'net472' throws 'TypeLoadException' #83
@lauxjpn: I am not sure if the implementation is buggy or if I do something wrong, but when trying to load my database via oledb the version I provide with nuget gets ignored and I get the TypeLoadException from JetFactory. The call of Type.GetType(...) seems to be problematic, if I load the System.Data.OleDb via Assembly.Load(..) the correct one gets loaded, but Type.GetType(...) uses the default for my target framework (in this case net472). Should I open up a bug or is this my fault?
@xoniuqe I tried adding a binding redirect but didnt work. I can see in the debug as it loads, it loads the correct version but at runtime the .net framework version keeps on getting picked.
Here's the problem. The netstandard version includes all the OleDb classes whereas the .net framework version doesn't. It in turn references the normal System.Data
@lauxjpn The OleDb bug that was in the net core version, do you know if that was only in net core? If so on the full framework you can ignore the version check. Tried without the version check and it goes further but I do get a COM error when it tries to create the database using DAO
@xoniuqe I tested my changes and it does work on your test project. It will just use the OleDb classes from the framework's System.Data rather than the nuget package. Also I would recommend changing your connection string to use ACE rather than Jet. Jet is quite old and only supports database formats up to around access 2003. Creating a new database will use DAO which will use the current access runtime installed. If you are using e.g the 2010 or 2016 runtime, it will be created in that format which is not supported when using the Jet connection string.
Should only need to change the Provider to Microsoft.ACE.OLEDB.12.0
@ChrisJollyAU Thank you for the fast work, unfortunalety I think I have to stick to the Jet driver because we currently have the requirement to work with the old database format. But I give it a try and will give you an update. But this has to wait until monday.
I had no serious issue with the test project that @xoniuqe provided when using #84, but only a minor one regarding the double quotes surrounding the Data Source connection string option value, that will lead to a failing path check later on when executing our custom CREATE DATABASE command.
I will open another PR for that fix.
@lauxjpn: This worked kind of. I can load the mdb file successfully with the removed quotes, but when I try to migrate I get an OleDBException "Unrecognized database format error"(may not be the exact wording). If I change the provider to Microsoft.ACE.OLEDB.12.0 this works but the migration does not create an database password. is this the same issue as you mentioned before (concerning an upcoming(?) PR)?
@xoniuqe Not sure about the database password. However I did mention something about that unrecognized database format error earlier in this issue.
In summary the new file is created using DAO from the currently installed access engine (e.g. in the test suite for this project it uses the access 2010 engine). However when trying to read it using OleDb, you are specifying the Jet OleDb driver which is too old to understand the 2010 format. The ACE OleDb driver can understand that format.
when I try to migrate I get an OleDBException "Unrecognized database format error"(may not be the exact wording)
In summary the new file is created using DAO from the currently installed access engine (e.g. in the test suite for this project it uses the access 2010 engine). However when trying to read it using OleDb, you are specifying the Jet OleDb driver which is too old to understand the 2010 format. The ACE OleDb driver can understand that format.
We should fix this. We should provide an option to specify the database version that should be used.
There is already support to specify the DatabaseVersion for database creation operations in EFCore.Jet.Data, so this should not be that hard.
Your sample code uses the Database.EnsureCreated() method, which generates a EFCore.Jet specific CREATE DATABASE statement. This statement currently does not support specifying a password, a collating order or a specific database version.
However, you can just call JetConnection.CreateDatabase() instead:
If I change the provider to Microsoft.ACE.OLEDB.12.0 this works but the migration does not create an database password.
Your sample code uses the Database.EnsureCreated() method, which generates a EFCore.Jet specific CREATE DATABASE statement. This statement currently does not support specifying a password [...]
@lauxjpn After a short test with my prototype everything seems to work as I would expect it. Thank you for your fast responses and the fixes. Great job! (@ChrisJollyAU thank you too, you were also helpful).
When I first was evaluating to use this provider for our ancient software I was a bit sceptical (at first the project seemed a bit inactive to me, to be honest) but I must admit im really impressed by the handling of my issues here 👍
I tried to get the prerelease package working in a net 5 project. Didn't work. Tried downgrading to 3.1 core, also didn't work
I either get typeload exceptions or version conflicts with nuget packages
Is there an example of a working test project?
Did a screenshot of the project file sorry 😊
These are the references I use (froegt about the sqlite…)
<PackageReference Include="EntityFrameworkCore.Jet" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.3">
When I try to upgrade to theprerelease I get
Version conflict detected for Microsoft.EntityFrameworkCore.Relational. Install/reference Microsoft.EntityFrameworkCore.Relational 5.0.3 directly to project DuikLogBoekEF to resolve this issue. DuikLogBoekEF -> Microsoft.EntityFrameworkCore.Tools 5.0.3 -> Microsoft.EntityFrameworkCore.Design 5.0.3 -> Microsoft.EntityFrameworkCore.Relational (>= 5.0.3) DuikLogBoekEF -> EntityFrameworkCore.Jet 3.1.0-alpha.4 -> Microsoft.EntityFrameworkCore.Relational (>= 3.1.10 && < 5.0.0).
From: Christopher Jolly <[email protected]>
Sent: zondag 28 februari 2021 15:28
To: bubibubi/EntityFrameworkCore.Jet <[email protected]>
Cc: jeromv <[email protected]>; Mention <[email protected]>
Subject: Re: [bubibubi/EntityFrameworkCore.Jet] Using 'System.Data.OleDb' on 'net472' throws 'TypeLoadException' (#83)
You need the prerelease. The version you are using is 2.2.0 which is compatible with net core 2
Your project file is not included
If your project file uses packagereferences have this as a line in it
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#83 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADCZCMAWRMZWOOYSDO4IHJLTBJHFHANCNFSM4ULDWBLQ> . <https://github.com/notifications/beacon/ADCZCMDXIA6YTTZIYD6CNOTTBJHFHA5CNFSM4ULDWBL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOF3X3ICI.gif>
Ah, your version is wong for all those starting with Microsoft.EntityFrameworkCore . Being version 5 they are referencing the net 5 version of those packages
3.1.12 is the latest in the 3.1 series. If you have all those change to use that version and have
<PackageReference Include="EntityFrameworkCore.Jet" Version="3.1.0-alpha.4" /> for EFCore it should work
You may want to add either EntityFrameworkCore.Jet.OleDb or EntityFrameworkCore.Jet.Odbc depending on whether you prefer oledb or odbc style connection strings (and behind the scenes access)
Also, it would be best to downgrade the Microsoft.EntityFrameworkCore packages first before going to the correct EFCore version
Activity
lauxjpn commentedon Dec 2, 2020
@xoniuqe How are you referencing OleDb in the project file?
Is it like
<PackageReference Include="System.Data.OleDb" Version="5.0.0" />Originally posted by @ChrisJollyAU in #34 (comment)
lauxjpn commentedon Dec 2, 2020
@ChrisJollyAU Yes I did. I will upload a demo project on my github. https://github.com/xoniuqe/Ef-Core-Jet-TypeLoadException
Originally posted by @xoniuqe in #34 (comment)
lauxjpn commentedon Dec 2, 2020
@xoniuqe Do you specifically need the full .net framework? Changing your demo to use .net core 3.1 is a possible solution
Originally posted by @ChrisJollyAU in #34 (comment)
lauxjpn commentedon Dec 2, 2020
@ChrisJollyAU I have dependencies to .net Framework assemblies which are not usable in .net core 3.1, so yes.
Originally posted by @xoniuqe in #34 (comment)
lauxjpn commentedon Dec 2, 2020
@xoniuqe I tried adding a binding redirect but didnt work. I can see in the debug as it loads, it loads the correct version but at runtime the .net framework version keeps on getting picked.
Should probably open a issue specific for this
Originally posted by @ChrisJollyAU in #34 (comment)
lauxjpn commentedon Dec 2, 2020
Here's the problem. The netstandard version includes all the OleDb classes whereas the .net framework version doesn't. It in turn references the normal System.Data
@lauxjpn The OleDb bug that was in the net core version, do you know if that was only in net core? If so on the full framework you can ignore the version check. Tried without the version check and it goes further but I do get a COM error when it tries to create the database using DAO
Originally posted by @ChrisJollyAU in #34 (comment)
ChrisJollyAU commentedon Dec 3, 2020
@xoniuqe I tested my changes and it does work on your test project. It will just use the OleDb classes from the framework's System.Data rather than the nuget package. Also I would recommend changing your connection string to use ACE rather than Jet. Jet is quite old and only supports database formats up to around access 2003. Creating a new database will use DAO which will use the current access runtime installed. If you are using e.g the 2010 or 2016 runtime, it will be created in that format which is not supported when using the Jet connection string.
Should only need to change the Provider to
Microsoft.ACE.OLEDB.12.0Have it working in both x86 and x64
xoniuqe commentedon Dec 3, 2020
@ChrisJollyAU Thank you for the fast work, unfortunalety I think I have to stick to the Jet driver because we currently have the requirement to work with the old database format. But I give it a try and will give you an update. But this has to wait until monday.
lauxjpn commentedon Dec 3, 2020
Okay, the issue is fixed with #84.
I had no serious issue with the test project that @xoniuqe provided when using #84, but only a minor one regarding the double quotes surrounding the
Data Sourceconnection string option value, that will lead to a failing path check later on when executing our customCREATE DATABASEcommand.I will open another PR for that fix.
10 remaining items
xoniuqe commentedon Dec 9, 2020
@lauxjpn: This worked kind of. I can load the mdb file successfully with the removed quotes, but when I try to migrate I get an OleDBException "Unrecognized database format error"(may not be the exact wording). If I change the provider to
Microsoft.ACE.OLEDB.12.0this works but the migration does not create an database password. is this the same issue as you mentioned before (concerning an upcoming(?) PR)?ChrisJollyAU commentedon Dec 9, 2020
@xoniuqe Not sure about the database password. However I did mention something about that unrecognized database format error earlier in this issue.
In summary the new file is created using DAO from the currently installed access engine (e.g. in the test suite for this project it uses the access 2010 engine). However when trying to read it using OleDb, you are specifying the Jet OleDb driver which is too old to understand the 2010 format. The ACE OleDb driver can understand that format.
As an aside the wikipedia article has a nice table of the drivers and which formats each support. https://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine
lauxjpn commentedon Dec 9, 2020
@xoniuqe The connection string quoting issue is fixed with #88.
lauxjpn commentedon Dec 9, 2020
We should fix this. We should provide an option to specify the database version that should be used.
There is already support to specify the
DatabaseVersionfor database creation operations inEFCore.Jet.Data, so this should not be that hard.I will push a PR for this.
@xoniuqe Regarding the password:
Your sample code uses the
Database.EnsureCreated()method, which generates a EFCore.Jet specificCREATE DATABASEstatement. This statement currently does not support specifying a password, a collating order or a specific database version.However, you can just call
JetConnection.CreateDatabase()instead:Or together with
EnsureDeleted()andEnsureCreated():lauxjpn commentedon Dec 9, 2020
@xoniuqe The
System.Data.OleDb.OleDbException (0x80004005): Unrecognized database format 'test.mdb'.issue is fixed with #90.lauxjpn commentedon Dec 10, 2020
@xoniuqe This issue is fixed with #91.
As far as I am aware, we should now have fixed all issues reported by you. So if I missed anything, please remind me again.
xoniuqe commentedon Dec 14, 2020
@lauxjpn After a short test with my prototype everything seems to work as I would expect it. Thank you for your fast responses and the fixes. Great job! (@ChrisJollyAU thank you too, you were also helpful).
When I first was evaluating to use this provider for our ancient software I was a bit sceptical (at first the project seemed a bit inactive to me, to be honest) but I must admit im really impressed by the handling of my issues here 👍
jeromv commentedon Feb 28, 2021
Hello,
I tried to get the prerelease package working in a net 5 project. Didn't work. Tried downgrading to 3.1 core, also didn't work
I either get typeload exceptions or version conflicts with nuget packages
Is there an example of a working test project?
ChrisJollyAU commentedon Feb 28, 2021
Hi @jeromv . Net 5 is not supported yet. It does require a fair number of changes to be built against it.
It should be working for .net core 3.1 . Can you post your project file and the exact error message you're getting
jeromv commentedon Feb 28, 2021
ChrisJollyAU commentedon Feb 28, 2021
You need the prerelease. The version you are using is 2.2.0 which is compatible with net core 2
Your project file is not included
If your project file uses packagereferences have this as a line in it
<PackageReference Include="EntityFrameworkCore.Jet" Version="3.1.0-alpha.4" />jeromv commentedon Feb 28, 2021
ChrisJollyAU commentedon Feb 28, 2021
Ah, your version is wong for all those starting with
Microsoft.EntityFrameworkCore. Being version 5 they are referencing the net 5 version of those packages<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />3.1.12 is the latest in the 3.1 series. If you have all those change to use that version and have
<PackageReference Include="EntityFrameworkCore.Jet" Version="3.1.0-alpha.4" />for EFCore it should workYou may want to add either
EntityFrameworkCore.Jet.OleDborEntityFrameworkCore.Jet.Odbcdepending on whether you prefer oledb or odbc style connection strings (and behind the scenes access)Also, it would be best to downgrade the
Microsoft.EntityFrameworkCorepackages first before going to the correct EFCore versionjeromv commentedon Feb 28, 2021
jeromv commentedon Feb 28, 2021