Professional Web Applications Themes

dll import - ASP.NET Web Services

I have created a dll from a C++ class using .Net and have imported it into my C# applications (one webservice, one standalone app). It works fine for a while, but will eventually fail to produce the error "System.NullReferenceException: Object reference not set to an instance of an object" when calling a method from the dll. In the case of the webservice, after it fails once it continues to fail until I reboot. My searches have been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1 for the webservice. The only suggestion I have found through ...

  1. #1

    Default dll import

    I have created a dll from a C++ class using .Net and have imported it into my
    C# applications (one webservice, one standalone app). It works fine for a
    while, but will eventually fail to produce the error
    "System.NullReferenceException: Object reference not set to an instance of an
    object" when calling a method from the dll. In the case of the webservice,
    after it fails once it continues to fail until I reboot. My searches have
    been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1 for
    the webservice.

    The only suggestion I have found through search is to check the permissions,
    which I have done, but I could probably use some more detailed instructions
    on how to do this.

    Any suggestions on how I might fix this problem?



    The code:

    DLL call that produces the error:
    IntPtr pMSG = MSG_Class.CreateMSGClass();

    and also:
    byte[] Message = new byte[MSG_Class.GetBufferSize(pMSG)];
    MSG_Class.GetBuffer(pMSG , Message); // this fails occasionally


    import:
    DLL Import class:
    [DllImport("MSG_1.dll")]
    public static extern IntPtr CreateMSGClass ();

    [DllImport("MSG_1.dll",CallingConvention=CallingCon vention.ThisCall)]
    public static extern void GetBuffer( IntPtr instance, byte [] bufferOut );


    C++ (from which the dll was created):
    CreateMSGClass:
    return new MSGClass();

    void MSG_Class::GetBuffer(char * BufferOut) {
    memcpy(BufferOut, TheBuffer, sizeof(TheBuffer);
    }




    Jason Guest

  2. #2

    Default Re: dll import

    You should be able to easily determine what is null when it should not be by
    testing for null before using your objects. What has your debugging told
    you, if anything?

    Dale Preston

    "Jason" <Jasondiscussions.microsoft.com> wrote in message
    news:53610F64-0E5F-4718-8930-BFF8E91976DFmicrosoft.com...
    > I have created a dll from a C++ class using .Net and have imported it into
    my
    > C# applications (one webservice, one standalone app). It works fine for a
    > while, but will eventually fail to produce the error
    > "System.NullReferenceException: Object reference not set to an instance of
    an
    > object" when calling a method from the dll. In the case of the
    webservice,
    > after it fails once it continues to fail until I reboot. My searches have
    > been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1
    for
    > the webservice.
    >
    > The only suggestion I have found through search is to check the
    permissions,
    > which I have done, but I could probably use some more detailed
    instructions
    > on how to do this.
    >
    > Any suggestions on how I might fix this problem?
    >
    >
    >
    > The code:
    >
    > DLL call that produces the error:
    > IntPtr pMSG = MSG_Class.CreateMSGClass();
    >
    > and also:
    > byte[] Message = new byte[MSG_Class.GetBufferSize(pMSG)];
    > MSG_Class.GetBuffer(pMSG , Message); // this fails occasionally
    >
    >
    > import:
    > DLL Import class:
    > [DllImport("MSG_1.dll")]
    > public static extern IntPtr CreateMSGClass ();
    >
    > [DllImport("MSG_1.dll",CallingConvention=CallingCon vention.ThisCall)]
    > public static extern void GetBuffer( IntPtr instance, byte [] bufferOut );
    >
    >
    > C++ (from which the dll was created):
    > CreateMSGClass:
    > return new MSGClass();
    >
    > void MSG_Class::GetBuffer(char * BufferOut) {
    > memcpy(BufferOut, TheBuffer, sizeof(TheBuffer);
    > }
    >
    >
    >
    >

    Dale Preston Guest

  3. #3

    Default Re: dll import

    Debugging has not produced any information that seems helpful. My byte array
    is created successfully and the IntPtr contains a seemingly valid value after
    the CreateMSGClass method executes successfully.

    I think I may be misunderstanding something basic about dlls. The error
    that was previously occurring when instantiating the class from the dll
    seemed to have stopped once I made the IntPtr to the class a member variable
    of my C# class (instead of a variable local to the class method in which it
    was being used) and removed the second instance of the class. I was
    previously trying to create multiple instances of the class. Should I be able
    to do this?
    For example:
    IntPtr pMSG1 = MSG_Class.CreateMSGClass();
    IntPtr pMSG2 = MSG_Class.CreateMSGClass();

    The class packaged in the DLL contains a pointer to a char array member
    which is modified (and sometimes resized) through set accessors member
    functions. Is this ok to do?

    The failing GetBuffer() method is copying this array into the
    pre-initialized byte array which I have verified is created successfully in
    the C# code. The method is contained within the dll so, as far as I know, I
    cannot step into that code to see what the data is set to, or verfiy that the
    array is passed in successfully. Is there any way to do this or is there any
    other way to figure out if something inside a method in the dll is set to
    null?


    Thanks,
    Jason





    "Dale Preston" wrote:
    > You should be able to easily determine what is null when it should not be by
    > testing for null before using your objects. What has your debugging told
    > you, if anything?
    >
    > Dale Preston
    >
    > "Jason" <Jasondiscussions.microsoft.com> wrote in message
    > news:53610F64-0E5F-4718-8930-BFF8E91976DFmicrosoft.com...
    > > I have created a dll from a C++ class using .Net and have imported it into
    > my
    > > C# applications (one webservice, one standalone app). It works fine for a
    > > while, but will eventually fail to produce the error
    > > "System.NullReferenceException: Object reference not set to an instance of
    > an
    > > object" when calling a method from the dll. In the case of the
    > webservice,
    > > after it fails once it continues to fail until I reboot. My searches have
    > > been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1
    > for
    > > the webservice.
    > >
    > > The only suggestion I have found through search is to check the
    > permissions,
    > > which I have done, but I could probably use some more detailed
    > instructions
    > > on how to do this.
    > >
    > > Any suggestions on how I might fix this problem?
    > >
    > >
    > >
    > > The code:
    > >
    > > DLL call that produces the error:
    > > IntPtr pMSG = MSG_Class.CreateMSGClass();
    > >
    > > and also:
    > > byte[] Message = new byte[MSG_Class.GetBufferSize(pMSG)];
    > > MSG_Class.GetBuffer(pMSG , Message); // this fails occasionally
    > >
    > >
    > > import:
    > > DLL Import class:
    > > [DllImport("MSG_1.dll")]
    > > public static extern IntPtr CreateMSGClass ();
    > >
    > > [DllImport("MSG_1.dll",CallingConvention=CallingCon vention.ThisCall)]
    > > public static extern void GetBuffer( IntPtr instance, byte [] bufferOut );
    > >
    > >
    > > C++ (from which the dll was created):
    > > CreateMSGClass:
    > > return new MSGClass();
    > >
    > > void MSG_Class::GetBuffer(char * BufferOut) {
    > > memcpy(BufferOut, TheBuffer, sizeof(TheBuffer);
    > > }
    > >
    > >
    > >
    > >
    >
    >
    >
    Jason Guest

Similar Threads

  1. FDF Import
    By gundlaR@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 9
    Last Post: July 30th, 07:34 PM
  2. SWF import ID3.1
    By decorix29@adobeforums.com in forum Adobe Indesign Windows
    Replies: 5
    Last Post: June 27th, 11:15 AM
  3. hoq to import a gif
    By Ferdynandus webforumsuser@macromedia.com in forum Macromedia Freehand
    Replies: 0
    Last Post: November 25th, 09:33 AM
  4. No CDR Import?
    By Linda Rathgeber in forum Macromedia Fireworks
    Replies: 0
    Last Post: September 18th, 10:57 PM
  5. CSV import
    By Jwulff in forum PHP Development
    Replies: 0
    Last Post: July 21st, 05:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139