Solved

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

Posted on 2011-09-15
6
317 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now