1

I'm trying out NetOffice to perform MS Word mail merge using a template and programatically filling in the merge fields. The examples available here does not really have this scenario. I updated Example 03 in it so that it creates a new document from an existing MS Word document with merge fields. I then changed it to access the merge fields using the code below:

var fields = newDocument.MailMerge.Fields;
foreach (Word.MailMergeField field in fields)
{
   ...
}

But the for loop gets this exception the first time it tries to enumerate through fields: Factory is not initialized with NetOffice assemblies. If I try to run on debug, fields.Count returns a correct count of the merge fields on my document. I just can't seem to access the fields to fill/update them.

Has anyone encountered this before?

UPDATE

Running a debug on Core.cs, it fails to load the assembly from WordApi.dll, and consequently does not get the FactoryInfo from that assembly, which I assume it needs in its _factoryList. I haven't quite figured out why it is failing to load the assembly even when the dll is in the folder that it is searching in.

2
  • 1
    This was bug in some NetOfficeFw packages. When you update to latest NetOfficeFw packages from nuget.org/profiles/netoffice you will get fixed version of NetOffice libraries. Commented Aug 2, 2020 at 13:46
  • I was getting the same error in Outlook at Dim oAccounts = oOutlook.Session.Accounts. I switched to the FW version of the package and it worked. What's the difference between the two, and may I ask why you chose not to publish the update/fix to the non-FW version? Commented Dec 2, 2020 at 8:33

1 Answer 1

2

The problem I'm getting appears to be a bug on NetOffice. The bug is in the CurrentAppDomain class' LoadFrom(). Given it is accepting the assembly's full file path (and not the assembly's fully qualified name), it should perform an Assembly.LoadFrom(path) if LoadAssembliesUnsafe is false.

I have reported this bug/issue on github. Link here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.