Hi,

I've written a .NET app, using VS2010 on Windows 7, that retrieves
information from the GroupWise Admin API. I've found an issue attempting to
fetch or iterate over the DMS Libraries. I've created a sample application
that I'm including which illustrates the problem.

Any attempt to access a DMS Library object throws an exception indicating
the following:

System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.

Can someone have a look at it and let me know if this is a bug or a
permissions problem.

I would appreciate some insight or some direction on this.

Thanks
Tim

Sample Application (files included as message body since post filter rejects
ZIP files)
************************************************** **************************************

Form1.cs
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace GroupWiseAdminSample

{

public partial class Form1 : Form

{

const string poDN = "TSPO.DEVORG";

const string libraryDN = "TSPO Library.DEVORG";

const string domainPath = @"\\MSHQ-CONTACT\Novell\MAIL\TSDOMAIN";

GWAdministrator _gwAdmin;

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

_gwAdmin = new GWAdministrator(domainPath);

_gwAdmin.Connect();

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

_gwAdmin.Dispose();

}

private void button1_Click(object sender, EventArgs e)

{

DocumentLibrary library = _gwAdmin.GetDocumentLibraryByDN(poDN, libraryDN);

if (library != null)

{

// create list item for library

//

}

}

private void button2_Click(object sender, EventArgs e)

{

Close();

}

}

}



DocumentLibrary.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml.Serialization;

namespace GroupWiseAdminSample

{

public class DocumentLibrary

{

public DocumentLibrary() { }

[XmlAttribute()]

public string Name { get; set; }

[XmlAttribute()]

public string ID { get; set; }

[XmlAttribute()]

public string DistinguishedName { get; set; }

public List<DocumentType> DocumentTypes { get; set; }

public List<FieldDefinition> FieldDefinitions { get; set; }

}

}



DocumentType.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml.Serialization;

namespace GroupWiseAdminSample

{

public class DocumentType

{

public DocumentType() { }

[XmlAttribute()]

public string Name { get; set; }

[XmlAttribute()]

public int LifeTime { get; set; }

[XmlAttribute()]

public int MaxVersionCount { get; set; }

}

}



FieldDefinition.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml.Serialization;

namespace GroupWiseAdminSample

{

public enum FieldType

{

String = 1,

Numeric = 2,

Date = 3,

Binary = 4

};

public enum StringCaseType

{

Upper = 1,

Lower = 2,

Mixed = 3

};

public class FieldDefinition

{

[XmlAttribute()]

public string Name { get; set; }

[XmlAttribute()]

public FieldType Type { get; set; }

[XmlAttribute()]

public bool ReadOnly { get; set; }

[XmlAttribute()]

public bool Required { get; set; }

[XmlAttribute()]

public StringCaseType StringCase { get; set; }

}

}



GWAdministrator.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using AdminTypeLibrary;

namespace GroupWiseAdminSample

{

public class GWAdministrator: IDisposable

{

private IADSystem _system;

public GWAdministrator(string domainPath) { this.DomainPath = domainPath; }

public string DomainPath { get; private set; }

public bool Connect()

{

try

{

// connect to GroupWise domain database

//

this._system = (IADSystem)(new SystemClass());

this._system.Connect(this.DomainPath);

}

catch

{

return false;

}

return true;

}

public void Disconnect()

{

if (this._system != null)

this._system = null;

}

public void Dispose()

{

this.Disconnect();

}

public List<DocumentLibrary> GetDocumentLibraries(string postOfficeId)

{

List<DocumentLibrary> libraries = new List<DocumentLibrary>();

try

{

var gwPostOffice =
(IADPostOffice)this._system.PostOffices.ItemByObje ctID(postOfficeId);

var iterator =
(IADDMSLibrariesIterator)gwPostOffice.Libraries.Cr eateIterator();

var gwLibrary = (IADDMSLibrary)iterator.Next(); // fails here with exception
cannot read from or write to protected memory

while (gwLibrary != null)

{

try

{

var library = new DocumentLibrary

{

Name = gwLibrary.Name,

ID = gwLibrary.ObjectID,

DistinguishedName = gwLibrary.DistinguishedName,

DocumentTypes = GetDocumentTypes(gwLibrary.ObjectID),

FieldDefinitions = GetFieldDefinitions(gwLibrary.ObjectID)

};

// add to list

libraries.Add(library);

// next user

gwLibrary = (IADDMSLibrary)iterator.Next();

} // trap iteration and library creation errors

catch (Exception e)

{

Console.WriteLine(e);

}

}

} // trap postoffice retrieval and first iteration errors

catch (Exception e)

{

Console.WriteLine(e);

}

return libraries;

}

public List<DocumentType> GetDocumentTypes(string libraryId)

{

List<DocumentType> documentTypes = new List<DocumentType>();

try

{

var gwLibrary = (IADDMSLibrary)this._system.ItemByObjectID(library Id); //
library object id

if (gwLibrary != null)

{

//var gwDocumentTypes = gwLibrary;

//var iterator = (IADDMSLibrariesIterator)gwLibrarieCreateIterator( );

//var gwLibrary = (IADDMSLibrary)iterator.Next();

//var library = new Data.DocumentLibrary

//{

// Name = gwLibrary.Name,

// ID = gwLibrary.ObjectID,

// DistinguishedName = gwLibrary.DistinguishedName

//};

//// add to list

//libraries.Add(library);

//// next user

//gwLibrary = (IADDMSLibrary)iterator.Next();

}

} // trap library retrieval errors

catch (Exception e)

{

Console.WriteLine(e);

}

return documentTypes;

}

public List<FieldDefinition> GetFieldDefinitions(string libraryId)

{

List<FieldDefinition> fieldDefinitions = new List<FieldDefinition>();

try

{

var gwLibrary = (IADDMSLibrary)this._system.ItemByObjectID(library Id); //
library object id

if (gwLibrary != null)

{

var gwFields = (IADDMSFieldDefinitions)gwLibrary.FieldDefinitions ;

foreach (IADDMSFieldDefinition gwField in gwFields)

{

try

{

var field = new FieldDefinition

{

Name = gwField.Name,

Type = (FieldType)gwField.DataType,

ReadOnly = gwField.ReadOnly,

Required = gwField.Required,

StringCase = (StringCaseType)gwField.StringCase

};

// add to list

//

fieldDefinitions.Add(field);

} // trap iteration and fieldDefinition creation errors

catch (Exception e)

{

Console.WriteLine(e);

}

}

}

} // trap library retrieval error

catch (Exception e)

{

Console.WriteLine(e);

}

// return field definitions

//

return fieldDefinitions;

}

public DocumentLibrary GetDocumentLibrary(string libraryId)

{

// document library object to be returned

//

DocumentLibrary documentLibrary = null;

try

{

var gwLibrary = (IADDMSLibrary)this._system.ItemByObjectID(library Id); //
fails here with exception cannot read from or write to protected memory

if (gwLibrary != null)

{

var library = new DocumentLibrary

{

Name = gwLibrary.Name,

ID = gwLibrary.ObjectID,

DistinguishedName = gwLibrary.DistinguishedName,

DocumentTypes = GetDocumentTypes(gwLibrary.ObjectID),

FieldDefinitions = GetFieldDefinitions(gwLibrary.ObjectID)

};

//

//

documentLibrary = library;

}

}

catch (Exception e)

{

Console.WriteLine(e);

}

// return document library

//

return documentLibrary;

}

public DocumentLibrary GetDocumentLibraryByDN(string postOfficeDN, string
libraryDN)

{

// document library object to be returned

//

DocumentLibrary documentLibrary = null;

try

{

var gwPostOffice =
(IADPostOffice)this._system.PostOffices.ItemByDN(p ostOfficeDN);

var gwLibrary = (IADDMSLibrary)gwPostOffice.Libraries.ItemByDN(lib raryDN);
// fails here with exception cannot read from or write to protected memory

if (gwLibrary != null)

{

var library = new DocumentLibrary

{

Name = gwLibrary.Name,

ID = gwLibrary.ObjectID,

DistinguishedName = gwLibrary.DistinguishedName,

DocumentTypes = GetDocumentTypes(gwLibrary.ObjectID),

FieldDefinitions = GetFieldDefinitions(gwLibrary.ObjectID)

};

//

//

documentLibrary = library;

}

}

catch (Exception e)

{

Console.WriteLine(e);

}

// return document library

//

return documentLibrary;

}

}

}