Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IDIC casts to invalid WinRT interfaces #1659

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Tests/FunctionalTests/DynamicInterfaceCasting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,26 @@
IList<List<Point>> list2 = new List<List<Point>>();
instance2.IterableOfPointIterablesProperty = list2;

// Ensure that these don't crash but return null
if ((IWinRTObject)instance as IList<Point> != null)
{
return 105;
}

if ((IWinRTObject)instance as IList<ManagedClass> != null)
{
return 106;
}

return 100;

object SetAndGetBoxedValue(TestComponentCSharp.Class instance, object val)
{
instance.ObjectProperty = val;
return instance.ObjectProperty;
}

class ManagedClass
{
public int Number { get; set; }
}
7 changes: 7 additions & 0 deletions src/WinRT.Runtime/IWinRTObject.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT
}
}

// Make sure we are going to do a QI on a WinRT interface,
// otherwise we can get a helper type for a non WinRT type.
if (!Projections.IsTypeWindowsRuntimeType(type))
{
return false;
}

Type helperType = type.FindHelperType();
if (helperType is null || !helperType.IsInterface)
{
Expand Down