MethodImplOptions.InternalCall gives Security Exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert A. van Ginkel

    #1

    MethodImplOptions.InternalCall gives Security Exception

    I have a strange C# problem. Is the following a bug? Because it should be
    possible to run unsafe code. How can I accomplish this? And where can I read
    more about this, because documentation on this is rare.

    I have a project where i need to use some internal calls. In this project I
    have 'Allow unsafe code blocks' set to true.
    And in my class i have:

    [MethodImpl(Meth odImplOptions.I nternalCall)]
    extern private static IntPtr GetInvalidHandl e();

    private static readonly IntPtr InvalidHandle = GetInvalidHandl e();

    At runtime I get a Runtime Error called:
    An unhandled exception of type 'System.Securit y.SecurityExcep tion' occurred
    in mydll.dll
    Additional information: Security error.

    Can you please clarrify the problem?

    Regards, Robert


  • Willy Denoyette [MVP]

    #2
    Re: MethodImplOptio ns.InternalCall gives Security Exception

    Robert A. van Ginkel wrote:
    || I have a strange C# problem. Is the following a bug? Because it
    || should be possible to run unsafe code. How can I accomplish this?
    || And where can I read more about this, because documentation on this
    || is rare.
    ||
    || I have a project where i need to use some internal calls. In this
    || project I have 'Allow unsafe code blocks' set to true.
    || And in my class i have:
    ||
    || [MethodImpl(Meth odImplOptions.I nternalCall)]
    || extern private static IntPtr GetInvalidHandl e();
    ||
    || private static readonly IntPtr InvalidHandle = GetInvalidHandl e();
    ||
    || At runtime I get a Runtime Error called:
    || An unhandled exception of type 'System.Securit y.SecurityExcep tion'
    || occurred in mydll.dll
    || Additional information: Security error.
    ||
    || Can you please clarrify the problem?
    ||
    || Regards, Robert

    You can't do this. The explicit use of internalcall will cause
    the execution engine to throw a System.Security .SecurityExcept ion.
    "MethodImplOpti ons.InternalCal l" is used to declare a method in managed code that has no
    managed implementation. The implementation (unmanaged) is supplied by the runtime itself (CLR).

    What exactly are you trying to achieve?

    Willy.


    Comment

    • Robert A. van Ginkel

      #3
      Re: MethodImplOptio ns.InternalCall gives Security Exception

      Thanx for replying Willy,

      I know that there is managed code and unmanaged, what the difference is I
      don't know, I will look this up shortly but what I can understand is that
      because I dont have the source of Framework with *.pdb files and headers and
      stuff, I can't call it.
      First of all why can't I just call these function's, like calling api's in
      vb6? And can I never achieve this or should I first do something?

      On the question what am I making:
      A new socket lib., because with the framework his System.Net.Sock ets
      assembly it happends that if you send data to a server and when that server
      closes the socket (i.e. smtp, quit command) it sometimes happens that the
      socket hangs. First of all Framework is Cool, Development Enviroment Sucks,
      Why, because if you pause he stops all threads and breaks at the main, there
      is no thread monitor where u can choose which thread to pause. And if I am
      listening to a port in a thread, I can't Abort that thread.
      So I looked around and found some smart guys from Southern Storm Software
      that made .NET for unix, ok so I had the source of .NET, great, I ripped out
      Socket, TcpClient, Networkstream, TcpListener and compiled this, and found
      myself with a security problem.

      How can I solve this?

      ----- Original Message -----
      From: "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be>
      Newsgroups:
      microsoft.publi c.dotnet.academ ic,microsoft.pu blic.dotnet.fra mework,microsof t
      ..public.dotnet .framework.clr, microsoft.publi c.dotnet.langua ges.csharp,micr os
      oft.public.msdn .drgui.drguidot net.discussion
      Sent: Monday, August 25, 2003 12:17 PM
      Subject: Re: MethodImplOptio ns.InternalCall gives Security Exception

      [color=blue]
      > Robert A. van Ginkel wrote:
      > || I have a strange C# problem. Is the following a bug? Because it
      > || should be possible to run unsafe code. How can I accomplish this?
      > || And where can I read more about this, because documentation on this
      > || is rare.
      > ||
      > || I have a project where i need to use some internal calls. In this
      > || project I have 'Allow unsafe code blocks' set to true.
      > || And in my class i have:
      > ||
      > || [MethodImpl(Meth odImplOptions.I nternalCall)]
      > || extern private static IntPtr GetInvalidHandl e();
      > ||
      > || private static readonly IntPtr InvalidHandle = GetInvalidHandl e();
      > ||
      > || At runtime I get a Runtime Error called:
      > || An unhandled exception of type 'System.Securit y.SecurityExcep tion'
      > || occurred in mydll.dll
      > || Additional information: Security error.
      > ||
      > || Can you please clarrify the problem?
      > ||
      > || Regards, Robert
      >
      > You can't do this. The explicit use of internalcall will cause
      > the execution engine to throw a System.Security .SecurityExcept ion.
      > "MethodImplOpti ons.InternalCal l" is used to declare a method in managed[/color]
      code that has no[color=blue]
      > managed implementation. The implementation (unmanaged) is supplied by the[/color]
      runtime itself (CLR).[color=blue]
      >
      > What exactly are you trying to achieve?
      >
      > Willy.
      >
      >[/color]


      Comment

      Working...