It turned out that Windows was blocking the dlls due to a security mechanism: if a DLL is copied to the file system from unknown sources, it gets blocked.
To unblock it: in Windows Explorer, right click on the dll, choose Properties, and at the bottom click 'Unblock'. Do this for all the dlls that are used. It worked fine afterward. Thanks to Mathworks support for this solution. Some more details from them:
A Windows permission issue was the root cause of "NET.addAssembly" not working in the compiled application. The solution was to unblock the DLLs by manually adjusting their properties, as in the following resource: