To reproduce the error, follows the step below.1) Create a WPF User Control Library.2) Create a default user control as follow<UserControl x:Class="WpfControlLibrary1.UserControl2"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Grid><Label Content="UserControl2.xaml"/></Grid></UserControl>3) use ilmerge to create a test library.ilmerge /lib /out:wpfTestLib.dll WpfUserControlLibrary1.dll4) Add the wpfTestLib.dll to the reference of another Wpf window application and add the UserControl2 custom control.<Window x:Class="TestLib.Window1"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:c="clr-namespace:WpfControlLibrary1;assembly=wpfTestLib"Title="Window1" Height="300" Width="300"><Grid><c:UserControl2/></Grid></Window>5) You will get the following compiler error.Could not create an instance of type 'UserControl2'.I am using vs2008 and I have downloaded the latest version of ilmerge. Thus I wonder what went wrong?
- Edited by Sarah97 Wednesday, December 30, 2009 3:50 AM
You have your xml namespace defined as:
This is saying to pull it from the assembly "tcTestLib.dll".
However, with ILMerge, you created the assembly "wpfTestLib.dll"
You'll need to change the corresponding XAML declaration, or it will not find the appropriate control.
Reed Copsey, Jr. - http://reedcopsey.com
Hi Reed,Thanks for your reply. I made a typing mistake. Even thought I change from tcTestLib to wpfTestLib. The error is still there. What seems very strange is that the intellisense of vs2008 xaml editor shows "UserControl2" right after I finished typing "c:" which means the intellisense knows where to find the custom user control. However I just can't get it to compile.
Hi Microsoft team,I am not trying to be difficult. The reason I want to find out whether is this is a bug is that I have a lot of xaml user controls which are all in separated project files. I simply want to find out if this is a bug or, may be, there is a simple solution to fix it.thanks
Sarah,I've come across this problem myself in recent days. From a brief bit of searching it seems ILMerge doesn't work flawlessly with WPF as it can't handle xaml resources.There are a few other applications suggested here: http://stackoverflow.com/questions/1025843/merging-dlls-into-a-single-exe-with-wpfRegards,Matt
I don't know if you are still having a problem with this - I sort of am. I found that anything saved as a resource seems to appear in the new assembly under the oldassemblyname.g.resources. Take a look in reflector.
Normally you'd have the following:
after the merge you have:
I've been able to load the XAML resources out (resource dictionary) by using the following:
Stream stream = assembly.GetManifestResourceStream(oldAssemblyName+".g.resources");
//Read the found resource
//Find the correct key in the resource
using (ResourceReader resourceReader = new ResourceReader(stream))
foreach (DictionaryEntry de in resourceReader)
if (string.Compare((string)de.Key, ResourcePath, true) == 0)
rd = (
Where the ResourcePath is <oldAssemblyName>.g.resource. I do however still have 1 problem. I have a reference to a view model inside my resource dictionary, and this bombs out when loading the resource dictionary. I've added the schema as:
assembly: XmlnsDefinition("http://schemas/ViewModels", "ResourceSupplierDLL.ViewModels")]
Now, it's the way it bombs out that is funny. If I put my ResourceSupplierDLL.DLL as the first assembly to merge in ILMerge - it works. But if it's anywhere but the first I get the exception public type TestViewModel cannot be found - even though after loading the assembly the type does exist (checked it out by calling assembly.GetTypes() on my just loaded assembly).
Very odd problem indeed.