Reputation: 2720
I am caught up in a real messy situation.
Scenario: I have a Excel automation VBA add-in that calls a .NET 4.0 library (via ExcelDna). This 4.0 library invokes some methods in the 2.0 mixed mode library. Hence had to set 'BindAsLegacyV2Runtime' to the 4.0 CLR. I set this in the 4.0 library and when excel instantiates this library the CLR loads with this attribute set and everything works fine.(See this link). I cannot modify the excel.exe.config as it is denied in production machines.
I start excel process from a batch file and load my addin as :
Start Excel.exe my4.0addin.xla
Problem: Found this doesnt work in few user machines and investigated the issue to find that excel was loading pre-installed addins in the machine first before it loads the addin passed in as parameter. Hence, before the 4.0 add-in loads, excel was loading 2.0 CLR because of some other add-ins. Hence the attribute is failed to set and the logic goes for a toss.
I cannot modify the excel.exe.config (to add the attribute to config) or register my addin, since both these require admin permissions on the user machines and it is not possible in my environment.
Hence, is there a way to control excel loading the addins or any way to make this work ?
Upvotes: 1
Views: 575
Reputation: 2720
Here is a way I got this working. Could be useful for someone.
I wrote a WCF service that exposes my 4.0 functionalities. This is in .NET 4.0 (4.0 CLR).
I wrote a 2.0 client that consumes the wcf service via generated proxy. This is in .NET 3.5. (2.0 CLR). I then converted by addin to be in .NET 3.5 and consumed this client which is also in .NET 3.5 In the addin I can now directly use the 2.0 mixed mode assembly plus also have access to 4.0 functionalities via the wcf service.
Hence I avoided the the binding attribute and managed to keep my addin in 2.0.
Upvotes: 0
Reputation: 16907
Easiest would be to recompile the mixed mode assembly to target .NET 4.
A bit more adventurous would be to figure out how the .NET target version is stored in the mixed mode assembly, and edit the binary appropriately.
Upvotes: 2