views:

373

answers:

1

I am building a Prism app with several modules, one of which (MyModule) contains a user control (MyUserControl) that I created. MyUserControl tests fine, but when I add it to MyModule and run the app, I get this exception:

"Cannot find type 'MyUserControl'. The assembly used when compiling might be different than that used when loading and the type is missing."

I can fix the error by adding a reference to MyUserControl to my Shell application. But of course, that defeats the whole purpose of Prism, since the Shell does not use MyUserControl--only MyModule uses it.

MyUserControl is based on the WPF Calendar control from the WPF Toolkit, which seems to have a similar problem. I have another user control in another module that does not depend on the WPF Toolkit, and I don't get this exception for that control.

Any suggestions on how to fix this problem without coupling the Shell to MyUserControl? Thanks.

+1  A: 

I think what you need is just copy the MyUserControl.dll once built into the main app folder (adding a reference in your main app is just doing that) the simplest way of doing that is using a post build event. right click on MyUserControl project , select properties, select the "Build Events" tab, in the Post-build command line type: xcopy $(TargetFileName) $(SolutionDir)\YOUR MAIN APP FOLDER\bin\Debug\Modules\ /Y and that's it, once MyUserControl is built it will be copied into the main app folder automatically, then when you run the app the module that uses it will be able to find it.

Enrique G
That's the answer. I forgot the post-build event. For anyone else researching the issue: Since the Shell app is ignorant of its modules, the compiler won't pick up MyUserControl as a dependency. Hence the need for the post-build event.
David Veeneman

related questions