子斗子
子斗子

Reputation: 1

Get a COMException from WinUI3 when create a grid

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:

  1. var g1 = new Grid{RowDefinitions = { new RowDefinition {Height = GridLength.Auto} } }; No Exception.
  2. RowDefinition d = new() {Height = GridLength.Auto}; No Exception.
  3. 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

Answers (0)

Related Questions