[Runtime Version v2.0.50727]
Question regarding Assembly.LoadFrom(http).
This really is URGENT; thank you for your time.
Hello,
I have three projects: X, Y and Z.
Project X is a class library-type project full of user controls that other developers monkey with; these controls obey a set interfaces we have defined in project Z.
Project Y is a winforms-type project. It does not contain a reference to Project X, but it does contain a reference to project Z - just like project X does.
Project Y loads Project X dynamically from a HTTP using the following code:
/// * start sample
string _Url;
_Url = "http://localhost/projects/ProjectX.dll";
System.Reflection.Assembly _ProjectX;
_ProjectX = System.Reflection.Assembly.LoadFrom(_Url)
/// * end sample
This works fine. In debugger, the properties of the assembly appear correct. Then we fetch a certain class by it's FullName using the following code:
/// * start sample
string _FormName;
_FormName = "MyNameSpace.MyClassName";
System.Runtime.Remoting.ObjectHandle _ObjectHandle;
_ObjectHandle = System.Activator.CreateInstance(
_Assembly.GetName().ToString(), _FormName);
Object _Object;
_Object = _ObjectHandle.Unwrap() as object;
Z.ICustomForm _ICustomForm;
_ICustomForm = (_Object as Z.ICustomForm);
/// * end sample
This works perfectly, but ONLY when Project X is contained as a reference to Project Y and, of course, then included in the Project Y bin folder. And since we had a design goal to allow Project X to change often while project Y would almost never be changed/rebuilt, I was forced to remove the reference of Project X from project Y because loading Project X resulted in the exception (the located assembly's manifest definition does not match the assembly reference). Which I interpreted as a conflict with the local reference. Maybe I was wrong, I do not know.
Anyway, when Project X is _not_ referenced in Project Y, calling the above code (specfically, the System.Activator.CreateInstance() part) results in the following exception:
/// * start exception detail
TYPE
System.IO.FileNotFoundException
MESSAGE
"Could not load file or assembly 'ProjectX, Version=1.0.2594.26944, Culture=neutral, PublicKeyToken=41b1be53bdfc59e4' or one of its dependencies. The system cannot find the file specified."
FUSION LOG
=== Pre-bind state information ===
LOG: User = <mydomain>\<myusername>
LOG: DisplayName = ProjectX, Version=1.0.2594.26944, Culture=neutral, PublicKeyToken=41b1be53bdfc59e4
(Fully-specified)
LOG: Appbase = file:///C:/<project path>/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : ProjectY, Version=2.0.0.3, Culture=neutral, PublicKeyToken=41b1be53bdfc59e4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\<project path>\bin\Debug\ProjectY.vshost.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: ProjectX, Version=1.0.2594.26944, Culture=neutral, PublicKeyToken=41b1be53bdfc59e4
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
INNER EXCEPTION
null
/// * end exception detail
Honestly, I am stumpted.
So far I have:
1. Are the references for Project X in the same http folder
(yes, I checked)
2. Are the file types allowed by IIS
(yes, I checked)
3. Are all references pulled down with the ProjectX.dll
(no, they do not appear in the temp folder)
4. Can I manually download references
(I don't know, could not find mechanism)
5. Can I tell the assembly to go get its references
(I don't know, could not see how)
6. Do other people have the same issue
(I don't know, don't see where)
7. Can I compile references into a single dll
(I don't know, don't know how)
8. Must Project X be a local reference in Project Y
(I do not know, no documentation specifically on that)
It is important to remember that this DOES work when Project X is a local reference project Y. This means the assembly and its content load fine and that the CreateInstance code works correctly. But this is not acceptable. We need to load this remotely where other develoeprs can post new versions of project X at any given time and Project y will fetch the latest version across HTTP from a known URL.
Does anyone have any suggestions
Thanks, Jerry

URGENT Assembly.LoadFrom(http) == "Could not load file or assembly 'X' ... or one of its dependencies."
QuestionToBeAnswered
Hey Jerry,
You say you don't want to reference the dll directly in Project Y, but is there a problem placing a copy of the latest dll in the executable directory for the application The easiest solution would be to make part of the build of Project X to copy the built dll into the root directory of the test harness. It doesn't need to be referenced by Project Y, it merely needs to be in the same directory as the calling application.
There are alternatives, but I myself am just getting into the finer details of calling a dll through reflection that references another dll... (easy just isn't fun.)
Hope this helps.
Greg
Gluber2006
I couldn't seem to re-create the problem using a quick test project and w/ Cassini for my web server.
However, from a ClickOnce standpoint, you could always use the ClickOnce Community Resource Kit's manifest tool to modify to deployment and add assembly X and the files needed by assembly X into the application manifest. This will allow you to add assembly X and it's dependencies to the deployment without having to directly add them as references in your main application's project. The assembly X files would be downloaded along with the rest of the deployment and available for your main application to consume.
Hope this helps at least some...
AndyJ_PS
Two reasons this is not a good solution:
1. This is a ClickOnce deployment so the bin is not as simple (and static) a thing to muck with.
2. The remote assembly can use resource assemblies that are not anticiapted at the time of the ClickOnce deploy.
Thanks. I have a feeling there is NO answer to my question.