Yak build error: 'the calling thread must be STA'

Greetings @will, how are things?

We must meet up again soon once this mess is all over!

Anyway, I’m finally trying to do the right thing and create a yak package for biomorpher but running into the following snag when attempting to build, tbh the error is beyond the realms of my knowledge and wondering if you might be able to shed some light?

I have no fancy threading going on in the solution even though the error seems to refer to something to that effect, however Biomorpher.IGA.Friends is mentioned - this is the only static class in the solution so perhaps this could have something to do with it (I don’t know why it would)?

Anyway, any help appreciated! I’ve zipped up to the contents of what I’m trying to build, feel free to decompile if necessary, src on git.

Thanks and see you again soon in the flesh all being well,

John.

0.7.1.zip (2.8 MB)

C:\Users\su918958\Documents\GitHub\Biomorpher\release\0.7.1>"C:\Users\su918958\Documents\YakTemp\Yak.exe" build Building package from contents of C:\Users\su918958\Documents\GitHub\Biomorpher\release\0.7.1

Found manifest.yml for package: Biomorpher (0.7.1)
Inspecting content: Biomorpher.gha

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.TypeInitializationException: The type initializer for ‘Biomorpher.IGA.Friends’ threw an exception. —> System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
at System.Windows.Input.InputManager…ctor()
at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
at System.Windows.Input.KeyboardNavigation…ctor()
at System.Windows.FrameworkElement.FrameworkServices…ctor()
at System.Windows.FrameworkElement.EnsureFrameworkServices()
at System.Windows.FrameworkElement…ctor()
at System.Windows.Controls.Control…ctor()
at System.Windows.Controls.ItemsControl…ctor()
at HelixToolkit.Wpf.HelixViewport3D…ctor()
at Biomorpher.IGA.Friends…cctor()
— End of inner exception stack trace —
at Biomorpher.IGA.Friends.VerionInfo()
at Biomorpher.BiomorpherInfo.get_Version()
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object index)
at Yak.GrasshopperAssemblyInfo.GetProperty[T](String name)
at Yak.GrasshopperAssemblyInfo.get_Version()
at Yak.Inspectors.GrasshopperAssemblyInspector.Inspect()
at Yak.Cli.Commands.BuildCommand.Execute(String args)
at Yak.Cli.Program.Main(String args)

Hey John!

I’ll see if I can fix this in yak itself, but as a workaround try defining BiomorpherInfo.Version directly, instead of using Friends.VerionInfo().

public override string Version => "0.7.1";

Hope you’re well!

Yes of course!

Thank you, not sure why I didn’t spot that; all now works fine. Sometimes it just needs a fresh pair of eyes :slight_smile:

As I use the version info everywhere it made sense to have it in one place, but it’s really no extra trouble to just write the version directly in BiomorpherInfo. I’m guessing the yak ‘fix’ might be overly involved unless others end up doing the same thing.

All good here, term is about to kick off and about to go back to teaching studio - a little concerned about that but otherwise well. Hope you’re doing well too!

After a bit more investigation, the line that’s causing the error is in Friends.cs.

public static HelixViewport3D dummyHelix = new HelixViewport3D();

This field is being initialised when you call Friends.GetVerion() and Yak gets upset because it can’t handle loading UI code when it tries to get the GHA’s version. If you convert this field to a property (or delete it, since it isn’t used) then you can revert the workaround and Yak will be happy again.

public static HelixViewport3D DummyHelix => new HelixViewport3D();

I’m going to fix up Yak so it doesn’t completely crap out when it runs into a situation like this.

Doing well thanks, considering everything that this year is throwing at us! Glad you are too. Good luck in the studio!

Indeed, thanks @will. Works fine with Friends.VersionInfo() reinstated and the dummyHelix deleted. It looks like that was a relic from the past that really should have been cleaned up earlier, I had to play a few tricks to get the 12 windows to orbit at the same time. In the end, later versions do not use the same trick so that field (which should really be a property) can be removed!

Thanks for your help and pleased to flag this up! As you know I’m no software developer but I try :slight_smile:

Thanks also for the well wishes! Pleased to hear you’re well too.

John.