0

I managed to host the CLR 2.0 in a Delphi win32 application that was able to create and host WPF controls inside a Delphi control, something similar to the ElementHost for WinForms applications.

Now, I want to move my solution to the CLR 4.0 and everything works fine except when I try to create a UserControl that has an associated Xaml resource. In that case it causes a stackoverflow error which forces the process to exit! But if I create some WPF controls by code (without reading xaml) then everything works fine!

I managed to step in the framework code until I entered the XamlReader.LoadBaml method, which crashed just after executing the following code:

            // We don't actually use the GeneratedInternalTypeHelper any more.
            // But for v3 compat, don't allow loading of internals in PT unless there is one.
            Type internalTypeHelper = null;
            if (streamInfo.Assembly != null) 
            {
                try 
                { 
                    internalTypeHelper = XamlTypeMapper.GetInternalTypeHelperTypeFromAssembly(parserContext);
                } 
                // This can perform attribute reflection which will fail if the assembly has unresolvable
                // attributes. If that happens, just assume there is no helper.
                catch (Exception e)
                { 
                    if (MS.Internal.CriticalExceptions.IsCriticalException(e))
                    { 
                        throw; 
                    }
                } 
            }

Note that the loaded assemblies use the CLR4 too.

Thanks for your help,

Morgan

  • Hello there! I'm fairily new to the practice of hosting .net apps into delphi natively by hosting the CLR and such stuff, the thing is that i found curious that you mentioned you used something similar to ElementHost in WinForms to create and host WPF elements in Delphi.. Now, my interest is in WinForms, is there any documentation to help me achieve what I want without the need of Hydra 4? – ULI-R0 Sep 01 '16 at 19:36

1 Answers1

0

I found the issue thanks to another post on Stackoveflow (Hosting CLR in Delphi with/without JCL - example see Important Note).

I had to initialize the fpu with Set8087CW($133F) then the weird stackoverlow stopped!

I still have a weird behaviour though: everything's fine without any debugger, but if i run the app from VS2010, then a black wpf form is displayed preventing me from interacting with the content. However, if i run the app then attach with the debugger then everything's fine!

Community
  • 1
  • 1