I have created brand-new Excel VSTO Workbook project . The problem comes with System.ComponentModel.Annotations.dll library. When I'm trying to fetch single record from database, I get following exception:
System.IO.FileLoadException: 'Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
I have discovered that _Microsoft.EntityFrameworkCore.dll_ refers to 4.2.0.0 version of _System.ComponentModel.Annotations_, while its version really is 4.2.2.0.

What's more strange is that same context works in Windows Forms app without errors.
_P.S._ I get same error in EF 2.2.3.
EF Core version: 3.0.0-preview3.19153.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win10 x64 Home Single Language 1809 OS build 17763.379
IDE: Visual Studio 2019 Community 2019 RC 16.0.0 RC.4) and Visual Studio 2017 15.9.10
What's more strange is that same context works in Windows Forms app without errors.
This is because there are binding redirects in your WinForm app app.config file (in your output folder)
And it is not possible for you to add these to Excel.
I searched around and I found some hints suggesting that it maybe possible to use binding redirects in an app.config, at least for VSTO add-ins.
This Stack Overflow question also shows a more heavy handed approach based on handling AppDomain.AssemblyResolve. https://stackoverflow.com/questions/25664372/making-binding-redirects-work-for-office-add-ins.
I will leave this open at least until next triage, in case someone has other suggestions.
@divega The solution in the link you gave - works!
Here's what I've got:
public partial class ThisWorkbook
{
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs e)
{
try
{
if (!e.Name.StartsWith("System.ComponentModel.Annotations"))
return null;
var assemblyName = e.Name.Split(',')[0];
var assemblyBasePath = this.Path;
var fullPath = assemblyBasePath + @"\" + assemblyName + ".dll";
var assembly = Assembly.LoadFrom(fullPath);
return assembly;
}
catch (Exception ex)
{
return null;
}
}
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
}
}