Solved

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

Posted on 2011-09-15
6
316 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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 …
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now