dotnet / dotnet/wpf

IDestinationTypeProvider.GetDestinationType() throws NullReferenceException when used in custom markup extension

Open
#3,521 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* Windows version: Windows 7
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes/No (.NET Framework 4.8 isn't installed so I can't try on it)



**Problem description:**

When calling IDestinationTypeProvider.GetDestinationType() in a custom markup extension, the call to the method ends up with a NullReferenceException

**Actual behavior:** NullReferenceException thrown
>at MS.Internal.Xaml.Context.ObjectWriterContext.GetDestinationType()
at MS.Internal.Xaml.ServiceProviderContext.GetDestinationType()
at MarkupExtension's namepsace.TestExtension.ProvideValue(IServiceProvider serviceProvider)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)

**Expected behavior:**

IDestinationTypeProvider.GetDestinationType() returns the C# type of the property where the markup extension has been used

**Minimal repro:**

*The markup extension:*

public class TestExtension : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (serviceProvider.GetService(typeof(IDestinationTypeProvider)) is IDestinationTypeProvider destinationTypeProvider)
{
Type destinationType = destinationTypeProvider.GetDestinationType();
}
//Do other stuff
}
}

*Using the markup extension:*

In any .xaml file of a WPF project define the xmlns for the `TestExtension`'s namespace and then use the markup extension like ``

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.