Reputation: 1
When I try to create a Grid, it throw System.Runtime.InteropServices.COMException
var definition = new RowDefinition {Height = GridLength.Auto};
var grid = new Grid { RowDefinitions = { definition, definition } };
StackTrace below:
System.Runtime.InteropServices.COMException (0x800F1000): No installed components were detected.
at WinRT.DelegateExtensions.DynamicInvokeAbi(Delegate del, Object[] invoke_params)
at ABI.System.Collections.Generic.IVectorMethods`1.Append(IObjectReference obj, T value)
at Test..ctor()
...
I try to run below code at Immediate Window:
var g1 = new Grid{RowDefinitions = { new RowDefinition {Height = GridLength.Auto} } };
No Exception.RowDefinition d = new() {Height = GridLength.Auto};
No Exception.var g3 = new Grid{RowDefinitions = {d}};
COMException.And I change my code into
RowDefinition Definition() => new RowDefinition {Height = GridLength.Auto};
var grid = new Grid { RowDefinitions = { Definition(), Definition() } };
it can run without exception.
Upvotes: 0
Views: 124