>From 1de2c1babc844e138ca24450d25cd332f2f049e1 Mon Sep 17 00:00:00 2001
From: Arnaud <arnaud.champion@devatom.fr>
Date: Wed, 27 Oct 2010 13:43:56 +0200
Subject: [PATCH] Make examples work with mono compiled in 64bits, simplify the ConnectOpenAuth process

---
 Connect.cs                                         |   64 ++++++-
 Domain.cs                                          |    6 +-
 Error.cs => Errors.cs                              |   22 +-
 Event.cs                                           |   12 +-
 MarshalHelper.cs                                   |   16 ++-
 Node.cs                                            |    2 +-
 StoragePool.cs                                     |    8 +-
 StorageVol.cs                                      |    2 +-
 Types.cs                                           |  196 +++++++++++++-------
 .../MonoDevelop/virConnectOpenAuth/MainWindow.cs   |   58 +++----
 examples/VisualStudio/virConnectOpenAuth/Form1.cs  |   56 +++----
 projects/MonoDevelop/LibvirtBindings.csproj        |    6 +-
 projects/MonoDevelop/LibvirtBindings.sln           |    2 +-
 projects/VisualStudio/LibvirtBindings.csproj       |    7 +-
 14 files changed, 282 insertions(+), 175 deletions(-)
 rename Error.cs => Errors.cs (86%)

diff --git a/Connect.cs b/Connect.cs
index 374af35..5530c32 100644
--- a/Connect.cs
+++ b/Connect.cs
@@ -380,8 +380,66 @@ namespace Libvirt
         ///<param name="flags">Open flags</param>
         ///<returns>a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virConnectOpenAuth")]
-        public static extern IntPtr OpenAuth(string name, ref virConnectAuth auth, int flags);
+        private static extern IntPtr OpenAuth(string name, ref ConnectAuthUnmanaged auth, int flags);
+        /// <summary>
+        /// This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback See virConnectOpen for notes about environment variables which can have an effect on opening drivers
+        /// </summary>
+        /// <param name="name">URI of the hypervisor</param>
+        /// <param name="auth">Authenticate callback parameters</param>
+        /// <param name="flags">Open flags</param>
+        /// <returns>a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html </returns>
+        public static IntPtr OpenAuth(string name, ref ConnectAuth auth, int flags)
+        {
+            // Create a structure that hold cbdata and the callback target
+            OpenAuthManagedCB cbAndUserData = new OpenAuthManagedCB();
+            cbAndUserData.cbdata = auth.cbdata;
+            cbAndUserData.cbManaged = auth.cb;
+            // Pass the structure as cbdata
+            IntPtr cbAndUserDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbAndUserData));
+            Marshal.StructureToPtr(cbAndUserData, cbAndUserDataPtr, true);
+
+            // Create the real ConnectAuth structure, it will call OpenAuthCallbackFromUnmanaged via callback
+            ConnectAuthUnmanaged connectAuth = new ConnectAuthUnmanaged();
+            connectAuth.cbdata = cbAndUserDataPtr;
+            connectAuth.cb = OpenAuthCallbackFromUnmanaged;
+            connectAuth.CredTypes = auth.CredTypes;
 
+            return OpenAuth(name, ref connectAuth, flags);
+        }
+
+        private static int OpenAuthCallbackFromUnmanaged(IntPtr creds, uint ncreds, IntPtr cbdata)
+        {
+            // Give back the structure that hold cbdata and the callback target
+            OpenAuthManagedCB cbAndUserData = (OpenAuthManagedCB)Marshal.PtrToStructure(cbdata, typeof(OpenAuthManagedCB));
+            int offset = 0;
+            int credIndex = 0;
+
+            ConnectCredential[] cc = new ConnectCredential[ncreds];
+            // Loop thru credentials and initialize the ConnectCredential array
+            while (credIndex < ncreds)
+            {
+                IntPtr currentCred = MarshalHelper.IntPtrOffset(creds, offset);
+                ConnectCredential cred = (ConnectCredential)Marshal.PtrToStructure(currentCred, typeof(ConnectCredential));
+                offset += Marshal.SizeOf(cred);
+                cc[credIndex] = cred;
+                credIndex++;
+            }
+            // Call the delegate with the ConnectCredential array, this allow the user to answer the result
+            cbAndUserData.cbManaged(ref cc, cbAndUserData.cbdata);
+
+            offset = 0;
+            credIndex = 0;
+            // Loop thru ConnectCredential array and copy back to unmanaged memory
+            while (credIndex < ncreds)
+            {
+                IntPtr currentCred = MarshalHelper.IntPtrOffset(creds, offset);
+                Marshal.StructureToPtr(cc[credIndex], currentCred, true);
+                offset += Marshal.SizeOf(cc[credIndex]);
+                credIndex++;
+            }
+
+            return 0;
+        }
         /// <summary>
         /// This function should be called first to get a restricted connection to the library functionalities. The set of APIs usable are then restricted on the available methods to control the domains. See virConnectOpen for notes about environment variables which can have an effect on opening drivers
         /// </summary>
@@ -405,7 +463,7 @@ namespace Libvirt
         /// <param name="ff">optional function to deallocate opaque when not used anymore</param>
         /// <returns>t shall take a reference to it, by calling virDomainRef. The reference can be released once the object is no longer required by calling virDomainFree. Returns 0 on success, -1 on failure</returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virConnectDomainEventRegister")]
-        public static extern int DomainEventRegister(IntPtr conn, [MarshalAs(UnmanagedType.FunctionPtr)] virConnectDomainEventCallback cb,
-                                                                IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] virFreeCallback ff);
+        public static extern int DomainEventRegister(IntPtr conn, [MarshalAs(UnmanagedType.FunctionPtr)] ConnectDomainEventCallback cb,
+                                                                IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] FreeCallback ff);
     }
 }
diff --git a/Domain.cs b/Domain.cs
index cf83fc2..6d32300 100644
--- a/Domain.cs
+++ b/Domain.cs
@@ -42,7 +42,7 @@ namespace Libvirt
         /// <param name="size">size of stats structure</param>
         /// <returns>0 in case of success or -1 in case of failure.</returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainBlockStats")]
-        public static extern int BlockStats(IntPtr dom, string path, virDomainBlockStatsStruct stats, int size);
+        public static extern int BlockStats(IntPtr dom, string path, DomainBlockStatsStruct stats, int size);
         /// <summary>
         /// This method will dump the core of a domain on a given file for analysis. Note that for remote Xen Daemon the file path will be interpreted in the remote host.
         /// </summary>
@@ -197,7 +197,7 @@ namespace Libvirt
         /// 0 in case of success and -1 in case of failure.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainGetInfo")]
-        public static extern int GetInfo(IntPtr domain, [Out] virDomainInfo info);
+        public static extern int GetInfo(IntPtr domain, [Out] DomainInfo info);
         /// <summary>
         /// Retrieve the maximum amount of physical memory allocated to a domain. 
         /// If domain is NULL, then this get the amount of memory reserved to Domain0 i.e. the domain where the application runs.
@@ -323,7 +323,7 @@ namespace Libvirt
         /// 0 in case of success or -1 in case of failure.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainInterfaceStats")]
-        public static extern int InterfaceStats(IntPtr dom, string path, virDomainInterfaceStatsStruct stats, int size);
+        public static extern int InterfaceStats(IntPtr dom, string path, DomainInterfaceStatsStruct stats, int size);
         /// <summary>
         /// Determine if the domain is currently running.
         /// </summary>
diff --git a/Error.cs b/Errors.cs
similarity index 86%
rename from Error.cs
rename to Errors.cs
index 8d424f2..921d067 100644
--- a/Error.cs
+++ b/Errors.cs
@@ -15,7 +15,7 @@ namespace Libvirt
     ///<summary>
     /// class for libvirt errors binding
     ///</summary>
-    public class Error
+    public class Errors
     {
         /// <summary>
         /// The error object is kept in thread local storage, so separate threads can safely access this concurrently. 
@@ -25,7 +25,7 @@ namespace Libvirt
         /// A <see cref="IntPtr"/> pointer to the hypervisor connection.
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virConnResetLastError")]
-        public static extern void virConnResetLastError(IntPtr conn);
+        public static extern void ConnResetLastError(IntPtr conn);
 
         /// <summary>
         /// Set a connection error handling function, if @handler is NULL it will reset to default 
@@ -41,7 +41,7 @@ namespace Libvirt
         /// A <see cref="virErrorFunc"/>function to get called in case of error or NULL
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virConnSetErrorFunc")]
-        public static extern void virConnSetErrorFunc(IntPtr conn, IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)]virErrorFunc handler);
+        public static extern void ConnSetErrorFunc(IntPtr conn, IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)] ErrorFunc handler);
 
         /// <summary>
         /// Copy the content of the last error caught at the library level. 
@@ -55,7 +55,7 @@ namespace Libvirt
         /// 0 if no error was found and the error code otherwise and -1 in case of parameter error.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virCopyLastError")]
-        public static extern int virCopyLastError([Out] virError to);
+        public static extern int CopyLastError([Out] Error to);
 
         /// <summary>
         /// Default routine reporting an error to stderr.
@@ -64,7 +64,7 @@ namespace Libvirt
         /// A <see cref="virError"/> pointer to the error.
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDefaultErrorFunc")]
-        public static extern void virDefaultErrorFunc([In] virError err);
+        public static extern void DefaultErrorFunc([In] Error err);
 
         /// <summary>
         /// Resets and frees the given error.
@@ -73,7 +73,7 @@ namespace Libvirt
         /// A <see cref="virError"/> error to free.
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virFreeError")]
-        public static extern void virFreeError(virError err); // Does not work, anybody know why?
+        public static extern void FreeError(Error err); // Does not work, anybody know why?
 
         /// <summary>
         /// Provide a pointer to the last error caught at the library level. 
@@ -83,7 +83,7 @@ namespace Libvirt
         /// A pointer to the last error or NULL if none occurred.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virGetLastError")]
-        public static extern int virGetLastError();
+        public static extern int GetLastError();
 
         /// <summary>
         /// Reset the error being pointed to.
@@ -92,14 +92,14 @@ namespace Libvirt
         /// A <see cref="virError"/> pointer to the to clean up.
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virResetError")]
-        public static extern void virResetError(virError err);
+        public static extern void ResetError(Error err);
 
         /// <summary>
         /// Reset the last error caught at the library level. The error object is kept in thread local storage, 
         /// so separate threads can safely access this concurrently, only resetting their own error object.
         /// </summary>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virResetLastError")]
-        public static extern void virResetLastError();
+        public static extern void ResetLastError();
 
         /// <summary>
         /// Save the last error into a new error object.
@@ -109,7 +109,7 @@ namespace Libvirt
         /// It is the caller's responsibility to free the error with virFreeError().
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virSaveLastError")]
-        public static extern virError virSaveLastError();
+        public static extern Error SaveLastError();
 
         /// <summary>
         /// Set a library global error handling function, if @handler is NULL, it will reset to default printing on stderr. 
@@ -122,6 +122,6 @@ namespace Libvirt
         /// A <see cref="virErrorFunc"/>function to get called in case of error or NULL.
         /// </param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virSetErrorFunc")]
-        public static extern void virSetErrorFunc(IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)]virErrorFunc handler);
+        public static extern void SetErrorFunc(IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)] ErrorFunc handler);
     }
 }
diff --git a/Event.cs b/Event.cs
index 821d2e1..1540d70 100644
--- a/Event.cs
+++ b/Event.cs
@@ -22,11 +22,11 @@ namespace Libvirt
         ///<param name="updateTimeout">the virEventUpdateTimeoutFunc which will be called (a delegate)</param>
         ///<param name="removeTimeout">the virEventRemoveTimeoutFunc which will be called (a delegate)</param>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virEventRegisterImpl")]
-        public static extern void RegisterImpl([MarshalAs(UnmanagedType.FunctionPtr)]virEventAddHandleFunc addHandle,
-                                               [MarshalAs(UnmanagedType.FunctionPtr)]virEventUpdateHandleFunc updateHandle,
-                                               [MarshalAs(UnmanagedType.FunctionPtr)]virEventRemoveHandleFunc removeHandle,
-                                               [MarshalAs(UnmanagedType.FunctionPtr)]virEventAddTimeoutFunc addTimeout,
-                                               [MarshalAs(UnmanagedType.FunctionPtr)]virEventUpdateTimeoutFunc updateTimeout,
-                                               [MarshalAs(UnmanagedType.FunctionPtr)]virEventRemoveTimeoutFunc removeTimeout);
+        public static extern void RegisterImpl([MarshalAs(UnmanagedType.FunctionPtr)] EventAddHandleFunc addHandle,
+                                               [MarshalAs(UnmanagedType.FunctionPtr)] EventUpdateHandleFunc updateHandle,
+                                               [MarshalAs(UnmanagedType.FunctionPtr)] EventRemoveHandleFunc removeHandle,
+                                               [MarshalAs(UnmanagedType.FunctionPtr)] EventAddTimeoutFunc addTimeout,
+                                               [MarshalAs(UnmanagedType.FunctionPtr)] EventUpdateTimeoutFunc updateTimeout,
+                                               [MarshalAs(UnmanagedType.FunctionPtr)] EventRemoveTimeoutFunc removeTimeout);
     }
 }
diff --git a/MarshalHelper.cs b/MarshalHelper.cs
index bf622f7..fc93893 100644
--- a/MarshalHelper.cs
+++ b/MarshalHelper.cs
@@ -7,10 +7,7 @@
  */
 
 using System;
-using System.Collections.Generic;
-using System.Linq;
 using System.Runtime.InteropServices;
-using System.Text;
 
 namespace Libvirt
 {
@@ -32,5 +29,18 @@ namespace Libvirt
             IntPtr s = Marshal.ReadIntPtr(stringPtr, IntPtr.Size);
             return Marshal.PtrToStringAnsi(s);
         }
+
+        public static IntPtr IntPtrOffset(IntPtr src, int offset)
+        {
+            switch (IntPtr.Size)
+            {
+                case 4:
+                    return new IntPtr(src.ToInt32() + offset);
+                case 8:
+                    return new IntPtr(src.ToInt64() + offset);
+                default:
+                    throw new NotSupportedException("Surprise!  This is running on a machine where pointers are " + IntPtr.Size + " bytes and arithmetic doesn't work in C# on them.");
+            }
+        }
     }
 }
diff --git a/Node.cs b/Node.cs
index 0560cf5..e4389f3 100644
--- a/Node.cs
+++ b/Node.cs
@@ -82,7 +82,7 @@ namespace Libvirt
         /// 0 in case of success and -1 in case of failure.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virNodeGetInfo")]
-        public static extern int GetInfo(IntPtr h, [Out] virNodeInfo info);
+        public static extern int GetInfo(IntPtr h, [Out] NodeInfo info);
 
         // TODO virNodeGetSecurityModel
 
diff --git a/StoragePool.cs b/StoragePool.cs
index 3952d5b..ec0d635 100644
--- a/StoragePool.cs
+++ b/StoragePool.cs
@@ -28,7 +28,7 @@ namespace Libvirt
         /// 0 on success, or -1 upon failure
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStoragePoolBuild")]
-        public static extern int Build(IntPtr pool, virStoragePoolBuildFlags flags);
+        public static extern int Build(IntPtr pool, StoragePoolBuildFlags flags);
 
         /// <summary>
         /// Starts an inactive storage pool.
@@ -96,7 +96,7 @@ namespace Libvirt
         /// 0 on success, or -1 if it could not be obliterate.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStoragePoolDelete")]
-        public static extern int Delete(IntPtr pool, virStoragePoolDeleteFlags flags);
+        public static extern int Delete(IntPtr pool, StoragePoolDeleteFlags flags);
 
         /// <summary>
         /// Destroy an active storage pool. This will deactivate the pool on the host, 
@@ -164,7 +164,7 @@ namespace Libvirt
         /// 0 on success, or -1 on failure.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStoragePoolGetInfo")]
-        public static extern int GetInfo(IntPtr pool, ref virStoragePoolInfo info);
+        public static extern int GetInfo(IntPtr pool, ref StoragePoolInfo info);
 
         /// <summary>
         /// Fetch the locally unique name of the storage pool.
@@ -237,7 +237,7 @@ namespace Libvirt
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStoragePoolGetXMLDesc")]
         [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StringWithoutNativeCleanUpMarshaler))]
-        public static extern string GetXMLDesc(IntPtr pool, virDomainXMLFlags flags);
+        public static extern string GetXMLDesc(IntPtr pool, DomainXMLFlags flags);
 
         /// <summary>
         /// Determine if the storage pool is currently running.
diff --git a/StorageVol.cs b/StorageVol.cs
index 96ae2e9..9730172 100644
--- a/StorageVol.cs
+++ b/StorageVol.cs
@@ -109,7 +109,7 @@ namespace Libvirt
         /// 0 on success, or -1 on failure.
         /// </returns>
         [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStorageVolGetInfo")]
-        public static extern int GetInfo(IntPtr vol, ref virStorageVolInfo info);
+        public static extern int GetInfo(IntPtr vol, ref StorageVolInfo info);
 
         /// <summary>
         /// Fetch the storage volume key. 
diff --git a/Types.cs b/Types.cs
index dfe8020..4609b6c 100644
--- a/Types.cs
+++ b/Types.cs
@@ -7,9 +7,10 @@
  */
 
 using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.IO;
 using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
 
 namespace Libvirt
 {
@@ -20,7 +21,8 @@ namespace Libvirt
     ///</summary>
     ///<param name="userData">user provided data for the error callback</param>
     ///<param name="error">the error being raised.</param>
-    public delegate void virErrorFunc(IntPtr userData, virError error);
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate void ErrorFunc(IntPtr userData, Error error);
     /// <summary>
     /// A callback function to be registered, and called when a domain event occurs
     /// </summary>
@@ -30,7 +32,7 @@ namespace Libvirt
     /// <param name="detail">event specific detail information</param>
     /// <param name="opaque">opaque user data</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virConnectDomainEventCallback(IntPtr conn, IntPtr dom, virDomainEventType evt, int detail, IntPtr opaque);
+    public delegate void ConnectDomainEventCallback(IntPtr conn, IntPtr dom, DomainEventType evt, int detail, IntPtr opaque);
     ///<summary>
     /// Callback for receiving file handle events. The callback will be invoked once for each event which is pending.
     ///</summary>
@@ -39,13 +41,13 @@ namespace Libvirt
     ///<param name="events">bitset of events from virEventHandleType constants</param>
     ///<param name="opaque">user data registered with handle</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virEventHandleCallback(int watch, int fd, int events, IntPtr opaque);
+    public delegate void EventHandleCallback(int watch, int fd, int events, IntPtr opaque);
     ///<summary>
     /// Free callbacks
     ///</summary>
     ///<param name="opaque">user data registered with handle</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virFreeCallback(IntPtr opaque);
+    public delegate void FreeCallback(IntPtr opaque);
     ///<summary>
     /// Part of the EventImpl, this callback Adds a file handle callback to listen for specific events. The same file handle can be registered multiple times provided the requested event sets are non-overlapping If the opaque user data requires free'ing when the handle is unregistered, then a 2nd callback can be supplied for this purpose.
     ///</summary>
@@ -56,27 +58,27 @@ namespace Libvirt
     ///<param name="ff">the callback invoked to free opaque data blob</param>
     ///<returns>a handle watch number to be used for updating and unregistering for events</returns>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int virEventAddHandleFunc(int fd, int events, virEventHandleCallback cb, IntPtr opaque, virFreeCallback ff);
+    public delegate int EventAddHandleFunc(int fd, int events, EventHandleCallback cb, IntPtr opaque, FreeCallback ff);
     ///<summary>
     /// Part of the EventImpl, this user-provided callback is notified when events to listen on change
     ///</summary>
     ///<param name="watch">file descriptor watch to modify</param>
     ///<param name="events">new events to listen on</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virEventUpdateHandleFunc(int watch, int events);
+    public delegate void EventUpdateHandleFunc(int watch, int events);
     ///<summary>
     /// Part of the EventImpl, this user-provided callback is notified when an fd is no longer being listened on. If a virEventHandleFreeFunc was supplied when the handle was registered, it will be invoked some time during, or after this function call, when it is safe to release the user data.
     ///</summary>
     ///<param name="watch">file descriptor watch to stop listening on</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int virEventRemoveHandleFunc(int watch);
+    public delegate int EventRemoveHandleFunc(int watch);
     ///<summary>
     /// callback for receiving timer events
     ///</summary>
     ///<param name="timer">timer id emitting the event</param>
     ///<param name="opaque">user data registered with handle</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virEventTimeoutCallback(int timer, IntPtr opaque);
+    public delegate void EventTimeoutCallback(int timer, IntPtr opaque);
     ///<summary>
     /// Part of the EventImpl, this user-defined callback handles adding an event timeout. If the opaque user data requires free'ing when the handle is unregistered, then a 2nd callback can be supplied for this purpose.
     ///</summary>
@@ -86,43 +88,65 @@ namespace Libvirt
     ///<param name="ff">the callback invoked to free opaque data blob</param>
     /// <returns>A timer value</returns>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int virEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb, IntPtr opaque, virFreeCallback ff);
+    public delegate int EventAddTimeoutFunc(int timeout, EventTimeoutCallback cb, IntPtr opaque, FreeCallback ff);
     ///<summary>
     /// Part of the EventImpl, this user-defined callback updates an event timeout.
     ///</summary>
     ///<param name="timer">the timer to modify</param>
     ///<param name="timeout">the new timeout value</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate void virEventUpdateTimeoutFunc(int timer, int timeout);
+    public delegate void EventUpdateTimeoutFunc(int timer, int timeout);
     ///<summary>
     /// Part of the EventImpl, this user-defined callback removes a timer If a virEventTimeoutFreeFunc was supplied when the handle was registered, it will be invoked some time during, or after this function call, when it is safe to release the user data.
     ///</summary>
     ///<param name="timer">the timer to remove</param>
     /// <returns>0 on success, -1 on failure</returns>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int virEventRemoveTimeoutFunc(int timer);
+    public delegate int EventRemoveTimeoutFunc(int timer);
     ///<summary>
     /// Authentication callback
     ///</summary>
-    ///<param name="cred">Pointer to a virConnectCredential array</param>
+    ///<param name="creds">virConnectCredential array</param>
     ///<param name="ncred">number of virConnectCredential in cred</param>
     ///<param name="cbdata">user data passed to callback</param>
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int virConnectAuthCallback(IntPtr cred, uint ncred, IntPtr cbdata);
+    public delegate int ConnectAuthCallbackUnmanaged(IntPtr creds, uint ncred, IntPtr cbdata);
+    /// <summary>
+    /// Authentication callback
+    /// </summary>
+    /// <param name="creds">ConnectCredential array</param>
+    /// <param name="cbdata">user data passed to callback</param>
+    /// <returns></returns>
+    public delegate int ConnectAuthCallback(ref ConnectCredential[] creds, IntPtr cbdata);
     #endregion
 
     #region structs
     /// <summary>
+    /// This is a struct used to simply the C# bindings, for C# bindings internal use only.
+    /// </summary>
+    public struct OpenAuthManagedCB
+    {
+        /// <summary>
+        /// Pointer to user data of the ConnectOpenAuth
+        /// </summary>
+        public IntPtr cbdata;
+        /// <summary>
+        /// The C# delegate which must be called
+        /// </summary>
+        public ConnectAuthCallback cbManaged;
+    }
+
+    /// <summary>
     /// the virError object
     /// </summary>
     [StructLayout(LayoutKind.Sequential)]
-    public class virError
+    public struct Error
     {
         /// <summary>
         /// The error code, a virErrorNumber.
         /// </summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virErrorNumber code;
+        public ErrorNumber code;
         /// <summary>
         /// What part of the library raised this error.
         /// </summary>
@@ -145,7 +169,7 @@ namespace Libvirt
         /// How consequent is the error.
         /// </summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virErrorLevel level;
+        public ErrorLevel level;
         /// <summary>
         /// Connection if available, deprecated see note above.
         /// </summary>
@@ -204,7 +228,7 @@ namespace Libvirt
     /// Blocks domain statistics
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virDomainBlockStatsStruct
+    public struct DomainBlockStatsStruct
     {
         /// <summary>
         /// Number of read requests.
@@ -232,7 +256,7 @@ namespace Libvirt
     /// Domain interface statistics
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virDomainInterfaceStatsStruct
+    public struct DomainInterfaceStatsStruct
     {
         ///<summary>
         /// Bytes received
@@ -272,7 +296,7 @@ namespace Libvirt
     /// Structure to handle connection authentication
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virConnectAuth
+    public struct ConnectAuthUnmanaged
     {
         /// <summary>
         /// List of supported virConnectCredentialType values, should be a IntPtr to an int array or to a virConnectCredentialType array
@@ -287,39 +311,78 @@ namespace Libvirt
         /// Callback used to collect credentials, a virConnectAuthCallback delegate in bindings
         ///</summary>
         [MarshalAs(UnmanagedType.FunctionPtr)]
-        public virConnectAuthCallback cb;
-        ///<summary>
-        /// Data transported with callback, should be a IntPtr on what you want
-        ///</summary>
-        private IntPtr cbdataPtr;
+        public ConnectAuthCallbackUnmanaged cb;
         ///<summary>
         /// Data transported with callback, should be a IntPtr on what you want
         ///</summary>
-        public Object cbdata
+        public IntPtr cbdata;
+        /// <summary>
+        /// List of supported virConnectCredentialType values
+        /// </summary>
+        public ConnectCredentialType[] CredTypes
         {
             get
             {
-                return Marshal.PtrToStructure(cbdataPtr, typeof(Object));
+                int[] intCredTypes = new int[ncredtype];
+                Marshal.Copy(credtypes, intCredTypes, 0, (int)ncredtype);
+                ConnectCredentialType[] result = new ConnectCredentialType[ncredtype];
+                for (int i = 0; i < intCredTypes.Length; i++)
+                {
+                    result[i] = (ConnectCredentialType)intCredTypes[i];
+                }
+                return result;
             }
             set
             {
-                cbdataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(value));
-                Marshal.StructureToPtr(value, cbdataPtr, false);
+                ncredtype = (uint)value.Length;
+                credtypes = Marshal.AllocHGlobal(value.Length * sizeof(int));
+                int[] vals = new int[value.Length];
+                for (int i = 0; i < value.Length; i++)
+                {
+                    vals[i] = (int)value[i];
+                }
+                Marshal.Copy(vals, 0, credtypes, (int)ncredtype);
             }
         }
+    }
+
+    ///<summary>
+    /// Structure to handle connection authentication
+    ///</summary>
+    [StructLayout(LayoutKind.Sequential)]
+    public struct ConnectAuth
+    {
+        /// <summary>
+        /// List of supported virConnectCredentialType values, should be a IntPtr to an int array or to a virConnectCredentialType array
+        /// </summary>
+        private IntPtr credtypes;
+        ///<summary>
+        /// Number of virConnectCredentialType in credtypes
+        ///</summary>
+        [MarshalAs(UnmanagedType.U4)]
+        private uint ncredtype;
+        ///<summary>
+        /// Callback used to collect credentials, a virConnectAuthCallback delegate in bindings
+        ///</summary>
+        [MarshalAs(UnmanagedType.FunctionPtr)]
+        public ConnectAuthCallback cb;
+        ///<summary>
+        /// Data transported with callback, should be a IntPtr on what you want
+        ///</summary>
+        public IntPtr cbdata;
         /// <summary>
         /// List of supported virConnectCredentialType values
         /// </summary>
-        public virConnectCredentialType[] CredTypes
+        public ConnectCredentialType[] CredTypes
         {
             get
             {
                 int[] intCredTypes = new int[ncredtype];
                 Marshal.Copy(credtypes, intCredTypes, 0, (int)ncredtype);
-				virConnectCredentialType[] result = new virConnectCredentialType[ncredtype];
+				ConnectCredentialType[] result = new ConnectCredentialType[ncredtype];
 				for (int i=0; i< intCredTypes.Length; i++)
 				{
-					result[i] = (virConnectCredentialType)i;
+                    result[i] = (ConnectCredentialType)intCredTypes[i];
 				}
                 return result;
             }
@@ -341,38 +404,34 @@ namespace Libvirt
     /// Credential structure
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public class virConnectCredential
+    public class ConnectCredential
     {
         ///<summary>
         /// One of virConnectCredentialType constants
         ///</summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virConnectCredentialType type;
+        public ConnectCredentialType type;
         ///<summary>
         /// Prompt to show to user
         ///</summary>
-        //[MarshalAs(UnmanagedType.LPStr)]
         private IntPtr prompt;
         ///<summary>
         /// Additional challenge to show
         ///</summary>
-        //[MarshalAs(UnmanagedType.LPStr)]
         private IntPtr challenge;
         ///<summary>
         /// Optional default result
         ///</summary>
-        //[MarshalAs(UnmanagedType.LPStr)]
         private IntPtr defresult;
         ///<summary>
         /// Result to be filled with user response (or defresult). An IntPtr to a marshalled allocated string
         ///</summary>
-        //[MarshalAs(UnmanagedType.LPStr)]
         private IntPtr result;
         ///<summary>
         /// Length of the result
         ///</summary>
         [MarshalAs(UnmanagedType.U4)]
-        public uint resultlen;
+        private uint resultlen;
         ///<summary>
         /// Prompt to show to user
         ///</summary>
@@ -415,6 +474,7 @@ namespace Libvirt
             set
             {
                 result = NativeFunctions.StrDup(Marshal.StringToHGlobalAnsi(value));
+                resultlen = (uint)value.Length;
             }
         }
     }
@@ -423,13 +483,13 @@ namespace Libvirt
     /// Structure for domain memory statistics
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virDomainMemoryStat
+    public struct DomainMemoryStat
     {
         /// <summary>
         /// Tag
         /// </summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virDomainMemoryStatTags tag;
+        public DomainMemoryStatTags tag;
         /// <summary>
         /// Value
         /// </summary>
@@ -441,13 +501,13 @@ namespace Libvirt
     /// Structure to handle volume informations
     ///</summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virStorageVolInfo
+    public struct StorageVolInfo
     {
         /// <summary>
         /// virStorageVolType flags.
         /// </summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virStorageVolType type;
+        public StorageVolType type;
         /// <summary>
         /// Logical size bytes.
         /// </summary>
@@ -464,13 +524,13 @@ namespace Libvirt
     /// Structure to handle storage pool informations
     /// </summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virStoragePoolInfo
+    public struct StoragePoolInfo
     {
         /// <summary>
         /// virStoragePoolState flags
         /// </summary>
         [MarshalAs(UnmanagedType.I4)]
-        public virStoragePoolState state;
+        public StoragePoolState state;
         /// <summary>
         /// Logical size bytes
         /// </summary>
@@ -491,7 +551,7 @@ namespace Libvirt
     /// <summary>
     /// Structure to handle node informations
     /// </summary>
-    public struct virNodeInfo
+    public struct NodeInfo
     {
         /// <summary>
         /// String indicating the CPU model.
@@ -531,12 +591,12 @@ namespace Libvirt
     /// Structure tu handle domain informations
     /// </summary>
     [StructLayout(LayoutKind.Sequential)]
-    public struct virDomainInfo
+    public struct DomainInfo
     {
         /// <summary>
         /// The running state, one of virDomainState.
         /// </summary>
-        public virDomainState state;
+        public DomainState state;
         /// <summary>
         /// The maximum memory in KBytes allowed.
         /// </summary>
@@ -560,7 +620,7 @@ namespace Libvirt
     ///<summary>
     /// Enumerate errors
     ///</summary>
-    public enum virErrorNumber
+    public enum ErrorNumber
     {
         /// <summary>
         /// No error
@@ -831,7 +891,7 @@ namespace Libvirt
     /// <summary>
     /// Enumrate types of domain errors
     /// </summary>
-    public enum virErrorDomain
+    public enum ErrorDomain
     {
         /// <summary>
         /// None
@@ -982,7 +1042,7 @@ namespace Libvirt
     /// <summary>
     /// Enumerate the error levels
     /// </summary>
-    public enum virErrorLevel
+    public enum ErrorLevel
     {
         /// <summary>
         /// No error
@@ -1001,7 +1061,7 @@ namespace Libvirt
     /// Type of handles for callback
     ///</summary>
     [Flags]
-    public enum virEventHandleType
+    public enum EventHandleType
     {
         /// <summary>
         /// None
@@ -1029,7 +1089,7 @@ namespace Libvirt
     /// Memory statistics tags
     ///</summary>
     [Flags]
-    public enum virDomainMemoryStatTags
+    public enum DomainMemoryStatTags
     {
         /// <summary>
         ///  The total amount of memory written out to swap space (in kB).
@@ -1062,7 +1122,7 @@ namespace Libvirt
     ///<summary>
     /// Types of storage volume
     ///</summary>
-    public enum virStorageVolType
+    public enum StorageVolType
     {
         /// <summary>
         /// Regular file based volumes.
@@ -1077,7 +1137,7 @@ namespace Libvirt
     /// <summary>
     /// States of storage pool
     /// </summary>
-    public enum virStoragePoolState
+    public enum StoragePoolState
     {
         /// <summary>
         /// Not running.
@@ -1100,7 +1160,7 @@ namespace Libvirt
     /// Flasg for XML domain rendering
     /// </summary>
     [Flags]
-    public enum virDomainXMLFlags
+    public enum DomainXMLFlags
     {
         /// <summary>
         /// Dump security sensitive information too.
@@ -1115,7 +1175,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'defined' lifecycle event
     /// </summary>
-    public enum virDomainEventDefinedDetailType
+    public enum DomainEventDefinedDetailType
     {
         /// <summary>
         /// Newly created config file
@@ -1130,7 +1190,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'undefined' lifecycle event
     /// </summary>
-    public enum virDomainEventUndefinedDetailType
+    public enum DomainEventUndefinedDetailType
     {
         /// <summary>
         /// Deleted the config file
@@ -1140,7 +1200,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'started' lifecycle event
     /// </summary>
-    public enum virDomainEventStartedDetailType
+    public enum DomainEventStartedDetailType
     {
         /// <summary>
         /// Normal startup from boot
@@ -1158,7 +1218,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'suspended' lifecycle event
     /// </summary>
-    public enum virDomainEventSuspendedDetailType
+    public enum DomainEventSuspendedDetailType
     {
         /// <summary>
         /// Normal suspend due to admin pause
@@ -1172,7 +1232,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'resumed' lifecycle event
     /// </summary>
-    public enum virDomainEventResumedDetailType
+    public enum DomainEventResumedDetailType
     {
         /// <summary>
         /// Normal resume due to admin unpause
@@ -1186,7 +1246,7 @@ namespace Libvirt
     /// <summary>
     /// Details on the caused of the 'stopped' lifecycle event
     /// </summary>
-    public enum virDomainEventStoppedDetailType
+    public enum DomainEventStoppedDetailType
     {
         /// <summary>
         /// Normal shutdown
@@ -1217,7 +1277,7 @@ namespace Libvirt
     /// <summary>
     /// Types of domain events
     /// </summary>
-    public enum virDomainEventType
+    public enum DomainEventType
     {
         /// <summary>
         /// Domain defined
@@ -1248,7 +1308,7 @@ namespace Libvirt
     /// <summary>
     /// Flags for storage pool building
     /// </summary>
-    public enum virStoragePoolBuildFlags
+    public enum StoragePoolBuildFlags
     {
         /// <summary>
         /// Regular build from scratch.
@@ -1267,7 +1327,7 @@ namespace Libvirt
     ///<summary>
     /// Flags for storage pool deletion
     ///</summary>
-    public enum virStoragePoolDeleteFlags
+    public enum StoragePoolDeleteFlags
     {
         /// <summary>
         /// Delete metadata only (fast).
@@ -1281,7 +1341,7 @@ namespace Libvirt
     ///<summary>
     /// Types of credentials
     ///</summary>
-    public enum virConnectCredentialType
+    public enum ConnectCredentialType
     {
         ///<summary>
         /// Identity to act as
@@ -1324,7 +1384,7 @@ namespace Libvirt
     /// <summary>
     /// States of a domain
     /// </summary>
-    public enum virDomainState
+    public enum DomainState
     {
         /// <summary>
         /// No state.
diff --git a/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs b/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs
index cd56d30..675fee0 100644
--- a/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs
+++ b/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs
@@ -47,16 +47,18 @@ public partial class MainWindow : Gtk.Window
 	{
 		// Fill a structure to pass username and password to callbacks
         AuthData authData = new AuthData { password = entry3.Text, user_name = entry2.Text };
+		IntPtr authDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(authData));
+		Marshal.StructureToPtr(authData, authDataPtr, false);
 		
 		// Fill a virConnectAuth structure
-        virConnectAuth auth = new virConnectAuth
+        ConnectAuth auth = new ConnectAuth
         {
-            cbdata = authData,                  // The authData structure
+            cbdata = authDataPtr,                  // The authData structure
             cb = AuthCallback,                  // the method called by callbacks
             CredTypes = new[]
                             {
-                                virConnectCredentialType.VIR_CRED_AUTHNAME,
-                                virConnectCredentialType.VIR_CRED_PASSPHRASE
+                                ConnectCredentialType.VIR_CRED_AUTHNAME,
+                                ConnectCredentialType.VIR_CRED_PASSPHRASE
                             }          // The list of credentials types
         };
 		
@@ -132,41 +134,27 @@ public partial class MainWindow : Gtk.Window
 		tvcDomains.AddAttribute(crtDomainCell, "text", 0);
 	}
 	
-	private static int AuthCallback(IntPtr creds, uint ncred, IntPtr cbdata)
+	private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata)
+    {
+        AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData));
+        foreach (ConnectCredential cred in creds)
         {
-            // Get the AuthData structure
-            AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData));
-            int offset = 0;
-            int credIndex = 0;
-
-            while (credIndex < ncred)
+            switch (cred.type)
             {
-                IntPtr currentCred = new IntPtr(creds.ToInt32() + offset);
-
-                virConnectCredential cred = (virConnectCredential) Marshal.PtrToStructure(currentCred, typeof(virConnectCredential));
-                offset += Marshal.SizeOf(cred);
-                switch (cred.type)
-                {
-                    case virConnectCredentialType.VIR_CRED_AUTHNAME:
-                        // Fill the user name
-                        cred.Result = authData.user_name;
-                        cred.resultlen = (uint)authData.user_name.Length;
-                        break;
-                    case virConnectCredentialType.VIR_CRED_PASSPHRASE:
-                        // Fill the password
-                        cred.Result = authData.password;
-                        cred.resultlen = (uint)authData.password.Length;
-                        break;
-                    default:
-                        return -1;
-                }
-                // Write structure to the unmanaged address
-                Marshal.StructureToPtr(cred, currentCred, true);
-
-                credIndex++;
+                case ConnectCredentialType.VIR_CRED_AUTHNAME:
+                    // Fill the user name
+                    cred.Result = authData.user_name;
+                    break;
+                case ConnectCredentialType.VIR_CRED_PASSPHRASE:
+                    // Fill the password
+                    cred.Result = authData.password;
+                    break;
+                default:
+                    return -1;
             }
-            return 0;
         }
+        return 0;
+    }
 	
 	
 }
diff --git a/examples/VisualStudio/virConnectOpenAuth/Form1.cs b/examples/VisualStudio/virConnectOpenAuth/Form1.cs
index 497ed38..0d9de50 100644
--- a/examples/VisualStudio/virConnectOpenAuth/Form1.cs
+++ b/examples/VisualStudio/virConnectOpenAuth/Form1.cs
@@ -7,18 +7,19 @@
  * 
  * Sample code for :
  * Function :
- *      virConnectOpenAuth
- *      virConnectNumOfDefinedDomains
- *      virConnectListDefinedDomains
- *      virConnectNumOfDomains
- *      virDomainLookupByID
- *      virConnectListDomains
- *      virDomainGetName
- *      virConnectClose
+ *      Connect.OpenAuth
+ *      Connect.NumOfDefinedDomains
+ *      Connect.ListDefinedDomains
+ *      Connect.NumOfDomains
+ *      Connect.Close
+ *      Connect.ListDomains
+ *      Domain.LookupByID
+ *      Domain.GetName
+ *
  * Types :
- *      virConnectAuth
- *      virConnectCredential
- *      virConnectCredentialType
+ *      ConnectAuth
+ *      ConnectCredential
+ *      ConnectCredentialType
  */
 
 using System;
@@ -45,16 +46,17 @@ namespace virConnectOpenAuth
         {
             // Fill a structure to pass username and password to callbacks
             AuthData authData = new AuthData { password = tbPassword.Text, user_name = tbUsername.Text };
-
+            IntPtr authDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(authData));
+            Marshal.StructureToPtr(authData, authDataPtr, true);
             // Fill a virConnectAuth structure
-            virConnectAuth auth = new virConnectAuth
+            ConnectAuth auth = new ConnectAuth
             {
-                cbdata = authData,                  // The authData structure
+                cbdata = authDataPtr,               // The authData structure
                 cb = AuthCallback,                  // the method called by callbacks
                 CredTypes = new[]
                                 {
-                                    virConnectCredentialType.VIR_CRED_AUTHNAME,
-                                    virConnectCredentialType.VIR_CRED_PASSPHRASE
+                                    ConnectCredentialType.VIR_CRED_AUTHNAME,
+                                    ConnectCredentialType.VIR_CRED_PASSPHRASE
                                 }          // The list of credentials types
             };
 
@@ -114,38 +116,24 @@ namespace virConnectOpenAuth
             }
         }
 
-        private static int AuthCallback(IntPtr creds, uint ncred, IntPtr cbdata)
+        private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata)
         {
-            // Get the AuthData structure
             AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData));
-            int offset = 0;
-            int credIndex = 0;
-
-            while (credIndex < ncred)
+            foreach (ConnectCredential cred in creds)
             {
-                IntPtr currentCred = new IntPtr(creds.ToInt32() + offset);
-
-                virConnectCredential cred = (virConnectCredential) Marshal.PtrToStructure(currentCred, typeof(virConnectCredential));
-                offset += Marshal.SizeOf(cred);
                 switch (cred.type)
                 {
-                    case virConnectCredentialType.VIR_CRED_AUTHNAME:
+                    case ConnectCredentialType.VIR_CRED_AUTHNAME:
                         // Fill the user name
                         cred.Result = authData.user_name;
-                        cred.resultlen = (uint)authData.user_name.Length;
                         break;
-                    case virConnectCredentialType.VIR_CRED_PASSPHRASE:
+                    case ConnectCredentialType.VIR_CRED_PASSPHRASE:
                         // Fill the password
                         cred.Result = authData.password;
-                        cred.resultlen = (uint)authData.password.Length;
                         break;
                     default:
                         return -1;
                 }
-                // Write structure to the unmanaged address
-                Marshal.StructureToPtr(cred, currentCred, true);
-
-                credIndex++;
             }
             return 0;
         }
diff --git a/projects/MonoDevelop/LibvirtBindings.csproj b/projects/MonoDevelop/LibvirtBindings.csproj
index d66036c..2473625 100644
--- a/projects/MonoDevelop/LibvirtBindings.csproj
+++ b/projects/MonoDevelop/LibvirtBindings.csproj
@@ -49,9 +49,6 @@
     <Compile Include="..\..\Domain.cs">
       <Link>Domain.cs</Link>
     </Compile>
-    <Compile Include="..\..\Error.cs">
-      <Link>Error.cs</Link>
-    </Compile>
     <Compile Include="..\..\Event.cs">
       <Link>Event.cs</Link>
     </Compile>
@@ -82,6 +79,9 @@
     <Compile Include="..\..\Types.cs">
       <Link>Types.cs</Link>
     </Compile>
+    <Compile Include="..\..\Errors.cs">
+      <Link>Errors.cs</Link>
+    </Compile>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
diff --git a/projects/MonoDevelop/LibvirtBindings.sln b/projects/MonoDevelop/LibvirtBindings.sln
index aa07eb0..25753ff 100644
--- a/projects/MonoDevelop/LibvirtBindings.sln
+++ b/projects/MonoDevelop/LibvirtBindings.sln
@@ -33,6 +33,6 @@ Global
 		{FFCD939E-7F9A-44D5-AEBC-84F40942E8B5} = {504BA6A7-9D0E-44BA-827D-D797773347FD}
 	EndGlobalSection
 	GlobalSection(MonoDevelopProperties) = preSolution
-		StartupItem = ..\..\examples\MonoDevelop\virConnectOpen\virConnectOpen.csproj
+		StartupItem = ..\..\examples\MonoDevelop\virConnectOpenAuth\virConnectOpenAuth.csproj
 	EndGlobalSection
 EndGlobal
diff --git a/projects/VisualStudio/LibvirtBindings.csproj b/projects/VisualStudio/LibvirtBindings.csproj
index 86a8914..ca053fb 100644
--- a/projects/VisualStudio/LibvirtBindings.csproj
+++ b/projects/VisualStudio/LibvirtBindings.csproj
@@ -44,11 +44,14 @@
     <Compile Include="..\..\Connect.cs">
       <Link>Connect.cs</Link>
     </Compile>
+    <Compile Include="..\..\ConnectCredentialArrayMarshaler.cs">
+      <Link>ConnectCredentialArrayMarshaler.cs</Link>
+    </Compile>
     <Compile Include="..\..\Domain.cs">
       <Link>Domain.cs</Link>
     </Compile>
-    <Compile Include="..\..\Error.cs">
-      <Link>Error.cs</Link>
+    <Compile Include="..\..\Errors.cs">
+      <Link>Errors.cs</Link>
     </Compile>
     <Compile Include="..\..\Event.cs">
       <Link>Event.cs</Link>
-- 
1.7.2.3.msysgit.0

