internal static Exception GetExceptionFromErrorCode(int errorCode, string targetName) { string errorMessage = ExceptionHelper.GetErrorMessage(errorCode, false); if (errorCode == ExceptionHelper.ERROR_ACCESS_DENIED || errorCode == ExceptionHelper.ERROR_DS_DRA_ACCESS_DENIED) { return(new UnauthorizedAccessException(errorMessage)); } else { if (errorCode == ExceptionHelper.ERROR_NOT_ENOUGH_MEMORY || errorCode == ExceptionHelper.ERROR_OUTOFMEMORY || errorCode == ExceptionHelper.ERROR_DS_DRA_OUT_OF_MEM || errorCode == ExceptionHelper.RPC_S_OUT_OF_RESOURCES) { return(new OutOfMemoryException()); } else { if (errorCode == ExceptionHelper.ERROR_NO_LOGON_SERVERS || errorCode == ExceptionHelper.ERROR_NO_SUCH_DOMAIN || errorCode == ExceptionHelper.RPC_S_SERVER_UNAVAILABLE || errorCode == ExceptionHelper.RPC_S_CALL_FAILED) { return(new ActiveDirectoryServerDownException(errorMessage, errorCode, targetName)); } else { return(new ActiveDirectoryOperationException(errorMessage, errorCode)); } } } }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo); try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) { return; } else { throw e; } } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } } finally { // release the memory if (errorInfo != (IntPtr)0) { UnsafeNativeMethods.LocalFree(errorInfo); } } }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; if (this.Partitions.Contains(partition)) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int num = delegateForFunctionPointer(handle, partition, (int)option | 4, syncAllFunctionPointer, (IntPtr)0, ref intPtr); try { if (intPtr == (IntPtr)0) { if (num != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(num, false)); } } else { SyncFromAllServersOperationException syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, false); if (syncFromAllServersOperationException != null) { throw syncFromAllServersOperationException; } } } finally { if (intPtr != (IntPtr)0) { UnsafeNativeMethods.LocalFree(intPtr); } } return; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } else { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)); int errorCode = delegateForFunctionPointer(handle, partition, ((int)option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero); try { if (zero != IntPtr.Zero) { SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false); if (exception != null) { throw exception; } } else if (errorCode != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false)); } } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero); } } }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr info = (IntPtr)0; int result = 0; bool needToTryAgain = true; IntPtr functionPtr; // first try to use the DsReplicaGetInfo2W API which does not exist on win2k machine // call DsReplicaGetInfo2W functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (functionPtr == (IntPtr)0) { // a win2k machine which does not have it. functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; needToTryAgain = false; } else { UnsafeNativeMethods.DsReplicaGetInfo2W dsReplicaGetInfo2W = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); result = dsReplicaGetInfo2W(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref info); } // check the result if (needToTryAgain && result == DS_REPL_NOTSUPPORTED) { // this is the case that client is xp/win2k3, dc is win2k functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; } if (result != 0) { if (partition != null) { // this is the case of meta data if (type == (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ) { if (result == ExceptionHelper.ERROR_DS_DRA_BAD_DN || result == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(result, false), "objectPath"); } DirectoryEntry verifyEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { verifyEntry.RefreshCache(new string[] { "name" }); } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072020) | // dir_error on server side e.ErrorCode == unchecked ((int)0x80072030)) // object not exists { throw new ArgumentException(SR.DSNoObject, "objectPath"); } else if (e.ErrorCode == unchecked ((int)0x80005000) | // bad path name e.ErrorCode == unchecked ((int)0x80072032)) // ERROR_DS_INVALID_DN_SYNTAX { throw new ArgumentException(SR.DSInvalidPath, "objectPath"); } } } else { if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } } } throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } return(info); }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; int errorCode = 0; bool flag = true; IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (procAddress == IntPtr.Zero) { procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)); errorCode = delegateForFunctionPointer(dsHandle, secondaryType, partition, IntPtr.Zero, ref zero); advanced = false; flag = false; } else { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W infow = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W)); errorCode = infow(dsHandle, type, partition, IntPtr.Zero, null, null, 0, context, ref zero); } if (flag && (errorCode == 50)) { procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW ow2 = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)); errorCode = ow2(dsHandle, secondaryType, partition, IntPtr.Zero, ref zero); advanced = false; } if (errorCode == 0) { return(zero); } if (partition != null) { if (type == 9) { if ((errorCode == ExceptionHelper.ERROR_DS_DRA_BAD_DN) || (errorCode == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE)) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(errorCode, false), "objectPath"); } DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { directoryEntry.RefreshCache(new string[] { "name" }); } catch (COMException exception) { if ((exception.ErrorCode == -2147016672) | (exception.ErrorCode == -2147016656)) { throw new ArgumentException(Res.GetString("DSNoObject"), "objectPath"); } if ((exception.ErrorCode == -2147463168) | (exception.ErrorCode == -2147016654)) { throw new ArgumentException(Res.GetString("DSInvalidPath"), "objectPath"); } } } else if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, this.Name); }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; int num = 0; bool flag = true; IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfo2W delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); num = delegateForFunctionPointer(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref intPtr); } else { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; flag = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (flag && num == 50) { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW delegateForFunctionPointer1 = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = delegateForFunctionPointer1(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (num == 0) { return(intPtr); } else { if (partition != null) { if (type != 9) { if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } else { if (num == ExceptionHelper.ERROR_DS_DRA_BAD_DN || num == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(num, false), "objectPath"); } else { DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { string[] strArrays = new string[1]; strArrays[0] = "name"; directoryEntry.RefreshCache(strArrays); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (!(cOMException.ErrorCode == -2147016672 | cOMException.ErrorCode == -2147016656)) { if (cOMException.ErrorCode == -2147463168 | cOMException.ErrorCode == -2147016654) { throw new ArgumentException(Res.GetString("DSInvalidPath"), "objectPath"); } } else { throw new ArgumentException(Res.GetString("DSNoObject"), "objectPath"); } } } } } throw ExceptionHelper.GetExceptionFromErrorCode(num, this.Name); } }
internal unsafe void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllCallback, string partition, SyncFromAllServersOptions option, SyncUpdateCallback?callback, SafeLibraryHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, nameof(partition)); } // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW var dsReplicaSyncAllW = (delegate * unmanaged <IntPtr, char *, int, IntPtr, IntPtr, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (dsReplicaSyncAllW == null) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } int result; fixed(char *partitionPtr = partition) { IntPtr syncAllFunctionPointer = Marshal.GetFunctionPointerForDelegate(syncAllCallback); result = dsReplicaSyncAllW(handle, partitionPtr, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, &errorInfo); GC.KeepAlive(syncAllCallback); } try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException?e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) { return; } else { throw e; } } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } } finally { // release the memory if (errorInfo != (IntPtr)0) { global::Interop.Kernel32.LocalFree(errorInfo); } } }
internal static SyncFromAllServersOperationException CreateSyncAllException(IntPtr errorInfo, bool singleError) { if (errorInfo != (IntPtr)0) { if (!singleError) { IntPtr intPtr = Marshal.ReadIntPtr(errorInfo); ArrayList arrayLists = new ArrayList(); int num = 0; while (intPtr != (IntPtr)0) { DS_REPSYNCALL_ERRINFO dSREPSYNCALLERRINFO = new DS_REPSYNCALL_ERRINFO(); Marshal.PtrToStructure(intPtr, dSREPSYNCALLERRINFO); if (dSREPSYNCALLERRINFO.dwWin32Err != ExceptionHelper.ERROR_CANCELLED) { string errorMessage = ExceptionHelper.GetErrorMessage(dSREPSYNCALLERRINFO.dwWin32Err, false); string stringUni = Marshal.PtrToStringUni(dSREPSYNCALLERRINFO.pszSrcId); string str = Marshal.PtrToStringUni(dSREPSYNCALLERRINFO.pszSvrId); SyncFromAllServersErrorInformation syncFromAllServersErrorInformation = new SyncFromAllServersErrorInformation(dSREPSYNCALLERRINFO.error, dSREPSYNCALLERRINFO.dwWin32Err, errorMessage, stringUni, str); arrayLists.Add(syncFromAllServersErrorInformation); } num++; intPtr = Marshal.ReadIntPtr(errorInfo, num * Marshal.SizeOf(typeof(IntPtr))); } if (arrayLists.Count != 0) { SyncFromAllServersErrorInformation[] syncFromAllServersErrorInformationArray = new SyncFromAllServersErrorInformation[arrayLists.Count]; for (int i = 0; i < arrayLists.Count; i++) { SyncFromAllServersErrorInformation item = (SyncFromAllServersErrorInformation)arrayLists[i]; syncFromAllServersErrorInformationArray[i] = new SyncFromAllServersErrorInformation(item.ErrorCategory, item.ErrorCode, item.ErrorMessage, item.SourceServer, item.TargetServer); } return(new SyncFromAllServersOperationException(Res.GetString("DSSyncAllFailure"), null, syncFromAllServersErrorInformationArray)); } else { return(null); } } else { DS_REPSYNCALL_ERRINFO dSREPSYNCALLERRINFO1 = new DS_REPSYNCALL_ERRINFO(); Marshal.PtrToStructure(errorInfo, dSREPSYNCALLERRINFO1); string errorMessage1 = ExceptionHelper.GetErrorMessage(dSREPSYNCALLERRINFO1.dwWin32Err, false); string stringUni1 = Marshal.PtrToStringUni(dSREPSYNCALLERRINFO1.pszSrcId); string str1 = Marshal.PtrToStringUni(dSREPSYNCALLERRINFO1.pszSvrId); if (dSREPSYNCALLERRINFO1.dwWin32Err != ExceptionHelper.ERROR_CANCELLED) { SyncFromAllServersErrorInformation syncFromAllServersErrorInformation1 = new SyncFromAllServersErrorInformation(dSREPSYNCALLERRINFO1.error, dSREPSYNCALLERRINFO1.dwWin32Err, errorMessage1, stringUni1, str1); SyncFromAllServersErrorInformation[] syncFromAllServersErrorInformationArray1 = new SyncFromAllServersErrorInformation[1]; syncFromAllServersErrorInformationArray1[0] = syncFromAllServersErrorInformation1; return(new SyncFromAllServersOperationException(Res.GetString("DSSyncAllFailure"), null, syncFromAllServersErrorInformationArray1)); } else { return(null); } } } else { return(new SyncFromAllServersOperationException()); } }
internal unsafe IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string?partition, ref bool advanced, int context, SafeLibraryHandle libHandle) { IntPtr info = (IntPtr)0; int result = 0; bool needToTryAgain = true; // first try to use the DsReplicaGetInfo2W API which does not exist on win2k machine // call DsReplicaGetInfo2W var dsReplicaGetInfo2W = (delegate * unmanaged <IntPtr, int, char *, IntPtr, char *, char *, int, int, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (dsReplicaGetInfo2W == null) { // a win2k machine which does not have it. var dsReplicaGetInfoW = (delegate * unmanaged <IntPtr, int, char *, IntPtr, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (dsReplicaGetInfoW == null) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastPInvokeError()); } fixed(char *partitionPtr = partition) { result = dsReplicaGetInfoW(dsHandle, secondaryType, partitionPtr, (IntPtr)0, &info); } advanced = false; needToTryAgain = false; } else { fixed(char *partitionPtr = partition) { result = dsReplicaGetInfo2W(dsHandle, type, partitionPtr, (IntPtr)0, null, null, 0, context, &info); } } // check the result if (needToTryAgain && result == DS_REPL_NOTSUPPORTED) { // this is the case that client is xp/win2k3, dc is win2k var dsReplicaGetInfoW = (delegate * unmanaged <IntPtr, int, char *, IntPtr, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (dsReplicaGetInfoW == null) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastPInvokeError()); } fixed(char *partitionPtr = partition) { result = dsReplicaGetInfoW(dsHandle, secondaryType, partitionPtr, (IntPtr)0, &info); } advanced = false; } if (result != 0) { if (partition != null) { // this is the case of meta data if (type == (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ) { if (result == ExceptionHelper.ERROR_DS_DRA_BAD_DN || result == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(result, false), "objectPath"); } DirectoryEntry verifyEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { verifyEntry.RefreshCache(new string[] { "name" }); } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072020) | // dir_error on server side e.ErrorCode == unchecked ((int)0x80072030)) // object not exists { throw new ArgumentException(SR.DSNoObject, "objectPath"); } else if (e.ErrorCode == unchecked ((int)0x80005000) | // bad path name e.ErrorCode == unchecked ((int)0x80072032)) // ERROR_DS_INVALID_DN_SYNTAX { throw new ArgumentException(SR.DSInvalidPath, "objectPath"); } } } else { if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, nameof(partition)); } } } throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } return(info); }