Excel-DNA / ExcelDna

Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library.
https://excel-dna.net
zlib License
1.26k stars 270 forks source link

Registration [Error] xlfRegister call failed for function or command #664

Closed Rand-Random closed 5 months ago

Rand-Random commented 5 months ago

A client of mine is getting the following message

Registration [Error] xlfRegister call failed for function or command: 'my function'

I am rather clueless as what could be the problem, the error only seems to happen irregullary.

Does excelDna write more detailed information somewhere, to narrow down the problem?

govert commented 5 months ago

You can enable a higher level of logging to see the exact call that is failing - in this case you need the 'Info' level of logging enabled.

.NET Framework 4.x Logging Configuration

If you are targeting .NET Framework 4.x, you can use a .config file to set up the logging, with these instructions: https://excel-dna.net/docs/archive/wiki/Diagnostic-Logging

Simplest is to add this .config file next to your .xll file (with name <MyAddIn>.xll.config), giving you a .log file after running.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4"/>
    <sources>
      <source name="ExcelDna.Integration" switchValue="All">
        <listeners>
          <remove name="Default"/>
          <add name="LogDisplay" type="ExcelDna.Logging.LogDisplayTraceListener,ExcelDna.Integration">
            <filter type="System.Diagnostics.EventTypeFilter" initializeData="Off"/>
          </add>
          <add name="File" 
               type="System.Diagnostics.TextWriterTraceListener" 
               initializeData="ExcelDnaAddIn.log" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

.NET 6 Logging Configuration

If you are targeting .NET 6, you can't use the .config file, and have the following options to configure the logging:

Set environment variables to configure the logging, then restart Excel:

EXCELDNA_DIAGNOSTICS_DEBUGGER_LEVEL=Verbose EXCELDNA_DIAGNOSTICS_FILE_LEVEL=Verbose EXCELDNA_DIAGNOSTICS_FILE_NAME=ExcelDna.log EXCELDNA_DIAGNOSTICS_LOGDISPLAY_LEVEL=Verbose EXCELDNA_DIAGNOSTICS_SOURCE_LEVEL=All

Set Registry entries under either of the keys

HKEY_CURRENT_USER\Software\ExcelDna\Diagnostics
HKEY_CURRENT_USER\Software\ExcelDna\Diagnostics

Then use these values, similar to the environment variables

Rand-Random commented 5 months ago

Thanks for the fast response.

Will come back to you once I have further data, most likely will take some days until client creates *.config file and error reoccures and provides feedback.

Rand-Random commented 5 months ago

Sadly, never got feedback with Logs activated. They nstalled a new version of my app, which has a newer excel dna library dependecy. This seems to have solved the issue at hand. So, I don't no what caused the problem to begin with.