// Map an interface catalog object (key) to a runtime type (ifc) public Object FindObject(ICatalogCollection coll, Object key) { ICatalogObject ifcObj = (ICatalogObject)key; Type ifc = null; ifc = FindInterfaceByID(ifcObj, _type, _ifcs); if (ifc == null) { ifc = FindInterfaceByName(ifcObj, _type, _ifcs); } DBG.Assert(ifc != null, "Unable to find requested interface: \n" + "\t" + (String)(ifcObj.Name()) + "\n" + "\t" + (String)(ifcObj.Key())); return(ifc); }
/// <include file='doc\ResourcePool.uex' path='docs/doc[@for="ResourcePool.PutResource"]/*' /> public bool PutResource(Object resource) { ITransactionResourcePool p = null; IntPtr token = (IntPtr)0; bool result = false; try { // 1. Get the tx pool. p = GetResourcePool(); if (p != null) { // 2. Reference our pool token. token = GetToken(); // 3. Stuff object into pool. DBG.Info(DBG.Pool, "Placing resource in context"); int hr = p.PutResource(token, resource); if (hr < 0) { result = false; } else { result = true; } } } finally { // If we failed to stick it in, unref it: if (!result && token != (IntPtr)0) { Marshal.Release(token); } if (p != null) { Marshal.ReleaseComObject(p); } } return(result); }
public Object FindObject(ICatalogCollection coll, Object key) { ICatalogObject methObj = (ICatalogObject)key; int slot = (int)(methObj.GetValue("Index")); ComMemberType mtype = ComMemberType.Method; MemberInfo info = Marshal.GetMethodInfoForComSlot(_type, slot, ref mtype); DBG.Assert(info != null, "Failed to find method info for COM slot!"); // Now we have the member info, look through the interface // mapping for this guy: if (info is PropertyInfo) { if (mtype == ComMemberType.PropSet) { info = ((PropertyInfo)info).GetSetMethod(); } else if (mtype == ComMemberType.PropGet) { info = ((PropertyInfo)info).GetGetMethod(); } else { DBG.Assert(false, "Illegal ComMemberType returned"); } } if (_map.InterfaceMethods != null) { for (int i = 0; i < _map.InterfaceMethods.Length; i++) { if (_map.InterfaceMethods[i] == info) { return(_map.TargetMethods[i]); } } DBG.Assert(false, "Had interface mapping, but found no method."); } return(info); }
// We assume that Set() is called inside the transaction, as soon // as any write work has been done on the catalog. internal void Set() { try { if (!_set && ContextUtil.IsInTransaction) { _set = true; RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\CLSID"); _version = (int)(key.GetValue("CLBVersion", 0)); DBG.Info(DBG.Registration, "Old version: " + _version); } } catch (Exception) { // We don't need to watch if the key isn't there, or if // other things failed. _set = false; _version = 0; DBG.Warning(DBG.Registration, "Failed to retreive original catalog version."); } }
/// <include file='doc\RegistrationWrappers.uex' path='docs/doc[@for="RegistrationHelper.InstallAssemblyFromConfig"]/*' /> public void InstallAssemblyFromConfig([MarshalAs(UnmanagedType.IUnknown)] ref RegistrationConfig regConfig) { // Create a permission object for unmanaged code SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); // demand that the caller have this permission sp.Demand(); // now that the caller is clean, assert it from now on. sp.Assert(); Platform.Assert(Platform.W2K, "RegistrationHelper.InstallAssemblyFromConfig"); if (Thread.CurrentThread.ApartmentState == ApartmentState.STA) { // HACK: In order to reduce deadlock likelihood, we need to get off // the current STA (into an MTA) in order to do this work. // Whip off a new thread... RegistrationThreadWrapper wrap = new RegistrationThreadWrapper(this, regConfig); Thread t = new Thread(new ThreadStart(wrap.InstallThread)); t.Start(); t.Join(); wrap.PropInstallResult(); } else { // First, try to do this in a "transacted" manner. This will // return false if we couldn't start up the transaction, // true if it succeeded. // We only do the transacted install if we're on win2k or higher, // cause MTS is all in the registry. if (Platform.IsLessThan(Platform.W2K) || !TryTransactedInstall(regConfig)) { // We need to try a non-transacted install: DBG.Info(DBG.Registration, "Failed to do a transacted install. Using non-tx install."); RegistrationDriver helper = new RegistrationDriver(); helper.InstallAssembly(regConfig, null); } } }
/// <include file='doc\RegistrationWrappers.uex' path='docs/doc[@for="RegistrationHelperTx.UninstallAssemblyFromConfig"]/*' /> public void UninstallAssemblyFromConfig([MarshalAs(UnmanagedType.IUnknown)] ref RegistrationConfig regConfig, Object sync) { bool succeed = false; try { DBG.Assert(ContextUtil.IsInTransaction, "Running in transactional helper w/o transaction will deadlock!"); RegistrationDriver helper = new RegistrationDriver(); helper.UninstallAssembly(regConfig, sync); ContextUtil.SetComplete(); succeed = true; } finally { if (!succeed) { DBG.Info(DBG.Registration, "Uninstall failed."); ContextUtil.SetAbort(); } } }
bool IConfigurationAttribute.AfterSaveChanges(Hashtable cache) { String target = (String)(cache["CurrentTarget"]); // Now that the component itself is configured, we go and add // roles to the sub-collection. (This ensures that all the // component logic that hits sub-collections gets run first. if (target == "Component") { Platform.Assert(Platform.MTS, "SecurityRoleAttribute"); // Pull out the RolesForComponent collection, add the name of // the desired role to that collection. AddRoleFor("Component", cache); } else if (target == "Method") { Platform.Assert(Platform.W2K, "SecurityRoleAttribute"); // Pull out the RolesForMethod collection, add the name of // the desired role to that collection. AddRoleFor("Method", cache); } else if (target == "Interface") { AddRoleFor("Interface", cache); } else if (target == "Application") { // We don't actually need to do anything for application, // as we have already verified that the role exists. } else { // We got called on a target we don't know about, which // shouldn't ever happen. DBG.Assert(false, "Invalid target for RoleAttribute"); } return(true); }
// helper to implement RemoteDispatch methods private String RemoteDispatchHelper(String s, out bool failed) { if (_denyRemoteDispatch) { throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } IMessage reqMsg = ComponentServices.ConvertToMessage(s, this); // Check to see if the method is marked as secure on the // server side: If so, we need to kick it back to the caller, // cause they called us incorrectly. Also verify the method // is not private, internal, or static. CheckMethodAccess(reqMsg); RealProxy rp = RemotingServices.GetRealProxy(this); DBG.Assert(rp != null, "Null RP in Invoke helper"); IMessage retMsg = rp.Invoke(reqMsg); // Check for failures: IMethodReturnMessage mrm = retMsg as IMethodReturnMessage; if (mrm != null && mrm.Exception != null) { failed = true; } else { failed = false; } String sret = ComponentServices.ConvertToString(retMsg); return(sret); }
/// <include file='doc\ResourcePool.uex' path='docs/doc[@for="ResourcePool.GetResource"]/*' /> public Object GetResource() { Object resource = null; ITransactionResourcePool p = null; IntPtr token = (IntPtr)0; try { // 0. Get our token: token = GetToken(); // 1. Get the tx pool. p = GetResourcePool(); if (p != null) { // 2. Try to get object out of pool. DBG.Info(DBG.Pool, "Retrieving resource in context"); int hr = p.GetResource(token, out resource); // 3. If succeeded, unreference the token. if (hr >= 0) { Marshal.Release(token); } } } finally { if (token != ((IntPtr)0)) { Marshal.Release(token); } if (p != null) { Marshal.ReleaseComObject(p); } } return(resource); }
internal static Object GetFeatureData(PlatformFeature feature) { Object value = FindFeatureData(feature); if (value != null) { return(value); } switch (feature) { case PlatformFeature.SWC: value = Thunk.SWCThunk.IsSWCSupported(); break; default: DBG.Assert(false, "Unknown feature"); return(null); } SetFeatureData(feature, value); return(value); }
/// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.IManagedObject.GetObjectIdentity"]/*' /> /// <internalonly/> void IManagedObject.GetObjectIdentity(ref String s, ref int AppDomainID, ref int ccw) { DBG.Assert(false, "IManagedObject.GetObjectIdentity should never be called."); throw new NotSupportedException("IManagedObject.GetObjectIdentity"); }
// Some dummy empty methods for IManagedObject. // These should never be called, this is just here to ensure that // IManagedObject gets stuck in the type library. /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.IManagedObject.GetSerializedBuffer"]/*' /> /// <internalonly/> void IManagedObject.GetSerializedBuffer(ref String s) { DBG.Assert(false, "IManagedObject.GetSerializedBuffer should never be called."); throw new NotSupportedException("IManagedObject.GetSerializedBuffer"); }
/// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.Dispose1"]/*' /> protected virtual void Dispose(bool disposing) { DBG.Info(DBG.SC, "ServicedComponent.Dispose(" + disposing + ")"); }
// implementation of IDisposable /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.Dispose"]/*' /> public void Dispose() { DBG.Info(DBG.SC, "Dispose(): calling DisposeObject."); DisposeObject(this); }
public static MemberInfo ConvertToClassMI(Type t, MemberInfo mi) { // get reflected type Type reflectType = mi.ReflectedType; if (!reflectType.IsInterface) { return(mi); } // First, try to hit the cache. We look for the cache entry // for this type, and it should be a little cache-table // of it's own. In that cache-table, we Cachetable subcache = (Cachetable)Cache.Get(t); if (subcache != null) { MemberInfo cmi = (MemberInfo)subcache.Get(mi); if (cmi != null) { return(cmi); } } DBG.Assert(t != null, "class type is null"); DBG.Assert(!t.IsInterface, " class type is actually an interface"); MethodInfo minfo = (MethodInfo)mi; MethodInfo clsMethodInfo = null; // minfo is an interface member info, map it to class memeber info // get the interface map DBG.Info(DBG.SC, "ReflectionCache: Looking up " + reflectType + " on " + t); InterfaceMapping imap = t.GetInterfaceMap(reflectType); if (imap.TargetMethods == null) { throw new InvalidCastException(); } for (int i = 0; i < imap.TargetMethods.Length; i++) { if (imap.InterfaceMethods[i] == minfo) { clsMethodInfo = imap.TargetMethods[i]; break; } } DBG.Assert(clsMethodInfo != null, "Failed to map interface method to class method"); DBG.Assert(!clsMethodInfo.ReflectedType.IsInterface, "Failed to map interface method to class method"); // Store the result in the cache: if (subcache == null) { subcache = (Cachetable)Cache.Set(t, new Cachetable()); } subcache.Reset(mi, clsMethodInfo); return((MemberInfo)clsMethodInfo); }
static Perf() { bool r = Util.QueryPerformanceFrequency(out _freq); DBG.Assert(r, "Hardware does not support perf counter!"); }
void IObjPool.PutDeactivated(Object p) { DBG.Assert(false, "ComExposedPool: This shouldn't be called"); throw new NotSupportedException(); }
internal static void UninstallUtilityApplication(Type t) { DBG.Info(DBG.Registration, "Starting utility uninstallation:"); try { if (Platform.IsLessThan(Platform.W2K)) { return; } ICatalog cat = null; ICatalogCollection apps = null; ICatalogObject app = null; int appidx = 0; cat = (ICatalog)(new xCatalog()); if (!Platform.IsLessThan(Platform.Whistler)) { // AS/URT 97116: Keep this from failing the install if // we're on a Beta2 Whistler machine, which has a different // GUID for ICatalog2. ICatalog2 cat2 = cat as ICatalog2; if (cat2 != null) { cat2.CurrentPartition(cat2.GlobalPartitionID()); } } apps = (ICatalogCollection)(cat.GetCollection("Applications")); RegistrationDriver.Populate(apps); app = FindApplication(apps, _appid, ref appidx); if (app != null) { // Make sure that we can change this puppy: app.SetValue("Changeable", true); app.SetValue("Deleteable", true); apps.SaveChanges(); DBG.Info(DBG.Registration, "Found application!"); int idx = 0, compcount = 0; Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx)); ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key())); ICatalogObject comp = FindComponent(comps, clsid, ref idx); // Store count here, if it is 1, we can delete the app later. compcount = comps.Count(); if (comp != null) { DBG.Info(DBG.Registration, "Found component at " + idx); comps.Remove(idx); comps.SaveChanges(); } if (comp != null && compcount == 1) { DBG.Info(DBG.Registration, "Removing .NET Utilities application."); // we removed the last component, kill the app apps.Remove(appidx); apps.SaveChanges(); } else { // Make sure that we can't change the app: app.SetValue("Changeable", false); app.SetValue("Deleteable", false); apps.SaveChanges(); } } } catch (Exception e) { // Log a failure in some acceptable manner. try { EventLog appLog = new EventLog(); appLog.Source = "System.EnterpriseServices"; String errMsg = String.Format(Resource.FormatString("Reg_ErrUninstSysEnt"), e); appLog.WriteEntry(errMsg, EventLogEntryType.Error); } catch {} // We threw an exception? What do we do here? //DBG.Assert(false, // "Installation of System.EnterpriseServices threw an exception!", // "Exception: " + e); DBG.Info(DBG.Registration, "Caught exception: " + e); } }
/// <include file='doc\RegistrationWrappers.uex' path='docs/doc[@for="RegistrationHelperTx.Deactivate"]/*' /> protected internal override void Deactivate() { DBG.Info(DBG.Registration, "TxHelper: Deactivate()"); }
public override MarshalByRefObject CreateInstance(Type serverType) { // Platform.Assert(Platform.W2K, "ServicedComponent"); RealProxy rp = null; MarshalByRefObject mo = null; DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for managed request"); ServicedComponentProxy.CleanupQueues(true); // First check if the type is configured to be activated remotely or is a well // known remote type. if ((null != RemotingConfiguration.IsWellKnownClientType(serverType)) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType))) { // It is configured for remote activation. Ask remoting services to do the // job of creating a remoting proxy and returning it. mo = base.CreateInstance(serverType); rp = RemotingServices.GetRealProxy(mo); } else { bool bIsAnotherProcess = false; string uri = ""; bool bEventClass = ServicedComponentInfo.IsTypeEventSource(serverType); IntPtr pUnk = Thunk.Proxy.CoCreateObject(serverType, !bEventClass, ref bIsAnotherProcess, ref uri); if (pUnk != IntPtr.Zero) { try { // TODO: Get rid of this useless foreknowledge requirement // Is there a way we can tell by QI'ing this guy if he's // an event class (or something else we need to artificially // wrap? if (bEventClass) { // events and queued components use RemoteServicedComponentProxy // set up a TP & Remote ServicedComponentProxy pair rp = new RemoteServicedComponentProxy(serverType, pUnk, true); mo = (MarshalByRefObject)rp.GetTransparentProxy(); } else { if (bIsAnotherProcess) // a-ha, we know it should be a RSCP now !!!! { FastRSCPObjRef oref = new FastRSCPObjRef(pUnk, serverType, uri); mo = (MarshalByRefObject)RemotingServices.Unmarshal(oref); DBG.Assert(mo != null, "RemotingServices.Unmarshal returned null!"); DBG.Assert(RemotingServices.GetRealProxy(mo) is RemoteServicedComponentProxy, "RemotingServices.Unmarshal did not return an RSCP!"); } else // bummer, this will give us back a SCP { mo = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk); DBG.Info(DBG.SC, "ret = " + mo.GetType()); DBG.Info(DBG.SC, "st = " + serverType); DBG.Info(DBG.SC, "rt == sc = " + (mo.GetType() == serverType)); DBG.Info(DBG.SC, "instanceof = " + serverType.IsInstanceOfType(mo)); if (!(serverType.IsInstanceOfType(mo))) { throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, mo.GetType())); } rp = RemotingServices.GetRealProxy(mo); if (!(rp is ServicedComponentProxy) && !(rp is RemoteServicedComponentProxy)) { // in cross-appdomain scenario, we get back a RemotingProxy, SetCOMIUnknown has not been made on our server! ServicedComponent sc = (ServicedComponent)mo; sc.DoSetCOMIUnknown(pUnk); } } } } finally { Marshal.Release(pUnk); } } } if (rp is ServicedComponentProxy) { // Here, we tell the server proxy that it needs to filter out // constructor calls: We only need to do this if // the proxy lives in the same context as the caller, // otherwise we'll get an Invoke call and can do the // filtering automagically: ServicedComponentProxy scp = (ServicedComponentProxy)rp; if (scp.HomeToken == Thunk.Proxy.GetCurrentContextToken()) { scp.FilterConstructors(); } } DBG.Assert(mo is ServicedComponent, " CoCI returned an invalid object type"); DBG.Info(DBG.SC, "SCPA.CreateInstance done."); return(mo); }
MarshalByRefObject ICustomFactory.CreateInstance(Type serverType) { // Platform.Assert(Platform.W2K, "ServicedComponent"); DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for unmanaged request"); DBG.Assert(ServicedComponentInfo.IsTypeServicedComponent(serverType), "unconfigured type passed to ICustomFactory.CreateInstance"); RealProxy rp = null; // The reason we don't want to cleanup GIT cookies from inside here (passing false) is // because we will already be in a new context, and RevokeInterfaceFromGlobal will be very expensive // (like 5x), as it needs to switch context. A more appropriate place to do this is in the managed CreateInstance // before we even call CoCreateInstance ServicedComponentProxy.CleanupQueues(false); int iSCInfo = ServicedComponentInfo.SCICachedLookup(serverType); bool fIsTypeJITActivated = (iSCInfo & ServicedComponentInfo.SCI_JIT) != 0; bool fIsTypePooled = (iSCInfo & ServicedComponentInfo.SCI_OBJECTPOOLED) != 0; bool fAreMethodsSecure = (iSCInfo & ServicedComponentInfo.SCI_METHODSSECURE) != 0; if (fIsTypeJITActivated) { // NOTE: If the component is JIT activated, we may be trying // to connect a new backing object to an existing TP held // by a managed client. So we look in our handy table // to see if there is a component registered for this context. // Because it is JIT activated, COM+ ensures that it will // have been the distinguished object in this context. IntPtr token = Thunk.Proxy.GetCurrentContextToken(); DBG.Info(DBG.SC, "SCPA.CreateInstance looking for JIT object in IdentityTable. token=" + token); Object otp = IdentityTable.FindObject(token); if (otp != null) { DBG.Info(DBG.SC, "SCPA.CreateInstance found JIT object in IdentityTable."); rp = RemotingServices.GetRealProxy(otp); DBG.Assert(rp is ServicedComponentProxy, "Cached something that wasn't a serviced component proxy in the ID table!"); DBG.Assert(rp != null, " GetTransparentProxy.. real proxy is null"); DBG.Assert(serverType == rp.GetProxiedType(), "Invalid type found in Deactivated list"); } } if (rp == null) { DBG.Info(DBG.SC, "SCPA.CreateInstance creating new SCP fJIT=" + fIsTypeJITActivated + " fPooled=" + fIsTypePooled + " fMethodsSecure=" + fAreMethodsSecure); rp = new ServicedComponentProxy(serverType, fIsTypeJITActivated, fIsTypePooled, fAreMethodsSecure, true); } else if (rp is ServicedComponentProxy) { ServicedComponentProxy scp = (ServicedComponentProxy)rp; scp.ConstructServer(); } MarshalByRefObject mo = (MarshalByRefObject)rp.GetTransparentProxy(); DBG.Assert(mo != null, " GetTransparentProxy returned NULL"); DBG.Info(DBG.SC, "SCPA.ICustomFactory.CreateInstance done."); return(mo); }
protected ServicedComponentMarshaler(SerializationInfo info, StreamingContext context) : base(info, context) { byte[] buffer = null; Type servertype = null; bool bFoundFIsMarshalled = false; DBG.Info(DBG.SC, "SCM: construct"); ComponentServices.InitializeRemotingChannels(); SerializationInfoEnumerator e = info.GetEnumerator(); while (e.MoveNext()) { DBG.Info(DBG.SC, "SCM: ctor: name = " + e.Name + " value = " + e.Value); if (e.Name.Equals("servertype")) { servertype = (Type)e.Value; } else if (e.Name.Equals("dcomInfo")) { buffer = (byte[])e.Value; } else if (e.Name.Equals("fIsMarshalled")) { int value = 0; Object o = e.Value; if (o.GetType() == typeof(String)) { value = ((IConvertible)o).ToInt32(null); } else { value = (int)o; } if (value == 0) { bFoundFIsMarshalled = true; } } } if (!bFoundFIsMarshalled) { DBG.Info(DBG.SC, "SCM: ctor: didn't find fIsMarshalled."); _marshalled = true; } _um = new SCUnMarshaler(servertype, buffer); _rt = servertype; if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(servertype)) { _rp = RemotingServices.GetRealProxy(base.GetRealObject(context)); } else { DBG.Assert(servertype != null, "SCM: server type is null during marshal."); if (ServicedComponentInfo.IsTypeEventSource(servertype)) { TypeInfo = (IRemotingTypeInfo) new SCMTypeName(servertype); } Object otp = base.GetRealObject(context); _rp = RemotingServices.GetRealProxy(otp); } // cleanup the buffer, in case we found an existing rp _um.Dispose(); }
public override ObjRef CreateObjRef(Type requestedType) { DBG.Info(DBG.SC, "RSCP: CreateObjRef, creating SCM of type " + requestedType); return(new ServicedComponentMarshaler((MarshalByRefObject)GetTransparentProxy(), requestedType)); }
// Implement Invoke public override IMessage Invoke(IMessage reqMsg) { AssertValid(); IMessage retMsg = null; // CHECK FOR CTOR if (reqMsg is IConstructionCallMessage) { DBG.Info(DBG.SC, "RSCP: Short circuiting constructor call."); if (((IConstructionCallMessage)reqMsg).ArgCount > 0) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments")); } // WE don't need dispatch the constructor message, the default .ctor is called // by CoCI // Create the return message MarshalByRefObject retObj = (MarshalByRefObject)GetTransparentProxy(); return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, retObj)); } // NON CTOR MESSAGE MethodBase mb = ((IMethodMessage)reqMsg).MethodBase; MemberInfo m = (MemberInfo)mb; DBG.Assert(m != null, "member info should not be null"); if (mb == _getTypeMethod) { DBG.Info(DBG.SC, "RSCP: Hijacking call to GetType"); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(ProxiedType, null, 0, mcm.LogicalCallContext, mcm)); } if (mb == _getHashCodeMethod) { int hashCode = this.GetHashCode(); DBG.Info(DBG.SC, "RSCP: Hijacking call to GetHashCode, returning " + hashCode); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(hashCode, null, 0, mcm.LogicalCallContext, mcm)); } DBG.Info(DBG.SC, "RSCP: Delivering call to " + mb.Name); // convert to class member info MemberInfo clsMemInfo = ReflectionCache.ConvertToClassMI(ProxiedType, m); DBG.Assert(!clsMemInfo.ReflectedType.IsInterface, "Failed to convert interface member info to class member info"); // dispatch the call #if _DEBUG if (clsMemInfo != m) { DBG.Info(DBG.SC, "RSCP: converted interface to class call: " + clsMemInfo.Name); } #endif try { int iMethodInfo; // check for rolebased security if (_fUseIntfDispatch || (((iMethodInfo = ServicedComponentInfo.MICachedLookup(clsMemInfo)) & ServicedComponentInfo.MI_HASSPECIALATTRIBUTES) != 0) || ((iMethodInfo & ServicedComponentInfo.MI_EXECUTEMESSAGEVALID) != 0) ) { // role based security implies we dispatch through an interface MemberInfo intfMemInfo = ReflectionCache.ConvertToInterfaceMI(m); if (intfMemInfo == null) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } //retMsg = EnterpriseServicesHelper.DispatchRemoteCall(reqMsg, intfMemInfo, _server); MethodCallMessageWrapperEx msgex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)intfMemInfo); retMsg = RemotingServices.ExecuteMessage((MarshalByRefObject)_server, (IMethodCallMessage)msgex); } else { // check for AutoDone bool fAutoDone = (iMethodInfo & ServicedComponentInfo.MI_AUTODONE) != 0; String s = ComponentServices.ConvertToString(reqMsg); IRemoteDispatch iremDisp = (IRemoteDispatch)_server; String sret; if (fAutoDone) { sret = iremDisp.RemoteDispatchAutoDone(s); } else { sret = iremDisp.RemoteDispatchNotAutoDone(s); } retMsg = ComponentServices.ConvertToReturnMessage(sret, reqMsg); } } catch (COMException e) { if (!(e.ErrorCode == Util.CONTEXT_E_ABORTED || e.ErrorCode == Util.CONTEXT_E_ABORTING)) { throw; } if (IsDisposeRequest(reqMsg)) { IMethodCallMessage mcm = reqMsg as IMethodCallMessage; retMsg = new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm); } else { throw; } } // if disposing, we need to release this side of the world. if (IsDisposeRequest(reqMsg)) { Dispose(true); } return(retMsg); }
void IObjPool.Shutdown() { DBG.Assert(false, "ComExposedPool: This shouldn't be called"); throw new NotSupportedException(); }
internal static void InstallUtilityApplication(Type t) { DBG.Info(DBG.Registration, "Starting utility installation:"); try { if (Platform.IsLessThan(Platform.W2K)) { return; } ICatalog cat = null; ICatalogCollection apps = null; ICatalogObject app = null; int junk = 0; cat = (ICatalog)(new xCatalog()); if (!Platform.IsLessThan(Platform.Whistler)) { // AS/URT 97116: Keep this from failing the install if // we're on a Beta2 Whistler machine, which has a different // GUID for ICatalog2. ICatalog2 cat2 = cat as ICatalog2; if (cat2 != null) { cat2.CurrentPartition(cat2.GlobalPartitionID()); } } apps = (ICatalogCollection)(cat.GetCollection("Applications")); RegistrationDriver.Populate(apps); app = FindApplication(apps, _appid, ref junk); if (app == null) { DBG.Info(DBG.Registration, "Didn't find existing application..."); app = (ICatalogObject)(apps.Add()); app.SetValue("Name", _appname); app.SetValue("Activation", ActivationOption.Library); app.SetValue("ID", "{" + _appid.ToString() + "}"); if (!Platform.IsLessThan(Platform.Whistler)) { // AS/URT 97116: Keep this from failing the install if // we're on a Beta2 Whistler machine, which has no Replicable property. try { app.SetValue("Replicable", 0); } catch (Exception) {} } apps.SaveChanges(); } else { // Make sure that we can change this puppy: app.SetValue("Changeable", true); app.SetValue("Deleteable", true); apps.SaveChanges(); app.SetValue("Name", _appname); if (!Platform.IsLessThan(Platform.Whistler)) { // AS/URT 97116: Keep this from failing the install if // we're on a Beta2 Whistler machine, which has no Replicable property. try { app.SetValue("Replicable", 0); } catch (Exception) {} } apps.SaveChanges(); } // Import ourselves into the application: Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx)); ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key())); ICatalogObject comp = FindComponent(comps, clsid, ref junk); if (comp == null) { cat.ImportComponent("{" + _appid + "}", "{" + clsid + "}"); comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key())); comp = FindComponent(comps, clsid, ref junk); } DBG.Assert(comp != null, "Couldn't find imported component!"); ConfigureComponent(comps, comp); // And finally, lock this guy down: app.SetValue("Changeable", false); app.SetValue("Deleteable", false); apps.SaveChanges(); DBG.Info(DBG.Registration, "Registering Proxy/Stub dlls:"); Thunk.Proxy.RegisterProxyStub(); // HACK // This is a HACK to get Windows XP Client COM+ export/import functionallity to work. // Export code will try to export System.EnterpriseServices.Thunk.dll because its not in it's // list of non-redist dlls. // We should get rid of this once this name is in the harcoded list in the export code. RegistryPermission rp = new RegistryPermission(PermissionState.Unrestricted); rp.Demand(); rp.Assert(); RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\MICROSOFT\\OLE\\NONREDIST"); rk.SetValue("System.EnterpriseServices.Thunk.dll", ""); rk.Close(); // END HACK } catch (Exception e) { // Log a failure in some acceptable manner. try { EventLog appLog = new EventLog(); appLog.Source = "System.EnterpriseServices"; String errMsg = String.Format(Resource.FormatString("Reg_ErrInstSysEnt"), e); appLog.WriteEntry(errMsg, EventLogEntryType.Error); } catch {} // We threw an exception? What do we do here? //DBG.Assert(false, // "Installation of System.EnterpriseServices threw an exception!", // "Exception: " + e); } }
// We cache this by mapping MemberInfo to MemberInfo in our // cache. Note that because assemblies can never be unloaded, // there's no reason to flush this cache (we won't be holding // anything alive longer than it would have been alive anyway. public static MemberInfo ConvertToInterfaceMI(MemberInfo mi) { // First, try to hit the cache: MemberInfo cmi = (MemberInfo)Cache.Get(mi); if (cmi != null) { return(cmi); } // Failed to hit the cache, do the lookup. // TODO: clean this up a bit. // TODO: Deal with non-methodInfo objects (work off MethodBase) MethodInfo minfo = mi as MethodInfo; if (minfo == null) { return(null); } MethodInfo intfMethodInfo = null; // check for AutoDone Type reflectType = minfo.ReflectedType; if (reflectType.IsInterface) { intfMethodInfo = minfo; } else { // get all the interfaces implemented by the class Type[] rgInterfaces = reflectType.GetInterfaces(); if (rgInterfaces == null) { return(null); } // iterate through all the interfaces for (int ii = 0; ii < rgInterfaces.Length; ii++) { // get interface mapping for each interface InterfaceMapping imap = reflectType.GetInterfaceMap(rgInterfaces[ii]); if (imap.TargetMethods == null) { continue; } // check if a class method in this inteface map matches for (int j = 0; j < imap.TargetMethods.Length; j++) { // see if the class method matches if (imap.TargetMethods[j] == minfo) { // grab the interface method intfMethodInfo = imap.InterfaceMethods[j]; break; } } if (intfMethodInfo != null) { break; } } } DBG.Assert(intfMethodInfo == null || intfMethodInfo.ReflectedType.IsInterface, "Failed to map class method to interface method"); Cache.Reset(mi, intfMethodInfo); return((MemberInfo)intfMethodInfo); }