Question

When I have first-chance exceptions enabled in VS2010, I get the following message the first time I call EntityFramework's SaveChanges(). This is a WinForms application running a MSSQL CE 4 database.

BindingFailure The assembly with display name 'Microsoft.SqlServer.Types' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

After continuing, this message is also displayed:

FileLoadException Could not load file or assembly 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I've included the Microsoft.SqlServer.Types.dll in the project.

I know this is a first-chance exception and it doesn't seem to affect the application outside of the notice when I debug, but I'd like to fix it anyways. (It's bugging me in the back of my mind.)

First, what is this error message trying to tell me?

Second, how do I fix it?

Was it helpful?

Solution

If you are using spatial types EF needs to probe what SqlTypes are loaded in the AppDomain to bind to it to use it when talking to the SqlServer. Here is the code that does it. If you look at the BindToLatest() method you will see that the exception if actually being caught and ignored. You only see it when you debug since you probably have the "break when an exception is thrown" option checked (Debug -> Exceptions, Common Language Runtime Exceptions, "Thrown" column)

OTHER TIPS

A first-chance exception is not a problem to fix. If the exception is handled, then there will be no impact on your code.

It's unhandled exceptions that you need to worry about.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top