TextBox throws an exception when building library/plugin for Autodesk Revit
I'm building a WPF plugin for Autodesk Revit application. I included Material design to my app. Here is a dummy project, it demonstrates the same problem that i'm facing in my actual application.
Since i'm building a library, i do not have app.xaml. I merged resources in the Resource dictionary file and i use them in the Window1 window.
When using TextBox, the application breaks, i get the following error:
System.Windows.Markup.XamlParseException: 'Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.'
Inner exception: NotImplementedException: The method or operation is not implemented.
Stack trace is the following:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at brisi.Window1.InitializeComponent() in C:\Users\Default\Desktop\brisi\brisi\Window1.xaml:line 1
I do have to point out that i have two bullshit lines of code in my .xaml.cs file:
ColorZoneAssist.SetMode(new CheckBox(), ColorZoneMode.Accent);
Hue hue = new Hue("xyz", System.Windows.Media.Color.FromArgb(1, 2, 3, 4), System.Windows.Media.Color.FromArgb(1, 5, 6, 7));. I don't have a good understanding of how Revit loads libraries that my plugin is using, but if i don't use those two lines, the app breaks [this problem].
I understand that debugging this problem will be difficult if you don't have access to Autodesk Revit. Any help will be appreciated.
Hi @JovanovicMarija sorry for the delay. I do not actually have access to the Revit, but I suspect the issue is with the assembly loading. I did find this other repo on github that does some assembly loading of third party libs. Which is what I suspect you need.
Basically I expect that you will need to locate and call Assembly.LoadFrom on both the MaterialDesignThemes.Wpf.dll and MaterialDesignColors.dll
Hi,
I can confirm that there is some kind of a problem with TextBox when it's used inside WPF class library as Marija described and called from COM enabled environment like Excel, Access VBA. It's not linked to a Revit library. You can create a small WPF class library, put only <TextBox />, call it from any COM and code breaks with the above-mentioned error.
Because of the nature of the error, "Not implemented" it made me wonder maybe it was broken between versions and it sure was. Code works normally when u use version 2.2.1.750 and you call the library from COM but then it breaks when you call it from let's say ConsoleApp. If you change it back to current stable 2.6.0 then it works from Console but not from COM again.
I hope you can figure out what's wrong with this because it's really annoying that you can't use simple TextBox,
@dfistric can you provide a GitHub repository where you reproduce the error in a simple console application?
Hi, here is the link to a repository where I tried to explain everything
https://gitlab.com/dfistric/wpftextblock
This is the simplest possible sample, MainWindow with Button and TextBox, no MVVM, no ResourceDictionary, Material design is referenced inside <Window.Resources>.
Try two types of calls from ConsoleApp and from Excel file with two different references in class library, one to 2.6.0. MaterialDesignThemes, and highest one when it works from COM 2.2.1.750, any higher doesn't work.
Hi, did anybody had time to check upper mentioned problem. Thx
@dfistric can you re-test with 3.0.0-ci3552 or later. I believe that the fix is already done for that.
@Keboo yes it works, I didn't test it before with prerelease version, my bad, only with the stable branch. Thank you for your time to check this out.