ditkis
asked on
Using DLL's on client machine
Hello!
My project consists of several DLL's. Among other I have xDLL.dll which has a reference to xObjects.dll. When compiling the project, xDll.dll and all dependensies are copying to bin folder of the project. It is known that on every machine (user machine) that this application will be used, all those files are located in c:\\Program Files\X\x.Objects.dll
My question: how can I use files located on users machines instead of those which are copying while compiling?
I've tried:
Copy Local = false for xObjects.dll
And have created the file:
<?xml version ="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microso ft-com:asm .v1">
<dependentAssembly>
<assemblyIdentity name="xObjects" culture="" publicKeyToken=""/>
<codeBase version="" href="file:///C:/Program Files/X/xObjects.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
-------------------------- -
Please help!
Thanks!
My project consists of several DLL's. Among other I have xDLL.dll which has a reference to xObjects.dll. When compiling the project, xDll.dll and all dependensies are copying to bin folder of the project. It is known that on every machine (user machine) that this application will be used, all those files are located in c:\\Program Files\X\x.Objects.dll
My question: how can I use files located on users machines instead of those which are copying while compiling?
I've tried:
Copy Local = false for xObjects.dll
And have created the file:
<?xml version ="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microso
<dependentAssembly>
<assemblyIdentity name="xObjects" culture="" publicKeyToken=""/>
<codeBase version="" href="file:///C:/Program Files/X/xObjects.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
--------------------------
Please help!
Thanks!
ASKER
assembly i wish to use is strongly named
Then I would install it into the GAC on the users' machines.
Use the command:
gacutil /i C:/Program Files/X/xObjects.dll
Use the command:
gacutil /i C:/Program Files/X/xObjects.dll
ASKER
I can not register assembly in GAC. I know there is another way to do it.
Try to supply the public key token in the assemblyIdentity node.
I think that if you set the version in your AssemblyInfo.cs should be enogh
[assembly: AssemblyVersion("1.0.0.7") ]
instead of
[assembly: AssemblyVersion("1.0.*")]
hope helps...
[assembly: AssemblyVersion("1.0.0.7")
instead of
[assembly: AssemblyVersion("1.0.*")]
hope helps...
Also set the culture if you set the culture in the assemblyinfo of the xObjects DLL
ASKER
I've tried to "Try to supply the public key token in the assemblyIdentity node." Didn't work.
The reason I want to use DLL's on user machine is because they are updating them regulary. I want to use any version they have, so I can not set the version. Is there anything else I can do to make it work?
The reason I want to use DLL's on user machine is because they are updating them regulary. I want to use any version they have, so I can not set the version. Is there anything else I can do to make it work?
try adding culture="neutral" if there is no culture specified in the assemblyinfo of the source dll
If you're still having trouble, try adding an event handler in your app to perhaps shed some more light on the cause:
{copied from http://support.microsoft.com/default.aspx?scid=kb;EN-US;837908}
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyReso lve += new ResolveEventHandler(MyReso lveEventHa ndler);
private Assembly MyResolveEventHandler(obje ct sender,ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly,objExecutingAss emblies;
string strTempAssmbPath="";
objExecutingAssemblies=Ass embly.GetE xecutingAs sembly();
AssemblyName [] arrReferencedAssmbNames=ob jExecuting Assemblies .GetRefere ncedAssemb lies();
//Loop through the array of referenced assembly names.
foreach(AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if(strAssmbName.FullName.S ubstring(0 , strAssmbName.FullName.Inde xOf(","))= =args.Name .Substring (0, args.Name.IndexOf(",")))
{
//Build the path of the assembly from where it has to be loaded.
strTempAssmbPath="C:\\Myas semblies\\ "+args.Nam e.Substrin g(0,args.N ame.IndexO f(","))+". dll";
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempA ssmbPath);
//Return the loaded assembly.
return MyAssembly;
}
{copied from http://support.microsoft.com/default.aspx?scid=kb;EN-US;837908}
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyReso
private Assembly MyResolveEventHandler(obje
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly,objExecutingAss
string strTempAssmbPath="";
objExecutingAssemblies=Ass
AssemblyName [] arrReferencedAssmbNames=ob
//Loop through the array of referenced assembly names.
foreach(AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if(strAssmbName.FullName.S
{
//Build the path of the assembly from where it has to be loaded.
strTempAssmbPath="C:\\Myas
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempA
//Return the loaded assembly.
return MyAssembly;
}
ASKER
I'm trying to use example from msdn but getting wierd error.
Studio underlines "+=" and "ResolveEventHandler" in "currentDomain.AssemblyRes olve += new ResolveEventHandler(MyReso lveEventHa ndler);" line. Does anybody know what's happening there?
Studio underlines "+=" and "ResolveEventHandler" in "currentDomain.AssemblyRes
Where are you adding the code? It should be in the entry point of your application (Main(), for example).
What compiler errors do you get?
What compiler errors do you get?
ASKER
TYpe or namespace name 'Assembly' could not be found...
ASKER
private Assembly MyResolveEventHandler(obje ct sender,ResolveEventArgs args)
add
using System.Reflection;
to the top of your code file.
using System.Reflection;
to the top of your code file.
ASKER
currentDomain.AssemblyReso lve += new ResolveEventHandler(MyReso lveEventHa ndler);
It still does not work, I got following error:
an object refence required for non static field, method or property .......... myresolveeventhadler....
It still does not work, I got following error:
an object refence required for non static field, method or property .......... myresolveeventhadler....
Are you defining the MyResolveEVentHandler as a method of the startup class as well?
ASKER
Yes, that's part of a code:
[STAThread]
static void Main()
{
Application.Run(new Form1());
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyReso lve += new ResolveEventHandler(MyReso lveEventHa ndler);
}
private Assembly MyResolveEventHandler(obje ct sender,ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly,objExecutingAss emblies;
string strTempAssmbPath="";
[STAThread]
static void Main()
{
Application.Run(new Form1());
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyReso
}
private Assembly MyResolveEventHandler(obje
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly,objExecutingAss
string strTempAssmbPath="";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use the <codeBase> element only in machine configuration or publisher policy files that also redirect the assembly version.
...
Note If you are supplying a code base hint for an assembly that is not strong-named, the hint must point to the application base or a subdirectory of the application base directory.
If you want to use the assembly from a location other than the app's location, I believe you have to use the GAC. This also means you need a strong name (using a public key) for the assembly. You can use GACUTIL to install the DLL into the GAC, and even create setup projects that will do this for you.