1

I have two projects, Project A is a WPF Application and Project B is a WPF Control Library.

Project A References default WPF stuff. But not System.Windows.Controls.Ribbon.

Project B defines a class MainWindow which inherits from RibbonWindow, located in the System.Windows.Controls.Ribbon Assembly.

Inside the App.xaml.cs im going to set the Current.MainWindow instance to a MainWindow of Project B

Current.MainWindow = factory.CreateMainWindow(); // Returns of type `MainWindow`

This causes the following Build-Errors:

CS0012: The type 'RibbonWindow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Controls.Ribbon, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

CS0029: Cannot implicitly convert type 'MyNamespace.MainWindow' to 'System.Windows.Window'

It can be solved referencing System.Windows.Controls.Ribbon from Project A

As you can see, MainWindow is a RibbonWindow which is a Window. Current.MainWindow requires a Window to be set. The MainWindow returned by factory.CreateMainWindow() is to be converted implicitly to Window.

Why does the implicit conversion require Assemblys of all in-between-Types to be referenced?

Community
  • 1
  • 1
LuckyLikey
  • 3,504
  • 1
  • 31
  • 54
  • 1
    "`MainWindow` is a `RibbonWindow` which is a `Window`" - **you** know that. **I** know that. The *compiler* can't know that until it sees that assembly. The compiler only works (when compiling each project) with the source code files and the assemblies *you* tell it it should pay attention to via references. – Damien_The_Unbeliever Apr 27 '17 at 08:47
  • @dam thanks, can you provide a bit more about the background of how the compiler does do this? Is it possible to tell the Compiler about those inbetween types without referencing the assembly? – LuckyLikey Apr 27 '17 at 09:03

0 Answers0