Accessing com classes from c#

S

Stephan Zaubzer

Hi
I relatively new to C# and at the moment I am having troubles accessing
com objects within C#.
I am working in VS.net. I add the com library I want to access to my
references. Accessing classes exported in this com interfaces will throw
a System.Security.SecurityException.
(System.Security.Permissions.SecurityPermission)
Status of failed permission:

<IPermission class="System.Security.Permissions.SecurityPermission,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
version="1"
Flags="UnmanagedCode"/>

I also tried inserting the following code before trying to call
unmanaged code, but with no success.

SecurityPermission perm = new
SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
perm.Assert();

Any Ideas?

Regards
Stephan
 
N

Nicholas Paldino [.NET/C# MVP]

Stephan,

Where are you running this application from? Is it an ASP.NET
application, or are you running it from the web, or a network share?

In any of these situations, you are not given permissions to run
unmanaged code. This is why your calls are failing, most likely.

If this is the case, to fix this, you have to go to the .NET framework
administration tool (it's under administrative tools) and change the
permission sets for the app (based on it's hash, a strong name, or other
identifier) so that you have unmanaged code permission.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top