.baml resource generation does not correctly resolve types
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/content/problem/936146/baml-resource-generation-does-not-correctly-resolv.html)._
---
In a WPF application if we use 'http' style namespaces like this for example:
<Window
...
xmlns:dxe="https://schemas.devexpress.com/winfx/2008/xaml/editors"
...>
...
<dxe:SpinEdit ... /> <!-- use a DevExpress SpinEdit control -->
...
</Window>
The application builds and runs fine. However, the generated .baml does not correctly define the SpinEdit control as belonging to a DevExpress assembly, and so if we try to use a System.Windows.Markup.Localizer.BamlLocalizer object and invoke its UpdateBaml method, it throws a XamlParseException "Cannot find type 'SpinEdit'. Type names are case sensitive" exception.
Inspecting the .baml in .NET Reflector shows that the SpinEdit references are generated without any way to resolve them, just as if they were built-in e.g. 'Button' or 'TextBox' WPF types.
For example, looking at a particular *.g.resources/*.baml resource, it appears like this:
<SpinEdit ... />
No namespace is supplied in the tag at all. This I believe is what causes the issue in BamlLocalizer.
On the other hand, if I simply change the namespace in the .xaml file to use old-school clr-namespace style:
<Window
...
xmlns:dxe="clr-namespace:DevExpress.Xpf.Editors;assembly=DevExpress.Xpf.Core.v18.1"
...>
...
<dxe:SpinEdit ... /> <!-- use a DevExpress SpinEdit control -->
...
</Window>
(All that is changed is to use the clr-namespace style instead of http style)
Then BamlLocalizer works fine, and the generated .baml resource looks like this:
<dxe:SpinEdit ... xmlns:dxe="clr-namespace:DevExpress.Xpf.Editors;assembly=DevExpress.Xpf.Core.v18.1" />
As it should.
Please fix the baml generator to properly resolve types, without having to resort to using clr-namespace xmlns definitions. It should work just as well using http xmlns definitions.
---
### Original Comments
#### Jack Warner on 3/2/2020, 00:17 PM:
I've done some more research into this, and it appears that it isn't the <dxe:SpinEdit ... /> tag that it is balking at, but rather in e.g. a binding expression such as this:
<TextBlock TextBlock.Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=dxe:SpinEdit},Path=MinValue}" />
<br>Or this:
<Style Style.TargetType="{x:Type dxe:SpinEdit}">
Or this, within the above <Style... tag:
<Setter Setter.Property="IsFloatValue" Setter.Value="False" />
which gets turned into this, in the .baml:
<Setter Setter.Property="SpinEdit.IsFloatValue" Setter.Value="False" />
All I know is that it is complaining about one or more of the 'SpinEdit' references in it.
#### Visual Studio Feedback System on 3/2/2020, 06:26 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
---
### Original Solutions
(no solutions)
Contributor guide
Assessment
This issue has not been assessed yet.