OfficeDev / Excel-Custom-Functions

Learn about custom functions in Excel.
Other
318 stars 63 forks source link

Excel: Error Installing add-ins if your function name already exists #104

Closed keyur32 closed 4 years ago

keyur32 commented 5 years ago

Bug: If you have an add-in with the same namespace and same function name already registered, an existing add-in will no longer work.

Upcoming fix: We will provide a better error message here. We did not want to have the same VBA behavior as showing up 2 functions with the same name but you could only call one. We will plan to make this expereince better with the ability to disambiguate the functions.

Tip: if you have multiple versions of the manifest, change the namespace to indicate environment, for testing purposes.

keyur32 commented 5 years ago

Additional workaround from @LouMM - If multiple functions are registered under the same namespace, it causes an ambiguous runtime error. A possible workaround could be to not include the namespace, or generate a unique namespace based off the name of the function.

ElizabethSamuel-MSFT commented 4 years ago

@keyur32 Any update on this? Thanks.

ByEqualation commented 4 years ago

Is this item closed?

This is really a tough thing to work around. My thought is that it has something to do with using Yo Office as I had not experienced this problem when working sans scaffold.

image

I am currently getting the above message Message header "Error installing functions".

Why I consider Yo Office partly responsible: I had a function working perfectly then pulled it in verbatim into a Yo Office generated project -using Typescript- and after making the few trivial typescript modifications. Here I am stuck. Tomorrow I will see if I can make due with the "Stop-Gap" but I am hoping that there may be a thread out there that I have not found just yet that has the answer that is missing here. Body of error. "This add-in wasn't installed because a custom function with the same name already exists.

Clicking on this error message changes the message to read Error loading Add-Ins "One or more add-ins failed to load. See your add-ins."

Finally after clicking on this alert message I get the following excellent recommendation, "Please add or enable add-in catalogs from the Trust Center. I would be happy to do that if I had any idea how and if it might help.

Please add or enable add-in catalogs from the Trust Center.

keyur32 commented 4 years ago

Hey @ByEqualation, we're actually planning to address this. It needs some investigation on options forward. While we could go back to VBA behavior, it would lead to the inconistent code being run (i.e. your custom function may return a value from a previously registered function, which also may not be great).

As a workaround, can you try to clear your cache: https://docs.microsoft.com/en-us/office/dev/add-ins/testing/clear-cache#clear-the-office-cache-on-windows. This should clear any previously sideloaded or registered custom functions, which should make this error less of a chance you'll run into.

PS. agree the current messaging flow doesn't lead developers/end users to success (that is currently on the backlog but feel free to add an item to officespdev.uservoice.com and we'll update it once we get to fixing that).

ByEqualation commented 4 years ago

FYI; the workaround also failed. It appears Microsoft Edge DevTools Preview is more 'preview than tool'. After 13 months, MSFT is still investigating their options... Great!

akrantz commented 4 years ago

@keyur32 The issue here is that add-ins registered via the developer registry don't get cleared out, so doing this more than once with Yo Office add-ins will lead to name conflicts. It isn't necessary to allow the duplicate function names from being registered. It just means that the old add-ins should be unregistered. Since this doesn't happen, the WEF cache needs to be cleared.

keyur32 commented 4 years ago

@akrantz - thanks that was my understanding, but it sounds like according to above clearing the cache did not work either?

@ByEqualation - If clearing the cache/WEF folder did not work for you, can you share the runtime log? What functions names are you trying to run? I'm also not sure what you meant by dev tools preview.

ByEqualation commented 4 years ago

So I went to... C:\Users*****\AppData\Local\Microsoft\Office\16.0\Wef

and deleted the contents of this directory. Then I Reboot 'for good measure' then I restart Excel and the add-in is pulled from somewhere else??? and the WEF directory is reconstituted with the same Add-in. Where do I look for this alternate source of the same Add-in/

The good news is I have successfully cleared out the function namespaces which was the major problem.

To address your question about what was meant by "Dev Tools Preview"... 1.) I followed the link you provided above "Clear the Office cache on Windows". 2.) On this page, step 1 is "Install the Microsoft Edge DevTools." Please follow that link and you will see that there is a DevTools app in Preview that does give some useful features but the one that matters in this case (see step 6)... 6."On the Network tab of the new window, select the Clear cache button." does nothing (at least on my machine).

It may be obvious to you folks but I do not recognize %LOCALAPPDATA% as being equal to the "AppData/Local" directory, add to this fact that it is a hidden directory to begin with this instruction could benefit from some additional explanation.

C:\Users*****\AppData\Local\Microsoft\Office\16.0\Wef

I hope others may benefit from my experience (not fun).

I would still like to know the source of the mystery recovery files that repopulate the Wef directory after it has been cleared out.

keyur32 commented 4 years ago

A feature to help with in production is in the backlog. CLosing this out, will have more details on a future community call: https://developer.microsoft.com/office/events/?filterBy=Community%20calls,Add-ins

davidianlandis commented 1 year ago

I'm having the problem with previous Yo Office generated add-ins having their namespace & functions hang around, and looking in the runtime log, I can even see them being installed. The weirdest thing is that it looks like the Id of the previous manifests are installed as solutions of the current manifest I build and start up.

I have cleared the cache and also the /Wef directory mentioned above. (In my case, on a Mac, both of these are in ~/Library/Containers/com.microsoft.Excel/Data/) Also went through and used npx office-toolbox remove to remove the old manifests, but the custom functions are still hanging around - and looks like they get re-registered as solutions on the current/latest project.

Example from runtime logs (where previous manifest id a833c5c7-c1a1-4163-99af-ecd1ea6355fa is having its functions installed as part of the current one d0595ae3-3d21-4808-a593-edbed5920753):

2/7/23 10:21:45 PM  Verbose CustomFunctions [Installation] [Functions] [Begin] Solution=a833c5c7-c1a1-4163-99af-ecd1ea6355fa, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx       
2/7/23 10:21:45 PM  Verbose CustomFunctions [Registration] [Begin] Function=CONTOSO.ADD, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx
2/7/23 10:21:45 PM  Medium  CustomFunctions [Installation] [Functions] [End] [Success] Solution=a833c5c7-c1a1-4163-99af-ecd1ea6355fa, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx
2/7/23 10:21:53 PM  Verbose CustomFunctions [Installation] [Addin] [Begin] Solution=d0595ae3-3d21-4808-a593-edbed5920753, Version=1.0.0.0       
2/7/23 10:21:53 PM  Medium  CustomFunctions [Installation] [Addin] [End] [Success] Solution=d0595ae3-3d21-4808-a593-edbed5920753, Version=1.0.0.0       
2/7/23 10:21:53 PM  Verbose CustomFunctions [Installation] [Functions] [Begin] Solution=d0595ae3-3d21-4808-a593-edbed5920753, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx       
2/7/23 10:21:53 PM  Verbose CustomFunctions [Registration] [Begin] Function=CONTOSO.ADD, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx        
2/7/23 10:21:53 PM  Unexpected  CustomFunctions [Registration] [End] [Failure] Function=CONTOSO.ADD, Workbook=Excel add-in d0595ae3-3d21-4808-a593-edbed5920753.xlsx    

I'm all out of googles, and this is the closest thread to what I'm experiencing. Wondering, is there anyway to completely unregister/uninstall the old solution/manifest id that keeps getting pulled in?

millerds commented 1 year ago

Did you check all the potential cache locations on Mac (https://learn.microsoft.com/th-th/office/dev/add-ins/testing/clear-cache lists a few possibilities)?

The other thing to doble check is the Add-in dialog to see what you have installed (and possibly uninstall something you didn't expect).

davidianlandis commented 1 year ago

Thanks. Yes, I checked all the cache locations listed under the "Clear the cache manually" section for Mac.

The old sideloaded add-ins are no longer in the Insert -> My Add-ins menu (only the one I just sideloaded), but I did notice when I open the dialog, I only see "Admin Managed" with "No add-ins currently available." I'm not sure if I should expect to see the sideloaded add-in in this list or not.

For now, I can just create a new namespace/formula combination to move forward, but still trying to figure out how those old user-defined functions from a previous manifest keep getting installed.

davidianlandis commented 1 year ago

It looks like I must have missed the Wef cache, I thought I had previously checked/cleared all 4 possible cache locations listed in the docs, but apparently not - or possibly while something was still running.

The following steps worked when making namespace or function name changes (making sure excel is closed):

  1. npm stop
  2. rm -rf ~/Library/Containers/com.microsoft.Excel/Data/Library/Caches/*
  3. rm -rf ~/Library/Containers/com.microsoft.Excel/Data/Library/Application Support/Microsoft/Office/16.0/Wef/*
  4. npm start

I now no longer see the old/orphaned functions (from the current manifest, or any of the old previous ones).