New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectWriterContext.GetDestinationType may throw null reference exception #100

Open
lindexi opened this Issue Dec 6, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@lindexi
Contributor

lindexi commented Dec 6, 2018

  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Windows version: Windows 10 17025
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: do not know

Problem description:

ObjectWriterContext.GetDestinationType may throw null reference exception when CurrentFrame.Previous is not ObjectWriterFrame.

Actual behavior:

The code is in wpf/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs

    internal XamlType GetDestinationType()
    {
        ObjectWriterFrame frame = _stack.CurrentFrame;

        if (frame == null)
        {
            return null;
        }

        if (frame.Instance != null && frame.XamlType == null) // when true
        {
            //
            // Text/TypeConverter, we need to go up a frame
            frame = frame.Previous as ObjectWriterFrame; // when the  frame.Previous is not ObjectWriterFrame that the frame is null
        }

        // for frame is null, calling the frame.Member will break
        if (frame.Member == XamlLanguage.Initialization) 
        {
            return frame.XamlType;
        }
        return frame.Member.Type;
    }      

if (frame.Member == XamlLanguage.Initialization)

Expected behavior:

We should check the frame = frame.Previous as ObjectWriterFrame; and the frame is not null.

Minimal repro:

@rladuca rladuca added the bug label Dec 6, 2018

@rladuca rladuca added this to the Future milestone Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment