Search code examples
c#.netasp.net-coreofficewriter

Could not load type 'System.Data.OleDb.OleDbType' from assembly officewriter.proces()


When i am trying to populate merge fields in a document template, when i reach the wordTemplate.process(); it tries to load a type 'System.Data.OleDb.OleDbType', but none is found. The project is a .net framework 4.7.2 class lib with a .net Core 2.1 UI lib.

I have tried doing this in an older asp.net website project that is targeting framework 4.7.2 as well, and there is works like a charm.

Error message:

WordWriter Error: Could not load type 'System.Data.OleDb.OleDbType' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e079'.

Full name of exception = "SoftArtisans.OfficeWriter.WordWriter.SAException"

I am simply trying to write a repeat block that replaces a merge field(this works in the asp.net website):

DataTable dt = new DataTable("Occassions");
dt.Columns.Add("AttentionNames");

foreach (AudAudiencePerson person in audiencePeopleToPrint)
{
  DataRow row = dt.NewRow();
  row["AttentionNames"] = "Mathias";
  dt.Rows.Add(row);
}

WordTemplate wordTemplate = new WordTemplate();  

wordTemplate.Open(@"pathToTemplate\BasicTemplate.docx");

wordTemplate.SetRepeatBlock(dt, "Repeat");
wordTemplate.Process();

MemoryStream ms = new MemoryStream();
wordTemplate.Save(ms);

What am i missing here?


Solution

  • Alright, figured it out... Because my parent project is a .NET Core 2.1 and the child project is a .NET framework 4.7.2, when it is in runtime, it will use the system.data from the Core project in the framework project. When editing the project in the IDE i will use the framework dll, but not when compiled. In the CORE dll, a lot of OleDB "framework" has been removed. that is why a got an error in runtime, but not when writing the code. I hope this helps someone.