Problem with Loading Assemblies from Add in  
Author Message
Teddy79





PostPosted: Visual C# General, Problem with Loading Assemblies from Add in Top

Hi all,
I'm doing an add in for Excel. I want to load dll files using Assembly.LoadFrom(string filePath). However there is the exception:

Could not load file or assembly 'DataAccess, Version=1.0.2468.3302, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)

I tried loading same dll file still using LoadForm but in a test console program, it could load. So I guess the problem is about some thing with Excel that prevents from loading assemblies from an Excel Add in I don't know what it is. I run the .NET configuration snapin to evaluate permissions to the dll file, it says "Unrestricted" in all 3 levels. Any idea Thanks in advance


Visual C#11  
 
 
OmegaMan





PostPosted: Visual C# General, Problem with Loading Assemblies from Add in Top

I would surmise it is a .net Trust issue. Excel does not want a marcro or add-in to load anything it does not know about so one uses CasPol to manage trust. This is from MSDN documentation on setting up a VSTO remote assembly, the principle is the same...


1. On the end user computer, click Start, point to All Programs, point to Accessories, and then click Command Prompt.
2. Type the following command to create a new code group that grants full trust to the assembly.
%windir%\Microsoft.NET\Framework\v2.0.50727\caspol -u -ag All_Code -url "<full assembly path>" FullTrust -n "<name>"
Replace <full assembly path> with the full path of the assembly on the end user computer—for example, C:\DeploymentFolder\WordDocument1.dll.
The -n parameter specifies a name for the new code group. This parameter is not required, but specifying a label makes it easier to later identify and remove the new code group after you have completed this Quick Start.
3. Click Yes when prompted to confirm that you want to perform the operation, and press ENTER.
4. Open the deployed document and verify that the message box appears.