Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't load assembly with reflection when using data binding in WPF

Posted on 2011-09-15
6
Medium Priority
?
325 Views
Last Modified: 2012-08-14
When using a Window.Resources element to instantiate a custom class contained in a name space it can't be instantiated.  

This seems to be because of using reflection in the custom class' constructor to dynamically load a class in an unreferenced assembly (I did not want to have to have it referenced because of possibly wanting to replace it with a diff implemntation of the assemby in the future).  

The given reason for this problem is because the unreferenced assembly can't be found.  Of course, I verified that the so-called missing assembly truly is in the bin\debug\ directory.   The real problem is because the designer is apparently looking for the assembly at "file:///C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\" instead of the bin\debug directory.  I tried it in VS2010 but it fails for the same reason except it is looking for the dll in the directory where the "sln"  file is located.

Why is Visual Studio looking for the DLL in those directories instead of the local directory debug\bin directory?.  Oh, btw it executes fine as an executable, it's just that the designer can't refresh in VS 2008.  Is there some sort of config option I need to adjust?
0
Comment
Question by:modotx
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36549088
You can add a reference to a DLL and update that DLL without having to do anything to the application. The obvious exception is when you make a breaking change to the way your application uses the DLL. For example, if you add a parameter to the constructor, you will have to add the parameter to the instantiation in your application and recompile.
0
 
LVL 3

Expert Comment

by:Neun123
ID: 36552571
I would look at the Working Directory configuration in:
Project Properties --> Debug

as described here:

http://msdn.microsoft.com/en-us/library/0a10ws2y.aspx
0
 

Author Comment

by:modotx
ID: 36561350
Neun123,

I tried what was suggested but it didn't work.  I do not think the designer looks at the Working Directory when not running in debug mode (keep in mind that I have not yet started the debugger, I have only done a build).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:modotx
ID: 36561466
Hi Strickdd,

I understand what you are saying, but there may be times that I create an interface to include in the project and then at various times add assemblies to a production folder, each with one or more classes that implement the interface, and use a config file that defines which assembly.class to load for a particular command without requiring me to have to recompile the main assembly.  For some reason, when the designer loads the referenced assembly it is using the working directory of where the Visual Studio IDE was launched from rather than internally using the debug directory as defined by the Build|Configuration command.  I basically have created a post build macro that will place a copy of my unreferenced dll into the directory that the designer expects it to be in.  This is a temporary solution cause I am thinking that this is a bug.

 
0
 
LVL 3

Accepted Solution

by:
Neun123 earned 1000 total points
ID: 36571047
This might sound strange, but we had some issues with SSIS paths in my current project. The fix was to change the "Start in:" value of the shortcut we used to run VS. (Right-click on the icon -> Properties -> Shortcut Tab)

You could create a new shortcut to try it out. (Have a look and see if the current shortcut's "start in" points to the path where it is looking for the assembly)
0
 

Author Comment

by:modotx
ID: 36583093
That will probably work, though not an ideal solution.  

However, a combination of creating a dedicated directory for non-referenced DLLs, creating post build macros to copy the dll there and to the associated build directory and creating a dedicated shortcut icon to launch VS using the dedicated directory as it's "Start In:" directory.

Personally, I think MS should fix this by internally changing the startup directory for the designer to being the directory defined by the Build Configuration.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Six Sigma Control Plans

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question