1

Hi I have looked at other answers and I don't see anything that would answer this, I have code that executes correctly when initiated by a unit test but throws

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

When the same method is called with the same values in debug mode the line that throws the error :

dbConnection = new SQLiteConnection(@"Data Source = " + pathtoDB + "; version=3;");

In both cases where it is called there is no difference in pathtoDB, as I say my unit test has no problem with this method but debug fails. I have no idea why.

Edit - Thanks for the links, but it's not actually answering the question, I accept that it's possible that the dll for SQLite may not be x64 but that does not explain why this runs correctly from a unit test but not from a debug session with exactly the same parameters. It is this that I am seeking an answer to. I have also updated the title

Edit - The Sqlite stuff is x64 it's not that that is causing it, just an update it's not changing the question.

Phil
  • 616
  • 2
  • 8
  • 21
  • May be helpful: https://stackoverflow.com/questions/18007967/net-framework-error-hresult-0x8007000b#18008488 – Jaskier Oct 31 '18 at 21:18
  • Possible duplicate of [Could not load file or assembly 'xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format](https://stackoverflow.com/questions/1648213/could-not-load-file-or-assembly-xxx-or-one-of-its-dependencies-an-attempt-was) – Ken White Oct 31 '18 at 21:33
  • C# code is JIT compiled into either 32 or 64 bit native code at runtime. If the parent process that loads the assembly is 32 bit it will be JITed into 32 bit or if the parent is 64 then 64. The unit test runner is probably 32 bit and the debug session is probably 64 (or vice versa). This is why you see different behavior. – Dave M Nov 01 '18 at 00:16

1 Answers1

0

With reference to [Dave M] who has explained the reason, this is closing off the question with the steps to rectify the issue.

To correct the problem, the [Solution Properties] was opened (VS2017) - an additional configuration was created from the [Configuration manager] with the platform set to x86 for the Project and Unit tests.

The solution was run in Debug and successfully completed the connection to the Database.

Phil
  • 616
  • 2
  • 8
  • 21