Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-15
6
Medium Priority
?
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

660 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