Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

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

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
modotx
Asked:
modotx
  • 3
  • 2
1 Solution
 
strickddCommented:
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
 
Neun123Commented:
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
 
modotxAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
modotxAuthor Commented:
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
 
Neun123Commented:
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
 
modotxAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now