Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more: , +
Hello there,

I have a little problem with using a non-standard user control in my existing WPF project, not critical, but very annoying. I'm trying to use the WPF NotifyIcon[^] by Philipp Sumi in my WPF project. I added a reference, added the namespace in XAML and C#, but the designer doesn't recognize the type. If I compile or debug, however, everything seems to work fine and I can use the control just as it was intended.

This leaves me with a working control that's just hard to use, since I can't take advantage of IntelliSense in the XAML code. Oddly enough, it doesn't even recognize my local type and gives me the same error message about a not found type and a missing assembly as the one I get with the TaskbarIcon.

I tried taking the same steps in a new project, without doing anything else before, and it worked, so I'm baffled why it behaves differently in two different projects (both target .NET 3.5, if that's important). Maybe someone can give me a hint on how to make this work? I have using Hardcodet.Wpf.TaskbarNotification; in my C#, and here is what my XAML looks like. If you need anything else to see what's going on, please ask.

<<Window x:Class="ASM_Informer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tb="http://www.hardcodet.net/taskbar"
        xmlns:local="clr-namespace:ASM_Informer.UI"
        Title="MainWindow" Height="Auto" Width="Auto">
    <Grid>
        <tb:TaskbarIcon x:Name="tb" ToolTipText="hello world">
            <tb:TaskbarIcon.TrayPopup>
                <local:DispoRMUC/>
            </tb:TaskbarIcon.TrayPopup>
        </tb:TaskbarIcon>
    </Grid>
</Window>



TaskbarIcon and DispoRMUC (my own user control that is found in the UI namespace) are the types that the designer apparently can't find and that show the error message.
I'm using the German version of Visual Studio 2010 (Professional), so I only have the German error message ("Fehler - Der tb:TaskbarIcon-Typ wurde nicht gefunden. Alle Assemblyverweise müssen vorhanden sein, und alle Assemblys, auf die verwiesen wird, müssen erstellt worden sein."), so I'll roughly translate: "Error - the tb:TaskbarIcon-type was not found. All assembly references must exist and all referenced assemblies must have been built.".

Many thanks in advance for anyone who takes the time to look into this. I hope someone can help me with this.
Posted
Updated 11-Feb-20 9:22am
Comments
Sergey Alexandrovich Kryukov 15-Mar-11 11:48am    
Are you saying all compiles and runs correctly but designer is not showing now? It happens.
Did you try to clean up and rebuild all from scratch?
--SA
Spoon Of Doom 16-Mar-11 3:07am    
Yes, exactly. As I said before, it's rather an annoyance than a critical error, but still it's.. well, annoying :)

I cleaned up and rebuilt, unfortunately it didn't make a difference. But thanks for the advise anyway!

Edit: Just to clarify, not only does the designer not show it, the XAML editor also marks the "TaskbarIcon" type with an error, saying that it could not be found.
Sergey Alexandrovich Kryukov 16-Mar-11 3:33am    
Hm... hard to say without the full project showing the condition... Frankly, I learned to minimize XAML (only dictionary, layout and binding, never events -- auto-generate event handlers is evil), so I don't create blockers of this sort. Also, do you use revision control? A must have, even for smallest projects, you always can trace back your steps...
--SA
Spoon Of Doom 16-Mar-11 4:08am    
Yes, the whole thing sits in a Team Foundation Server. But even with this, I haven't yet been able to find out exactly what's causing the problem, especially since even the local namespace is making the same problems. Is there anything specific you'd need to see? I don't want to spam the place by posting my whole project.
Anyways, I'll keep eye out and post back here if I find out what's causing this, but for now I guess I'll just move this stuff out of the XAML like you suggested so I don't get spammed by false errors all the time. I have a deadline and have probably already spent too much time tracing this problem than I should have. Thanks for your help!

The WPF Designer in Visual Studio is a basic designer. But the Visual Studio 2010 has better WPF Designer. The rendering of Design Time depends on the Controls and Complex design used in that particular Window or UserControl.

For example:
If you have a control which load records from DB on when initialized that the Designer will fail to show the Design, because if would not connect to DB unless you run the application.

But in your case, the problem is with the TaskbarIcon control. If you have the source code, try adding the project as reference and see.
 
Share this answer
 
Comments
Spoon Of Doom 16-Mar-11 3:54am    
Thanks very much for the advice. I tried adding the project, but the result was exactly the same. Any other hints?
Venkatesh Mookkan 17-Mar-11 2:51am    
Then you need to use a better Designer. Expression Blend 2.0 or greater is better than Visual Studio.
This has not been solved! I get problems like this all the time, even references and namespaces that do work suddenly stop working. Sometimes the intellisense sees my class in the namespace but the namespace is not recognized!

This really needs to be fixed.
I'd be happy to take a breaking change in the formatting if that's needed.
 
Share this answer
 
Comments
Glenn Rockland 14-Nov-14 19:49pm    
This still happens today - DateTime.Now
Schuttrim 11-May-17 3:10am    
Happened today inside a style's setter: "Type 'type' initialization failed: The type initializer for 'qualified.type.name' threw an exception."

This builds and even executes fine, but the line also causes weird errors through all xaml's and resource dictionaries where this is used. so in fact i have tons of errors by this line, but it works. This isn't nice.

Visual Studio 2015 Update 3
Hi We had same problem with TaskbarIcon component. We managed it by reinstalling package Hardcodet.NotifyIcon.Wpf in Visual Studio.

Tools >> NuGet Package Manager >> Manage NuGet Packages for Solution...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900