|
Your application, let us call in it MyApp.exe will live in the following directly.
C:\program files\MyCompany
The dependent dlls will live in the same directory.
|
|
|
|
|
Lets us take an eg., I have MyApp.exe, Test1.dll,Test2.dll,Test3.dll.
MyApp.exe depends/uses Test1.dll
Test1.dll depends/uses Test2.dll, Test3.dll
If i am installing all binaries to same directory say D:\TestAppln\ then my application will work perfectly.
But due to some issues i need to move Test1.dll to programfiles sub-directory always(e.g, C:\program files\MyCompany) irrespective of installation. My application may reside in any directory.
Since Test1.dll depends on Test2.dll and Test3.dll, i need to copy them from application folder to Test1.dll's folder i'e (e.g, C:\program files\MyCompany). Otherwise Test1.dll will not load.
So my question is how to make Test1.dll to refer its dependant dll from application folder.
I am looking for options other than GAC.
|
|
|
|
|
You can load the dlls dynamically.
Also the AppDomain has an option that allows you to specify a search path.
Creating an AppDomain yourself is one option. However I believe it is also possible to set that in the application itself perhaps via one of the properties.
|
|
|
|
|
Your question is pretty unclear. In a normal .net application you add references to .net assembly. So it has to exist in a location known to the application. If you don't wish to do this you can go the MEF (Managed Extensibility Framework) way. Have a look at these links - MEF in .Net[^]
Cheers,
Karthik
|
|
|
|
|
I am not sure whether i have confused.
Lets put that again, during deployment of my application i need install a particular dll to program files sub directory (eg. C:\program files\test). But my application will be in different directory. Since the dll Installed away from application directory and it uses/references many dlls present in application directory. How do i make that dll to pick dependent dlls from application directory. I dont want to move to GAC. Hope its clear.
|
|
|
|
|
Yes this is possible, for strongly named assemblies, with an addition to the configuration section of the application's configuration file ( appname.exe.config ).
In this example we have an assembly StealthLib.dll which has been moved out of the applications's base directory to v:\Temp . Information about this new location is given in the dependentAssembly element where we must specify the assemblyIdentity and the codeBase .
="1.0"="utf-8"
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="StealthLib" publicKeyToken="e0505f3b3553d5af"/>
<codeBase version="1.0.0.0" href="file://v:/Temp/StealthLib.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Be really careful when editing the configuration file as errors are silently ignored. For example the assembly will not be found if the casing of publicKeyToken is changed to PublicKeyToken.
The Assembly Binding Log Viewer (FUSLOGVW.exe) which comes with the .NET SDK is very useful for resolving assembly loading problems as it will log all the locations that have been searched for dependent assemblies.
LOG: Appbase = file:LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MainProg.exe
Calling assembly : MainProg, Version=1.0.4743.26012, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\VC\Projects\CP\AssemblyProbing\MainProg\bin\Debug\MainProg.exe.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:LOG: Assembly download was successful. Attempting setup of file: v:\Temp\StealthLib.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
LOG: Binding succeeds. Returns assembly from v:\Temp\StealthLib.dll.
LOG: Assembly is loaded in default load context.
Good luck
Alan.
|
|
|
|
|
Oh really great!. your input much appreciated. I have another question, Can we use the configfile for a dll to locate its dependent assembly? Or its only applicable for exe?
|
|
|
|
|
That's an interesting question that I don't know the answer to. Why not try it out? I may look at it tomorrow and if I do I'll post another reply.
Alan.
|
|
|
|
|
Did you get any update on this?
|
|
|
|
|
If you have say App.exe -> DllA -> DllB, i.e. DllA uses DllB and App does not directly reference DllB. If DllA and DllB have been moved out of the application base directory then App.exe.config must be edited to provide separate location information for both DllA and DllB and there is no assumption that DllB now resides in the same place as DllA.
Think of it like this: There is one process and the code in DllA executes in the context of that process. When code in DllA needs to call code residing in DllB then that assembly is loaded by 'the process' whose default locations are the GAC and the application base directory. Overrides to this default behaviour are on a per assembly basis.
Any information contained within *.dll.config is not read automatically and will be ignored.
Alan.
modified 2-Jan-13 17:27pm.
|
|
|
|
|
Thanks for the update. Immm... Need to find a way.
|
|
|
|
|
KASR1 wrote: i shound not put many assembly in GAC
Why not?
|
|
|
|
|
Even i am concerned about that, but i was asked to find other possible options to make the dll to refer its dependent dlls. I am interested to know whether it can be achieved via config file.
|
|
|
|
|
Hi, I want to get the latitude and longitude for a given address using google apis. Is it possible to do this in the windows based application?If possible how to do this?
|
|
|
|
|
I haven't used it before but here is a link [^] To the api.
Frazzle the name say's it all
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John F. Woods
|
|
|
|
|
I think google earth api can be used in .NET applications.You have to embed the required javascript functions in the HTML behind
a webBrowser object and then call the functions using the
webBrowser.Document.InvokeScript method.
|
|
|
|
|
Hi
I am in the process of developing a cloud backup software. The application is a desktop application developed using C#.
I need to add an option to stop/pause the backup if the computer was connected to a 3G network to save cost for the user.
I cannot seem to be able to find any example on how this can be achieved, there are some examples for Windows Phone and Windows Store Apps but I cannot find anything that can check if the connection type is a WiFi/Ethernet or 3G the latter is my main concern.
I tried a test application to enumerate the networks:
Console.WriteLine("checking network interfaces\n");
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var networkInterface in interfaces)
{
Console.WriteLine("Interface Detected");
Console.WriteLine("Description: "+networkInterface.Description);
Console.WriteLine("ID: " + networkInterface.Id);
Console.WriteLine("Name: " + networkInterface.Name);
Console.WriteLine("Interface Type: " + networkInterface.NetworkInterfaceType);
Console.WriteLine("Operational Status: " + networkInterface.OperationalStatus.ToString());
Console.WriteLine("Speed: " + networkInterface.Speed.ToString());
Console.WriteLine("Supports Multicast: " + networkInterface.SupportsMulticast.ToString());
Console.WriteLine("#########################################################\n");
}
The above code list my 3G connection as PPP which can be either ADSL or 3G. I am not sure if I can differentiate using some other options or APIs
I need a clear way to distinguish between those networks and so far I cannot find a way of doing so.
Can someone please help?
modified 24-Dec-12 7:12am.
|
|
|
|
|
|
Thats for Windows Phone, sadly the solution does not work with desktop applications.
|
|
|
|
|
Good morning,
I have a problem with the code below....when I receive answer from my clients, if they are connected, ping class answer twice. The problem is that I have to put the answers in a richtextbox I would avoid to see some double entry !
Thanks in advance !!
foreach (string PC in primaColonnaPc)
{
try
{
Ping x = new Ping();
PingReply reply = x.Send(PC);
if (reply.Status == IPStatus.Success)
{
valore = PC + " OK\r";
f2.riceviDati = valore;
}
else
valore =("ATTENZIONE: " + PC + "ERROR\r");
f2.riceviDati = valore;
}
catch (Exception)
{
valore =("ATTENZIONE:" + PC + ": WS not found\r");
f2.riceviDati = valore;
}
|
|
|
|
|
i am creating an asp.net application in which i have UploadImage.aspx page and user control
how would i create an object of Partial class UploadImage.cs in usercontrol.cs
Thanks for any help you might be able to provide with this problem,
|
|
|
|
|
Hi
Write the below in usercontrol
UploadImage objname = new UploadImage()
Regards
Naina
Naina
|
|
|
|
|
Hello,
I have declared a null array but when i try to use this array to store my values, it gives me an error as "use of unassigned local variable".
I donno whats wrong.
here is my code
double[] strPLatitude;
if (dr.HasRows)
{
while (dr.Read())
{
strPLatitude[i] = Convert.ToDouble(dr["latitude"].ToString());
i++;
}
}
|
|
|
|
|
You must allocate some space to it before you can store anything in it. Something like:
if (dr.HasRows)
{
strPLatitude = new double[N];
while (dr.Read())
{
You are also incrementing the variable i ; are you sure you initialised it somewhere?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes i have initialized variable i
And data in my database table would increase with time. hence it's not possible to allocate a space to the array, since i don't know how much records exist in my table
|
|
|
|