I have made a C# .NET dll which i would like to run from VBA without register it. I've found the solution there and it works perfectly, but only when the assembly is made with the Framework NET 3.5 or older. With Framework 4.0, i'm getting the error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded".. Someone could help me please?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
So, i've found the solution.
By default, Excel uses the 1.1 framework as explained here. If you have a look into the Windows Registry,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\AppPatch\YOUR_FRAMEWORK_VERSION\excel.exe\
you can see the targeted version is v1.1..... So, the solution is to make an Excel.exe.config file that forces Framework version 4, as explained here
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
</startup>
</configuration>