Closed campersau closed 3 years ago
Tagging subscribers to this area: @eiriktsarpalis, @layomia See info in area-owners.md if you want to be subscribed.
@dotnet/crossgen-contrib
Thanks @campersau to reporting this issue. I can repro it with preview4 but not with the latest from main. When you tried on the 6.0.100-preview.6.21301.1
did you compile/publish again?
@mangod9 Yes, I have also removed the bin/
and obj/
folders before I compiled / published again. Here are the json files which look like to contain the exact framework versions (using the 6.0.100-preview.6.21301.1
SDK):
EntryPointNotFound.runtimeconfig.json
{
"runtimeOptions": {
"tfm": "net6.0",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0-preview.6.21276.13"
}
]
}
}
EntryPointNotFound.deps.json
Ok, thanks. I can repro it now. It wasnt repro on a local build of the runtime, since runtime artifacts happen to include a newer version of newtonsoft. I see that crossgen2 doesnt produce correct instantiated generic collections code for some reason for the method Newtonsoft.Json.Utilities.ReflectionUtils.GetFields
:
4ad27: 48 8b f1 mov rsi, rcx
4ad2a: 8b fa mov edi, edx
4ad2c: ff 15 66 0d 0e 00 call qword ptr [0x12ba98] // Newtonsoft.Json.Utilities.ReflectionUtils (CCTOR_TRIGGER)
4ad32: 48 85 f6 test rsi, rsi
4ad35: 74 39 je 0x4ad70
4ad37: ff 15 33 20 0e 00 call qword ptr [0x12cd70] // System.Collections.Generic.List`1<System.Type> (NEW_OBJECT)
4ad3d: 48 8b d8 mov rbx, rax
4ad40: 48 8b ce mov rcx, rsi
4ad43: 8b d7 mov edx, edi
4ad45: ff 15 65 49 0e 00 call qword ptr [0x12f6b0] // System.Collections.Generic.IEnumerable`1<System.Reflection.FieldInfo> Newtonsoft.Json.Utilities.TypeExtensions.GetFields(System.Type, Newtonsoft.Json.Utilities.BindingFlags) (METHOD_ENTRY_DEF_TOKEN)
4ad4b: 48 8b d0 mov rdx, rax
4ad4e: 48 8b cb mov rcx, rbx
4ad51: ff 15 01 38 0e 00 call qword ptr [0x12e558] // void System.Collections.Generic.List`1<__Canon>..ctor(System.Collections.Generic.IEnumerable`1<!0>) (METHOD_ENTRY)
4ad57: 48 8b 0d 8a 5e 0e 00 mov rcx, qword ptr [0x130be8] // [INST] System.Collections.Generic.IEnumerable`1<!!0> System.Linq.Enumerable.Cast<!!0>(System.Collections.IEnumerable)<System.Reflection.FieldInfo> (METHOD_DICTIONARY)
4ad5e: 48 8b d3 mov rdx, rbx
4ad61: ff 15 e1 3b 0e 00 call qword ptr [0x12e948] // System.Collections.Generic.IEnumerable`1<!!0> System.Linq.Enumerable.Cast<!!0>(System.Collections.IEnumerable)<__Canon> (METHOD_ENTRY)
4ad67: 90 nop
4ad68: 48 83 c4 20 add rsp, 32
4ad6c: 5b pop rbx
4ad6d: 5e pop rsi
4ad6e: 5f pop rdi
4ad6f: c3 ret
4ad70: ff 15 da 16 0e 00 call qword ptr [0x12c450] // System.ArgumentNullException (NEW_OBJECT)
4ad76: 48 8b f0 mov rsi, rax
4ad79: 48 8b 15 a0 7b 0e 00 mov rdx, qword ptr [0x132920] // "targetType" (STRING_HANDLE)
Here is what is produced by crossgen1:
b1d27: 48 8b f1 mov rsi, rcx
b1d2a: 8b fa mov edi, edx
b1d2c: ff 15 c6 f7 f4 ff call qword ptr [0x14f8] // Newtonsoft.Json.Utilities.ReflectionUtils (CCTOR_TRIGGER)
b1d32: 48 85 f6 test rsi, rsi
b1d35: 74 39 je 0xb1d70
b1d37: ff 15 e3 02 f5 ff call qword ptr [0x2020] // System.Collections.Generic.List`1<System.Reflection.MemberInfo> (NEW_OBJECT)
b1d3d: 48 8b d8 mov rbx, rax
b1d40: 48 8b ce mov rcx, rsi
b1d43: 8b d7 mov edx, edi
b1d45: ff 15 e5 25 f5 ff call qword ptr [0x4330] // System.Collections.Generic.IEnumerable`1<System.Reflection.FieldInfo> Newtonsoft.Json.Utilities.TypeExtensions.GetFields(System.Type, Newtonsoft.Json.Utilities.BindingFlags) (METHOD_ENTRY_DEF_TOKEN)
b1d4b: 48 8b d0 mov rdx, rax
b1d4e: 48 8b cb mov rcx, rbx
b1d51: ff 15 11 29 f5 ff call qword ptr [0x4668] // void System.Collections.Generic.List`1<System.Reflection.MemberInfo>..ctor(System.Collections.Generic.IEnumerable`1<!0>) (METHOD_ENTRY)
b1d57: 48 8b 0d da 68 f5 ff mov rcx, qword ptr [0x8638] // [INST] System.Collections.Generic.IEnumerable`1<!!0> System.Linq.Enumerable.Cast<!!0>(System.Collections.IEnumerable)<System.Reflection.FieldInfo> (METHOD_DICTIONARY)
b1d5e: 48 8b d3 mov rdx, rbx
b1d61: ff 15 21 21 f5 ff call qword ptr [0x3e88] // System.Collections.Generic.IEnumerable`1<!!0> System.Linq.Enumerable.Cast<!!0>(System.Collections.IEnumerable)<__Canon> (METHOD_ENTRY)
b1d67: 90 nop
b1d68: 48 83 c4 20 add rsp, 32
b1d6c: 5b pop rbx
b1d6d: 5e pop rsi
b1d6e: 5f pop rdi
b1d6f: c3 ret
Guess you already have a workaround to upgrade to a newer version or but if you need to get the 9.x version working you could set one of these:
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
: Builds a single composite r2r image which doesnt run into that issue possibly due to aggressive inlining
-- or --
<PublishReadyToRunUseCrossgen2>true</PublishReadyToRunUseCrossgen2>
: Falls back to original crossgen (the default before preview4)
Thanks for the additional workaround suggestions!
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
: This doesn't seem to work with the original https://github.com/NuGetPackageExplorer/NuGetPackageExplorer WPF project. Starting the exe results in the following errors in the Windows Eventviewer:
Application: NuGetPackageExplorer.exe
CoreCLR Version: 6.0.21.25307
.NET Version: 6.0.0-preview.4.21253.7
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for 'System.Windows.Media.FontFamily' threw an exception.
---> System.TypeInitializationException: The type initializer for 'MS.Internal.FontCache.DWriteFactory' threw an exception.
---> System.InvalidCastException: Specified cast is not valid.
at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr) in DirectWriteForwarder.dll:token 0x600024e+0x53
at MS.Internal.Text.TextInterface.Factory.Initialize(FactoryType factoryType) in DirectWriteForwarder.dll:token 0x6000330+0x0
at MS.Internal.Text.TextInterface.Factory..ctor(FactoryType factoryType, IFontSourceCollectionFactory fontSourceCollectionFactory, IFontSourceFactory fontSourceFactory) in DirectWriteForwarder.dll:token 0x600032f+0xb
at MS.Internal.FontCache.DWriteFactory..cctor() in PresentationCore.dll:token 0x6001410+0x1b
--- End of inner exception stack trace ---
at MS.Internal.FontCache.DWriteFactory.get_SystemFontCollection() in PresentationCore.dll:token 0x6001412+0x0
at System.Windows.Media.FontFamily..cctor() in PresentationCore.dll:token 0x6001120+0x1f
--- End of inner exception stack trace ---
at MS.Internal.Text.DynamicPropertyReader.GetTypeface(DependencyObject element) in PresentationFramework.dll:token 0x6001d9c+0x0
at MS.Internal.Text.TextProperties.InitCommon(DependencyObject target) in PresentationFramework.dll:token 0x6001e30+0x0
at MS.Internal.Text.TextProperties..ctor(FrameworkElement target, Boolean isTypographyDefaultValue) in PresentationFramework.dll:token 0x6001e2d+0x2d
at System.Windows.Controls.TextBlock.GetLineProperties() in PresentationFramework.dll:token 0x60074bc+0x0
at System.Windows.Controls.TextBlock.EnsureTextBlockCache() in PresentationFramework.dll:token 0x60074bb+0x13
at System.Windows.Controls.TextBlock.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x600748f+0xd
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.AccessText.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6005f6f+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) in PresentationFramework.dll:token 0x6000596+0x1c
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006171+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60067f2+0x87
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60069c0+0x43
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Control.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006224+0x19
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.WrapPanel.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60078ba+0xaa
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) in PresentationFramework.dll:token 0x6000596+0x1c
at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006e6a+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Border.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6005fce+0x100
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Control.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006224+0x19
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60067f2+0x87
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) in PresentationFramework.dll:token 0x6000596+0x1c
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006171+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Decorator.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60067ae+0xa
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x600481c+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Border.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6005fce+0x100
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Window.MeasureOverrideHelper(Size constraint) in PresentationFramework.dll:token 0x6002a57+0xd8
at System.Windows.Window.MeasureOverride(Size availableSize) in PresentationFramework.dll:token 0x6002a1c+0x6a
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x39
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Interop.HwndSource.SetLayoutSize() in PresentationCore.dll:token 0x600038f+0x1f4
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) in PresentationCore.dll:token 0x6000373+0x102
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value) in PresentationCore.dll:token 0x6000372+0x7
at System.Windows.Window.SetRootVisual() in PresentationFramework.dll:token 0x6002a3f+0xe
at System.Windows.Window.SetRootVisualAndUpdateSTC() in PresentationFramework.dll:token 0x6002a40+0x0
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight) in PresentationFramework.dll:token 0x6002a3e+0x31f
at System.Windows.Window.CreateSourceWindow(Boolean duringShow) in PresentationFramework.dll:token 0x6002a39+0x161
at System.Windows.Window.CreateSourceWindowDuringShow() in PresentationFramework.dll:token 0x6002a38+0x0
at System.Windows.Window.SafeCreateWindowDuringShow() in PresentationFramework.dll:token 0x6002a97+0x8
at System.Windows.Window.ShowHelper(Object booleanBox) in PresentationFramework.dll:token 0x6002a9b+0x35
at System.Windows.Window.Show() in PresentationFramework.dll:token 0x60029d3+0x1f
at PackageExplorer.App.Application_Startup(Object sender, StartupEventArgs e) in C:\dev_projects\NuGetPackageExplorer\PackageExplorer\App.xaml.cs:line 80
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_0(Object state) in System.Private.CoreLib.dll:token 0x6002df4+0x0
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0x8d
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x2
at System.Windows.Threading.DispatcherOperation.InvokeImpl() in WindowsBase.dll:token 0x6000f87+0x7a
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) in WindowsBase.dll:token 0x6000f86+0x0
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in WindowsBase.dll:token 0x60002de+0x1a
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029a9+0x40
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029a9+0x80
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in WindowsBase.dll:token 0x60002dd+0x34
at System.Windows.Threading.DispatcherOperation.Invoke() in WindowsBase.dll:token 0x6000f84+0xf
at System.Windows.Threading.Dispatcher.ProcessQueue() in WindowsBase.dll:token 0x6000f1a+0xe5
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x6000f21+0x3f
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x60001a3+0x23
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in WindowsBase.dll:token 0x6000193+0x36
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0x76
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x2
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000efa+0xbb
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in WindowsBase.dll:token 0x6000191+0x118
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in WindowsBase.dll:token 0x6000f1c+0x3c
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in WindowsBase.dll:token 0x6000ed7+0x5e
at System.Windows.Application.RunDispatcher(Object ignore) in PresentationFramework.dll:token 0x6001fbe+0x1f
at System.Windows.Application.RunInternal(Window window) in PresentationFramework.dll:token 0x6001f92+0xd9
at PackageExplorer.App.Main() in NuGetPackageExplorer.dll:token 0x6000018+0xb
<PublishReadyToRunUseCrossgen2>false</PublishReadyToRunUseCrossgen2>
: this seems to work fine.
Ok, thanks for checking. Yeah the composite case did work on the simple repro, but looks like it has some trouble with the WPF scenario.
@trylek who is helping with investigating this further.
At the first glance I think the fundamental difference is in the following instruction: in Crossgen2, it produces
4ad37: ff 15 33 20 0e 00 call qword ptr [0x12cd70] // System.Collections.Generic.List`1<System.Type> (NEW_OBJECT)
whereas in Crossgen1 it's
b1d37: ff 15 e3 02 f5 ff call qword ptr [0x2020] // System.Collections.Generic.List`1<System.Reflection.MemberInfo> (NEW_OBJECT)
It looks somewhat similar to a previous problem we had with method dictionaries where a comparison function was missing a field thus incorrectly conflating two different instantiations. For the other difference where Crossgen2 refers to a method on Canon
whereas the Crossgen1 version has List`1
, I saw these in the past and I managed to convince myself this is correct for shared generics as we're in fact really calling the Canon
version, we're just smuggling the instantiation type information into the method by means of the generic dictionary.
@trylek, might also be worthwhile looking into why composite mode fails for Nuget Explorer app. Perhaps we can create a separate issue for that though.
Hmm, I'm getting somewhat lost in the multitude of related issues. Are you referring to this one?
https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/issues/1284
If the answer is positive, it would be great to double-check it's not the same issue my latest PR has fixed as the symptoms are very similar. I'm somewhat scared of the prospect of having to debug this in context of the VS UI, perhaps with the help of @tommcdon, @hoyosjs and / or some VS debugger folks we might be able to figure out how to construct a command-line repro?
As a workaround I had suggested trying composite mode, since the simple repro app didnt fail due to "Entry Point Not Found", but use composite caused a different issue for the original app as mentioned here: https://github.com/dotnet/runtime/issues/53520#issuecomment-852784434
In fact, how come the nuget package manager gets compiled by Crossgen2 at all? I'm not aware of any of our efforts in this space. Has that automatically switched over with the SDK change to use Crossgen2 by default?
@trylek the package explorer is a standalone UI app not in VS (WPF I believe?).
Correct it got switched over when they moved to Preview4 for their standalone app. For now they have explicitly switched it back to cg1.
In fact, the invalid cast @mangod9 refers to (#53520) is exactly what I would expect to be potentially caused by the bug I fixed yesterday.
Ok yeah that could very well be the same root cause too. Perhaps @campersau can help validate that?
In other words, as I'm a newcomer to this problem it will likely take me a bit to ramp up on building and testing stuff. If someone familiar with the problem could confirm or disprove whether the latest dotnet/runtime/main is still hitting the issue, that would be of great help, thanks Manish for facilitating that!
Tested with a crossgen2 build from today (6.0.0-preview.6.21306.9) and I couldn't repro. I could if I used preview 4 bits.
Thanks @hoyosjs for validating! Assume you tried with both cg2 default and composite mode?
If I do PublishReadyToRunComposite
the app fails to start. "The type initializer for 'System.Windows.Media.FontFamily' threw an exception."
is the exception that ends up tearing the program.
@hoyosjs Looks like the same exception I got here https://github.com/dotnet/runtime/issues/53520#issuecomment-852784434
@mangod9 I also get the exception with a simplified WPF example (still using 6.0.0-preview.6.21306.1
as I am waiting for a new daily build).
Just create a new WPF project for .net 6 with this csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform>x64</Platform>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup>
<SelfContained>true</SelfContained>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
And this MainWindow.xaml
(just added a TextBlock
).
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBlock Text="Hello World!" />
</Grid>
</Window>
Here is the complete stacktrace for this simple app (copied from windows eventviewer):
Application: WpfApp1.exe
CoreCLR Version: 6.0.21.30601
.NET Version: 6.0.0-preview.6.21306.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for 'System.Windows.Media.FontFamily' threw an exception.
---> System.TypeInitializationException: The type initializer for 'MS.Internal.FontCache.DWriteFactory' threw an exception.
---> System.InvalidCastException: Specified cast is not valid.
at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr) in DirectWriteForwarder.dll:token 0x600024e+0x53
at MS.Internal.Text.TextInterface.Factory.Initialize(FactoryType factoryType) in DirectWriteForwarder.dll:token 0x6000330+0x0
at MS.Internal.Text.TextInterface.Factory..ctor(FactoryType factoryType, IFontSourceCollectionFactory fontSourceCollectionFactory, IFontSourceFactory fontSourceFactory) in DirectWriteForwarder.dll:token 0x600032f+0xb
at MS.Internal.FontCache.DWriteFactory..cctor() in PresentationCore.dll:token 0x6001410+0x1b
--- End of inner exception stack trace ---
at MS.Internal.FontCache.DWriteFactory.get_SystemFontCollection() in PresentationCore.dll:token 0x6001412+0x0
at System.Windows.Media.FontFamily..cctor() in PresentationCore.dll:token 0x6001120+0x1f
--- End of inner exception stack trace ---
at MS.Internal.Text.DynamicPropertyReader.GetTypeface(DependencyObject element) in PresentationFramework.dll:token 0x6001d9c+0x0
at MS.Internal.Text.TextProperties.InitCommon(DependencyObject target) in PresentationFramework.dll:token 0x6001e30+0x0
at MS.Internal.Text.TextProperties..ctor(FrameworkElement target, Boolean isTypographyDefaultValue) in PresentationFramework.dll:token 0x6001e2d+0x2d
at System.Windows.Controls.TextBlock.GetLineProperties() in PresentationFramework.dll:token 0x60074bc+0x0
at System.Windows.Controls.TextBlock.EnsureTextBlockCache() in PresentationFramework.dll:token 0x60074bb+0x13
at System.Windows.Controls.TextBlock.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x600748f+0xd
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60069c0+0x43
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) in PresentationFramework.dll:token 0x6000596+0x1c
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6006171+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Decorator.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x60067ae+0xa
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x600481c+0x0
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Controls.Border.MeasureOverride(Size constraint) in PresentationFramework.dll:token 0x6005fce+0x100
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x238
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Window.MeasureOverrideHelper(Size constraint) in PresentationFramework.dll:token 0x6002a57+0xd8
at System.Windows.Window.MeasureOverride(Size availableSize) in PresentationFramework.dll:token 0x6002a1c+0x6a
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in PresentationFramework.dll:token 0x6002270+0x39
at System.Windows.UIElement.Measure(Size availableSize) in PresentationCore.dll:token 0x6000829+0x189
at System.Windows.Interop.HwndSource.SetLayoutSize() in PresentationCore.dll:token 0x600038f+0x1f4
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) in PresentationCore.dll:token 0x6000373+0x102
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value) in PresentationCore.dll:token 0x6000372+0x7
at System.Windows.Window.SetRootVisual() in PresentationFramework.dll:token 0x6002a3f+0xe
at System.Windows.Window.SetRootVisualAndUpdateSTC() in PresentationFramework.dll:token 0x6002a40+0x0
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight) in PresentationFramework.dll:token 0x6002a3e+0x31f
at System.Windows.Window.CreateSourceWindow(Boolean duringShow) in PresentationFramework.dll:token 0x6002a39+0x161
at System.Windows.Window.CreateSourceWindowDuringShow() in PresentationFramework.dll:token 0x6002a38+0x0
at System.Windows.Window.SafeCreateWindowDuringShow() in PresentationFramework.dll:token 0x6002a97+0x0
at System.Windows.Window.ShowHelper(Object booleanBox) in PresentationFramework.dll:token 0x6002a9b+0x35
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0x76
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x2
at System.Windows.Threading.DispatcherOperation.InvokeImpl() in WindowsBase.dll:token 0x6000f87+0x7a
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) in WindowsBase.dll:token 0x6000f86+0x0
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in WindowsBase.dll:token 0x60002de+0x1a
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029f7+0x40
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029f7+0x80
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in WindowsBase.dll:token 0x60002dd+0x34
at System.Windows.Threading.DispatcherOperation.Invoke() in WindowsBase.dll:token 0x6000f84+0xf
at System.Windows.Threading.Dispatcher.ProcessQueue() in WindowsBase.dll:token 0x6000f1a+0xe5
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x6000f21+0x3f
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x60001a3+0x23
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in WindowsBase.dll:token 0x6000193+0x36
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0x76
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x2
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000efa+0xbb
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in WindowsBase.dll:token 0x6000191+0x118
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in WindowsBase.dll:token 0x6000f1c+0x3c
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in WindowsBase.dll:token 0x6000ed7+0x5e
at System.Windows.Application.RunDispatcher(Object ignore) in PresentationFramework.dll:token 0x6001fbe+0x1f
at System.Windows.Application.RunInternal(Window window) in PresentationFramework.dll:token 0x6001f92+0xd9
at WpfApp1.App.Main() in WpfApp1.dll:token 0x6000002+0xb
If this should be a separate issue, you can just create a new one from this comment if want.
So probably taking a look at the compilation of FontFamily's static constructor's call to SystemFontCollection getter could help.
The failure seems to be around:
call qword ptr [System_Linq!System.Linq.Utilities.CombineSelectors[[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib]](System.Func``2<System.__Canon,System.__Canon>, System.Func``2<System.__Canon,System.__Canon>)+0xdbe760 (00007ffcd4213d70)]
But there's something fishy with that offset, as that is in the middle of a function and it looks weird to call there.
In case this is needed, repro steps:
git clone https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
git revert -m 1 2115ff0680f5f9aeee8eaf76e85df5b6106f7ea9
Then apply this patch:
diff --git a/Directory.Build.targets b/Directory.Build.targets
index d98c788..00dc0fd 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -13,6 +13,12 @@
<Product Condition="'$(IsTypesProject)' != 'true'">$(Product) ($(Configuration)) ($(Platform))</Product>
</PropertyGroup>
+ <ItemGroup>
+ <KnownCrossgen2Pack Update="Microsoft.NETCore.App.Crossgen2"
+ Crossgen2PackVersion="6.0.0-preview.6.21306.9"
+ />
+ </ItemGroup>
+
<Target Name="AddCommitHashToAssemblyAttributes" BeforeTargets="GetAssemblyAttributes">
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition=" '$(SourceRevisionId)' != '' ">
diff --git a/NuGet.config b/NuGet.config
index b4ce125..62e1f45 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
- <packageSources>
+ <packageSources>
<add key="NuGet CI packages" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/nuget-build/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="BuildPackages" value="https://pkgs.dev.azure.com/dotnet/NuGetPackageExplorer/_packaging/BuildPackages/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+ <add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
+ <add key="dotnet6-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6-transport/nuget/v3/index.json" />
</packageSources>
</configuration>
\ No newline at end of file
Replace the crossgen version in Directory.Build.targets
for whichever version you need to use (as long as JIT or interface changes are not required this should be fine).
Then navigate to the PackageExplorer folder and run dotnet publish -c release /p:PublishReadyToRun=true /p:PublishReadyToRunComposite=true -r win-x64 /bl
. Run NuGetPackageExplorer\PackageExplorer\bin\release\net6.0-windows10.0.19041\win-x64\publish\NuGetPackageExplorer.exe
Description
Using an older version of
Newtonsoft.Json
9.0.1
results in an "Entry point was not found." exception after aPublishReadyToRun
publish. With the latest version13.0.1
ofNewtonsoft.Json
it works correctly or whenPublishReadyToRun
isfalse
.Configuration
6.0.100-preview.4.21255.9
(I also tried out the daily6.0.100-preview.6.21301.1
build which resulted in the same exception)win
x64
Regression?
Yes, with net6.0 preview 3 this worked.
Other information
csproj:
Program.cs
Publish with:
dotnet publish -c Release
Console output when running the published exe:
Reference https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/issues/1284