Search code examples
.netassembliessql-server-cewindows-cefusion

Assembly Version Loading Problem and SQL CE


I have an application that utilizes SQL CE 3.5 and the Entity Framework from .NET 3.5.

We encountered a known issue with SQL CE 3.5 SP2 RTM that causes application crashes. As a result, we obtained Cummulative Update 2 which apparently addresses the issue.

Since we deployed SQL CE via XCopy with our application, we assumed that simply replacing the local managed and unmanaged DLLs with the CU2 versions would do the trick.

In the case where SQL CE has been installed on the machine ahead of time (and is therefore in the GAC), our application ignores the newer versions of the assemblies and DLLs and loads the old, broken versions from the GAC.

We determined that that uninstalling SQL CE (and therefore removing it from the GAC) or updating the GAC's assemblies allows our application to use the correct version.

Is there a better way? I've tried Assembly.LoadFile, but that didn't seem to work. (Both versions were loaded, but the older one was the one that was actually in use.)


Solution

  • Are you targeting a specific version of the SQL CE assemblies? In the properties tab check that the Specific Version property of the reference is set to True. Also check that you don't have an assembly binding redirect that directs the .Net framework to use the older assemblies.

    I can only assume that the Cummulative Update 2 incremented the version number, and if this is the case the assemblies in the GAC should only be used if the assembly version matches exactly. If they don't match then the .Net framework should use the assemblies found in your application directory, as they do match the version number exactly.