Skip to content

Commit

Permalink
Remove Resurrect logic as it shouldn't be needed for .NET 6 and newer. (
Browse files Browse the repository at this point in the history
#1380)

* Remove Resurrect logic as it shouldn't be needed for .NET 6 and newer.

* Remove double check.

* Add check back.
  • Loading branch information
jlaanstra authored and Sergio0694 committed Jan 25, 2024
1 parent 81f365e commit f8db5bc
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 178 deletions.
16 changes: 1 addition & 15 deletions src/WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ internal static unsafe InspectableInfo GetInspectableInfo(IntPtr pThis)
// We need to do the same thing for System.Type because there can be multiple WUX.Interop.TypeName's
// for a single System.Type.

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
if (rcw is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}

return rcw switch
{
ABI.System.Nullable nt => (T)nt.Value,
Expand Down Expand Up @@ -161,15 +155,7 @@ public static void RegisterObjectForInterface(object obj, IntPtr thisPtr) =>

public static object TryRegisterObjectForInterface(object obj, IntPtr thisPtr)
{
var rcw = ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
var target = rcw is Delegate del ? del.Target : rcw;
if (target is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}
return rcw;
return ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);
}

public static IObjectReference CreateCCWForObject(object obj)
Expand Down
18 changes: 0 additions & 18 deletions src/WinRT.Runtime/IWinRTObject.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,5 @@ object GetOrCreateTypeHelperData(RuntimeTypeHandle type, Func<object> helperData
{
return AdditionalTypeData.GetOrAdd(type, (type) => helperDataFactory());
}

internal void Resurrect()
{
if (NativeObject.Resurrect())
{
foreach (var cached in QueryInterfaceCache)
{
cached.Value.Resurrect();
}

// Delegates store their agile reference as an additional type data.
// These should be recreated when instances are resurrect.
if (AdditionalTypeData.TryGetValue(typeof(AgileReference).TypeHandle, out var agileObj))
{
AdditionalTypeData.TryUpdate(typeof(AgileReference).TypeHandle, new AgileReference(NativeObject), agileObj);
}
}
}
}
}
Loading

0 comments on commit f8db5bc

Please sign in to comment.