On Windows 8 x64 Enterprise I have a test .NET 4.0 C# Console Program targeting 'any cpu' in Visual Studio 2012 to which I added the GPMC Assembly via the instructions here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff519502(v=vs.85).aspx
The exact path to the GPMC Assembly is C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.GroupPolicy.Management\v4.0_2.0.0.0__31bf3856ad364e35\Microsoft.GroupPolicy.Management.dll
When I run the following code :
GPDomain domain = new GPDomain();
GPSearchCriteria searchCriteria = new GPSearchCriteria();
GpoCollection gpos = domain.SearchGpos(searchCriteria);
On the searchGpos I get the following exception:
System.InvalidCastException was unhandled
HResult=-2147467262
Message=Unable to cast COM object of type 'Microsoft.GroupPolicy.GPMGPOCollectionClass' to interface type 'System.Collections.IEnumerable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{496B0ABE-CDEE-11D3-88E8-00902754C43A}'
failed due to the following error: 'No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))' and the COM component does not support IDispatch::Invoke calls for DISPID_NEWENUM.
Source=mscorlib
StackTrace:
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
at Microsoft.GroupPolicy.GPMGPOCollectionClass.GetEnumerator()
at Microsoft.GroupPolicy.Common.CreateCollectionWrapper[T](IEnumerable gpmCollection, Int32 capacity, CreateComWrapper`1 createComWrapperDelegate, Object data)
at Microsoft.GroupPolicy.GPDomain.SearchGpos(GPSearchCriteria searchCriteria)
at GpoTest.Program.GetGPOs(String domainname) in c:\Users\mccafferym\Documents\Visual Studio 2012\Projects\GpoTest\GpoTest\Program.cs:line 18
at GpoTest.Program.Main(String[] args) in c:\Users\mccafferym\Documents\Visual Studio 2012\Projects\GpoTest\GpoTest\Program.cs:line 53
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I if enable debugging with .NET reflector on the Microsoft.GroupPolicy.Management.dll the exception occurs here on List<T> list = new List<T>(capacity);
// Generated by .NET Reflector from C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.GroupPolicy.Management\v4.0_2.0.0.0__31bf3856ad364e35\Microsoft.GroupPolicy.Management.dll namespace Microsoft.GroupPolicy { using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Runtime.CompilerServices; internal static class Common { internal static IList<T> CreateCollectionWrapper<T>(IEnumerable gpmCollection, int capacity, CreateComWrapper<T> createComWrapperDelegate, object data) { List<T> list = new List<T>(capacity); foreach (object obj2 in gpmCollection) { list.Add(createComWrapperDelegate(obj2, data)); } return list; }
The specified GUID & related CLSID when looked up in registry:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Interface\{496B0ABE-CDEE-11D3-88E8-00902754C43A}]
@="IEnumerable"
[HKEY_CLASSES_ROOT\Interface\{496B0ABE-CDEE-11D3-88E8-00902754C43A}\ProxyStubClsid32]
@="{00020424-0000-0000-C000-000000000046}"
[HKEY_CLASSES_ROOT\Interface\{496B0ABE-CDEE-11D3-88E8-00902754C43A}\TypeLib]
@="{BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}"
"Version"="2.4"
[HKEY_CLASSES_ROOT\CLSID\{00020424-0000-0000-C000-000000000046}]
@="PSOAInterface"
[HKEY_CLASSES_ROOT\CLSID\{00020424-0000-0000-C000-000000000046}\InprocServer32]
@="C:\\Windows\\System32\\oleaut32.dll"
"ThreadingModel"="Both"
I also tried targeting x86 & x64 to see if it made any difference (it didn't).