41

I am looking at the System.Data.SQLite download page, and it lists mixed mode assembly for .NET 4 and a regular (I assume). My project that is going to use this library is all .NET 4 which will be compiled to x86.

I have 2 questions:

  1. What is a mixed-mode assembly? Google returns a confusing array of answers, none of which make a lot of sense. One answer states that it's all about mixing native and managed code, while others claim its for mixing .Net versions.
  2. Which download should I get for my situation?

4 Answers 4

35

http://msdn.microsoft.com/en-us/library/x0w2664k.aspx

1) Allways check msdn first. Mixed mode means that the assembly can run managed and unmanaged code.

2) Setups for 32-bit Windows (.NET Framework 4.0)

http://system.data.sqlite.org/sqlite-netFx40-setup-bundle-x86-2010-1.0.74.0.exe

You kinda answered that question yourself "My project that is going to use this library is all .NET 4 which will be compiled to x86."

5
  • 2
    So effectively mixed mode assemblies are always written in c++? Sep 1, 2011 at 15:30
  • 2
    And you are saying that I should use the mixed-mode assembly. I am still unclear as to why. Sep 1, 2011 at 16:05
  • 5
    Because there are only mixed-mode assemblys. This is because the sqlite 'functionality' is written in C (COM) and you access it via a wrapper for .NET. So the assembly contains C and C# Code --> mixed mode assembly.
    – Steav
    Sep 2, 2011 at 12:25
  • 25
    Ahh now I got what u mean.... The difference is, that a mixed-mode assembly is 1 .dll file that contains the functinality and the .NET wrapper. If you don't use mixed-mode assembly you will have a SQLite.dll and a second DLL (SQlite.Interop.dll or however they call it) for the wrapper, so you dont have mixed codes within 1 dll
    – Steav
    Sep 2, 2011 at 12:31
  • 1
    Neither SQLite3.dll, nor SQLite.Interop.dll have managed code - see here . When not using the "System.Data.SQLite.dll" mixed mode assembly, then you must use another "System.Data.SQLite.dll" with a "SQLite.Interop.dll" file, which contain the managed code and native code, respectively - see here . Aug 3, 2016 at 14:23
7

There is a way to produce a mixed-mode assembly from pure IL. The final part of creating an assembly using reflection involves a call to AssemblyBuilder.Save. If you just pass PortableExecutableKinds.Required32Bit for the portableExecutableKind argument then you will create a mixed-mode assembly. You can avoid the problems this causes by also passing PortableExecutableKinds.ILOnly. i.e.


    assembly_bldr.Save(exe_name, PortableExecutableKinds.Required32Bit | PortableExecutableKinds.ILOnly, ImageFileMachine.I386 );

Needless to say, this information was hard won...

5

Taken from the official FAQ

(14) What is a mixed-mode assembly?

A mixed-mode assembly is a dynamic link library that contains both managed code and native code for a particular processor architecture. Since it contains native code it can only be loaded into a process that matches the processor architecture it was compiled for. Also see this StackOverflow question.

It even references this question!

1

For SQLite, the bundle contains a mixed-mode assembly for System.Data.SQLite; however, the default package contains two separate assemblies, one completely native, and the other an interop assembly which is completely managed.

There's actually a FAQ for this on the SQLite site.

(15) What is a "bundle" package (i.e. from the download page)?

The "bundle" packages listed on the download page contains the System.Data.SQLite mixed-mode assembly in a file named "System.Data.SQLite.dll" (see question #14) instead of separate "System.Data.SQLite.dll" and "SQLite.Interop.dll" files to contain the managed code and native code, respectively.

And the previous FAQ:

(14) What is a mixed-mode assembly?

A mixed-mode assembly is a dynamic link library that contains both managed code and native code for a particular processor architecture. Since it contains native code it can only be loaded into a process that matches the processor architecture it was compiled for. Also see this StackOverflow question.

Why are there two options?

Based on my research, the non-bundled form is available so that you can use P/Invoke in managed code (e.g. C#) to call into unmanaged code, rather than using IJW. IJW is magically better, and the mechanism to compile a C++ program into separate managed and unmanaged DLLs like this (so that P/Invoke even applies) is deprecated as of VS 2015, so newer versions of SQLite might drop the non-bundled package.

You should double-check my research, as I don't have direct evidence of anything in the preceding paragraph. Here's my research:

1
  • another reason of two options I think is for AnyCpu project.
    – ahdung
    Aug 10, 2021 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.