Mono.Cecil assembly references declared in XAML only - wpf

I have a WPF appliation which uses the WPFToolkit.Extended from Codeplex for some controls.
The project file of the WPF application contains a reference to the WPFToolkit.Extended assembly.
For deployment purposes I'd like to have all assembly references for the WPF application which I query with Mono.Cecil:
assembly.SelectMany(asm => asm.Modules).SelectMany(m => m.AssemblyReferences)
Now I noticed that the WPFToolkit.Extended is not in the result list. I assume because it is referenced in XAML only.
Is there a better way to solve this than instantiating a dummy instance of that assembly in the code (according my experiments this will work)?

Related

Embed BAML in assembly without WPF

I would like to embed compiled XAML into an assembly as BAML2006.
If the Embedded Resource MSBuild action is selected, the XAML file gets embedded into the assembly as a text resource that can be read like any other loose XAML resource. However, loose XAML has some serious limitations when it comes to referenced namespaces, most cripplingly, any namespace referred to by its [XmlnsDefinitionAttribute] must be loaded into the AppDomain before the loose XAML is parsed. In contrast, embedded BAML does not suffer from this, as the assembly containing the namespace is added to the list of referenced assemblies and is loaded by the AppDomain automatically before any code starts running.
If the Page MSBuild task is selected, XAML gets "compiled" into BAML2006 and is embedded to the .resources.g of the containing assembly. However, compilation will fail if the WindowsBase, PresentationCode and PresentationFramework assemblies are not referenced. As I am working on a project which uses XAML but not WPF (we load object graphs with XamlObjectWriter and custom markup extensions, but reuse the Visual Studio some of XAML editor infrastructure for IntelliSense support), I would like to avoid depending on these libraries.
Is there any way to make MSBuild embed BAML and add required assembly references without depending on WPF?
I guess Workflow Foundation uses a similar approach, but I haven't been able to find any information.

VS2010 WPF Designer and assembly references

I have a situation while developing a WPF MVVM application. After some extensive searching I'll try to explain the experienced behaviour on SO, and hope someone has a solution.
The WPF application under development, has a reference to a local developed "Infrastructure" assembly. This assembly mainly consists of classes to commmunicate with our WCF services.
This assembly has a assembly reference to a second assembly, "Ninject.Extensions.WCF", whoose content is used in some functionalities.
When I include a reference to the "Infrastructure" assembly, i get a VS2010 designer error that it cannot find the "Ninject.Extensions.WCF" assembly within a couple of seconds after triggering a local build.
This all makes sense because the designer "probably" traverses all referenced assemblies for definitions.
In this particular case, the assembly it's trying to load has nothing to do with WPF, so I can live with the designer not trying to resolve the assembly.
Is there a way to "tell" the designer to ignore these missing referenced assemblies instead of throwing an exception?

WPF: What is App.xaml's Purpose?

I've done .Net development for awhile but I'm new to the WPF technology. What is the supposed purpose of App.xaml? Also, what type of xaml code do you usually put in it? It seems like for simple applications it could be ignored and left untouched. Is this true?
App.xaml is the declarative portion of your code (usually generated by Visual Studio) extending System.Windows.Application. For example, Expression Blend can use App.xaml to share a Resource Dictionary or a design-time data set with your entire application. And, because we are using Microsoft products, whatever Expression Blend can do auto-magically, we can do by hand in Visual Studio.
Now the tangent: To me, to ask about the purpose of App.xaml is to ask about the purpose for System.Windows.Application. Feel free to accuse me of changing the original question (let the digital brutality ensue).
You can’t just open a System.Windows.Controls.Window in any Assembly you like… Chris Sells is likely telling me this in his book. I began to understand the purpose of System.Windows.Application while using MEF and MVVM Light to display WPF windows in DLLs (not EXEs). I got errors like this:
The type 'System.Windows.Markup.IComponentConnector' is defined in an assembly that is not referenced.
or
The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced.
The above error is simply saying that I’m trying to open a WPF Window inside of a DLL and not an EXE. Then, there’s this error:
The component 'Songhay.Wpf.WordWalkingStick.Views.ClientView' does not have a resource identified by the URI '/Songhay.Wpf.WordWalkingStick;component/views/clientview.xaml'.
This boils down to the absence of a facility that associates WPF Window XAML with the WPF “code” (an instance). This facility is associated with WPF EXEs and not WPF DLLs. Visual Studio auto-generates a WPF EXE class called App.g.cs (in your \obj\Debug folder) with this call in it: System.Windows.Application.LoadComponent(this, resourceLocater) where resourceLocater is a badly named variable containing a System.Uri pointing to the XAML like ClientView.xaml mentioned above.
I’m sure Chris Sells has a whole chapter written on how WPF depends on System.Windows.Application for its very life. It is my loss (quite literally of time) for not having read about it.
I have shown myself a little something with this unit test:
[STAThread]
[TestMethod]
public void ShouldOpenWindow()
{
Application app = new Application();
app.Run(new Window());
}
Failing to wrap a new Window in the System.Windows.Application.Run() method will throw an error from the land of COM talking about, “Why did you pull the rug from underneath me?”
For simple applications, it is true, it can be ignored. The major purpose for App.xaml is for holding resources (style, pens, brushes, etc.) that would would like to be available through out all of the windows in your application.
It is true. App.Xaml is some sort of central starting point. You CAN use it, or you CAN start your first window (it is defined in the app.xaml) manually. There are some lifetime events there centralls (like application start).
Storing resources that are used across the whole application.
Application is the root of the logical tree.
It is like Global.asax if you are coming from an ASP.NET background. You can also use it to share resources throughout your application. Comes in pretty handy for resource sharing.
App.xaml is a major part of wpf application.
It contains major four attributes
1.X:Class->used to connect you xaml and code-behind file(xaml.cs).
2.xmlns->To resolve wpf elements like canvas,stack panel(default one).
3.xmlns:x->To resolve XAML language definition.
4. StartupUri->To give start window when application is launching.
++++++++
App.xaml is the declarative starting point of your application. Visual
Studio will automatically create it for you when you start a new WPF
application, including a Code-behind file called App.xaml.cs. They
work much like for a Window, where the two files are partial classes,
working together to allow you to work in both markup (XAML) and
Code-behind.
App.xaml.cs extends the Application class, which is a central class in
a WPF Windows application. .NET will go to this class for starting
instructions and then start the desired Window or Page from there.
This is also the place to subscribe to important application events,
like application start, unhandled exceptions and so on.
One of the most commonly used features of the App.xaml file is to
define global resources that may be used and accessed from all over an
application, for instance global styles.
+++++++++
Source : http://www.wpf-tutorial.com/wpf-application/working-with-app-xaml/
Here is an updated answer in case people are still looking.
There is this excellent article on WPF, and the link specifically puts you at the App.Xaml point to begin teaching you the things you can do with it.
WPF is easy for the first very simple app or two. However, due to the increased flexibility of the framework, you need these types of tutorials to help you understand what can be done from where (in the various application files).
https://www.wpf-tutorial.com/wpf-application/working-with-app-xaml/
Good luck.

IlMerge Silverlight Class Library with Custom Controls

I am trying to merge all the assemblies of an class library in a single .dll file.
I can merge all the assemblies using the Ilmerge but is that when I use the merged dll in a Silverlight application I am having trouble when a template is apply to my control and binding problems if I use a control that inherits with UserControl.
is there any solution to solve this problem?
The problem is that when the initial dlls are built the Xaml in the project is added as a resource in the dll. The code generated to load this xaml will look something like this:-
System.Windows.Application.LoadComponent(this, new System.Uri("/SilverlightLibrary1;component/MyControl.xaml", System.UriKind.Relative));
Note how the name of the dll forms part of the Uri need to fetch the xaml. I doubt IlMerge is able to spot that and fix it up. Hence once merged the Uris cannot be found.
A resolution for this is probably uglier than multiple references or simply creating another project that links all the code files involved.

XAML in VS Shell: Loading an assembly without reference

I'm currently trying to customize a Visual Studio Isolated Shell so it opens a XAML file and its designer without a solution or a project. Therefore, for the designer to load, Visual Studio need to recognize every xaml tag in the XAML file or it won't load telling me that the document contains errors.
I'm currently trying to manually load an assembly from Telerik's control set (RadControls) without a reference since I need to use the designer without a solution/project.
Is it possible to manually load an assembly in XAML from a "custom" .dll like Telerik's without a VS project reference so the custom controls from the assembly are recognized by Visual Studio at design time (in order to use the WPF designer)?
Thanks!
SatixX
maybe you can read the namespace references out and try to resolve the assemblies in GAC and/or any other location (think of standard paths .NET itselfs looks for assemblies). Then try to load them with reflection. Afterwards you then could try to load the XAML. But: if an assembly isn't found, you should throw an error and stop loading the XAML. Also, considering an appdomain might be well suited because you can unload it again.
-sa

Resources