Our add-in uses Log4Net for logging. We're using an old version and there hasn't been any reason to change that. We've recently encountered an issue where one of our customers is using an add-in from another company and this add-in also uses Log4Net, but a newer version. Now when our add-in is activated by clicking the tab, a Log4Net error occurs. I'm able to reproduce this error by creating a test add-in using the newer Log4Net version. It seems very strange that a 3rd party library used by another add-in should have any effect on an unrelated add-in using a different version of the same same 3rd party library. Has anyone else encountered something like this? An ideas on how to fix this? I know we can update the Log4Net version, but that won't necessarily keep this from happening again.
We are not able to reproduce this issue using the Log4Net NuGet. Are you using different versions of the NuGet or are you referencing the Log4Net assemblies directly?
We are referencing the assemblies directly. Versions 1.2.10.0 and 2.0.17.0. I can send you the assemblies, if needed. The issue occurs during the log4net configuration code:
FileAppender fa = new FileAppender();
fa.Threshold = Level.Info;
BasicConfigurator.Configure(fa);
Create 2 different add-ins, each with a button that runs the above code, and have one add-in reference the newer version of log4net and one reference the older version. When you click the button on one of the add-ins and then other, you'll get an error.
In Visual Studio, what is the value for the "Specific Version" property for these assemblies you have referenced?
If you have selected "Yes" then you will receive an error when that specific version is not found.
The "Specific Version" property for both assemblies was set to nothing (i.e., blank). I changed both to No, and I still get the error.
It seems you have introduced a dependency on a specific version of Log4Net into your addin assembly. If your addin depends on a specific version of a 3rd party dll, the addin is responsible for deploying its dependencies. You can add the specific dll of log4net into your addin as content and it will be deployed to the addin assembly cache where it can be resolved by the .NET assembly resolver.
The other alternative is to upgrade your addin to use the latest version of Log4Net via the NuGet.
We're already doing exactly that (deploying the log4net assembly) and have been the whole time. Apparently is ISN'T being correctly resolved by the .NET assembly resolver or this conflict with the other version, which is in the assembly cache for the other vendor's software, wouldn't be occurring.
We encountered the same issue where we load our own or third-party libraries with different versions. This is a common issue in .NET 5+ where assemblies with different versions cannot be loaded side by side, unlike in the .NET Framework. In .NET 5 and higher, if two different versions of the same assembly (in this case, Log4Net) are loaded in the same process, the runtime will attempt to load the highest version, which can lead to conflicts like the error you're seeing.
Cause: From our point of view, this issue happens because ArcGIS Pro runs all add-ins in the same AppDomain and does not isolate the assemblies each add-in uses. So, when one add-in loads a newer version of Log4Net, that version is used globally, even if your add-in requires an older version. This causes conflicts when your add-in is activated.
The best way to resolve this would be for ArcGIS Pro to load each add-in in its own <code>AssemblyLoadContext</code>. This feature, introduced in .NET Core, allows for isolation between assemblies loaded in different contexts, meaning that each add-in could load and use its own version of Log4Net (or any other library) without interfering with other add-ins.
We recommend that the ArcGIS Pro team consider implementing <code>AssemblyLoadContext</code> for add-ins. This would resolve the versioning conflict you're experiencing and would prevent similar issues from happening in the future with other third-party libraries. It would also ensure that the add-ins can run independently, even if they use different versions of the same dependency.
Thanks for posting this information! We are also encountering similar issues when registering Gdal, which is incredibly frustrating. I hope ESRI reads this and considers implementing a solution.