Reputation: 441
I have a simple excel DNA add in, created in version 0.32.
In my add-in I am dynamically loading another assembly that is found on a network drive.
When I load my excel DNA add-in into Excel and run my Excel-DNA function, I get the following error :
{"This method implicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information."}
I have created a .config file for the ExcelDNA project in Visual Studio as shown below :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="DbPath" value="testString"/>
</appSettings>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
<legacyCasPolicy enabled="true"/>
<loadFromRemoteSources enabled="true"/>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
Any ideas on how I can resolve this issue?
Any help would be much appreciated.
Upvotes: 3
Views: 553
Reputation: 3034
If I recall correctly, the actual .config
file that you specify must reside alongside the executable process that is loading your add-in. In this instance, it would be Excel.exe
, thus the config should be called Excel.exe.config
, and exist in the Excel directory.
To load a library from a network share whilst using legacy support for Code Access Security in .NET 4.0, you may have to create a trusted code security group using the caspol.exe
tool (click here for .NET 4.5 details). This is probably dependent on how you deploy and sign the library you're attempting to load. The tool typically resides at the following path:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\CasPol.exe
Using an example command line issued to the tool:
CasPol.exe -m -ag 1.2 -url file://to/your/network/share/* FullTrust
It is worth noting, two code access security configurations exist, one for 32-bit and one for 64-bit architectures. If you modify code access security using the CasPol.exe
tool and a 64-bit command prompt, then you are modifying .NET code access security for 64-bit processes! Excel typically runs as a 32-bit process (if you followed Microsoft's install advice) so you would need to execute CasPol.exe
from a 32-bit command prompt, such as:
C:\Windows\SysWOW64\cmd.exe
Upvotes: 2