The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sabeeshcs (6) [Avatar] Offline
I am a new comer in C++/CLI programming. I am reading CLI/C++ in action trying to do the program in C++/CLI. I am using Windows XP and Visual studio 2008, framework 3.5. My problem is that, I had try to create the sample program " Using C++/CLI to write a WPF application " ( in chapter 7 ). In this chapter, you had describe Three ways to write WPF apps using c++, the first two programs is working, but the third one is not working properly ( may be my mistake. ) .
My program is like this,

I create a C# WPF Custom Control Library project and delete the default .xaml file and add a new .xaml file into the new project and the code is like this,

<Window x:Class="CSXamlLibrary.BaseWindow" >
Title="First Avalon App ( dynamically load XAML)" Height="400" Width="400" ResizeMode="NoResize">

<ListBox Canvas.Left="10" Canvas.Top="10" Width="180" Height="350" >
Name="listbox" x:FieldModifier="protected" />
<TextBox Canvas.Left="200" Canvas.Top="10" Width="180" Height="25" >
Name="textbox" x:FieldModifier="protected" />
<Button Canvas.Left="200" Canvas.Top="45" Width="80" Height="25" >
Name="addbutton" x:FieldModifier="protected">Add</Button>


and save the file and build it. Then VS-2008 create a .dll file.
After that I create a new C++/CLI project and apply the settings, add assemblies and add the referance to that .dll file, and my code is like


using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;

ref class AppMainWindow : CSXamlLibrary::BaseWindow

addbutton->Click += gcnew RoutedEventHandler(
this, &AppMainWindow::OnAddButtonClick);


void OnAddButtonClick(Object^ sender, RoutedEventArgs^ e)

textbox->Text = "";


#include "AppMainWindow.cpp"

ref class FirstAppDerive : Application

virtual void OnStartup(StartupEventArgs^ e) override
AppMainWindow^ mainwnd = gcnew AppMainWindow();


#include "FirstAppDerive.cpp";

using namespace System;
using namespace System::Windows;

int main( array<String^>^ args)

return ( gcnew FirstAppDerive())->Run();


and build the project, then it successfully build and display the output like this
1>------ Build started: Project: clr3, Configuration: Debug Win32 ------
1>Copying 'e:VisualStudioTestingCSXamlLibraryCSXamlLibraryinDebugCSXamlLibrary.dll' to target directory...
1>Copying 'e:VisualStudioTestingCSXamlLibraryCSXamlLibraryinDebugCSXamlLibrary.pdb' to target directory...
1>.App.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Generating Code...
1>Embedding manifest...
1>Caching metadata information for c:windowsassemblygac_msilwindowsbase3.0.0.0__31bf3856ad364e35windowsbase.dll...
1>Caching metadata information for e:visualstudiotestingcsxamllibrarycsxamllibraryindebugcsxamllibrary.dll...
1>Caching metadata information for c:windowsassemblygac_32presentationcore3.0.0.0__31bf3856ad364e35presentationcore.dll...
1>Caching metadata information for c:windowsassemblygac_msilpresentationframework3.0.0.0__31bf3856ad364e35presentationframework.dll...
1>Build log was saved at "file://e:VisualStudioTestingclr3clr3DebugBuildLog.htm"
1>clr3 - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


But when I try to run the program, the program open a file like "BaseWindow.xaml.cs" ( it is in my case, my first program name is BaseWindow.xaml ) and pointing to " InitializeComponent(); " and display a message like this.

An unhandled exception of type 'System.Exception' occurred in PresentationFramework.dll

Additional information: The component 'AppMainWindow' does not have a resource identified by the URI '/CSXamlLibrary;component/basewindow.xaml'.

How can I solve this problem. Please help me

Level (2) [Avatar] Offline
Re: An unhandled exception of type 'System.Exception' occurred
I have the same, exact problem and error message. VS 2008, .NET 3.5. Attempting to derive from a WPF class in a C# custom control library, using the method described in section 7.2.4 in the book. Has anyone found a solution?
Level (2) [Avatar] Offline
Re: An unhandled exception of type 'System.Exception' occurred
I learned it is not possible to derive a C++/CLI class from the C#-based WPF library. See, especially comments #5 and #7.