|
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
|
|
|
|
|
Then use a List or something. We tend not to use arrays in C#.
|
|
|
|
|
Actually, you do know what's wrong: you're using an unassigned local variable. It will even tell you that strPLatitude is the culprit.
How to fix? Assign something to it, obviously. Most C# compile errors are easy like that.
You wanted a null array? Then make a null array: double[] strPLatitude = null;
That doesn't make the code work, I grant you, but it fixes this problem.
However, this:
tashee wrote: declared a null array but when i try to use this array to store my values Reveals a deeper problem. You can't use something that doesn't exist. Like Richard wrote, "You must allocate some space to it before you can store anything in it". Your reply to him seems to imply you didn't really get it.
This is like saying "I have a place where a bookshelf should go but there isn't one there yet, why do things go wrong when I try to store books in it?"
Don't use something that doesn't exist. You need an actual bookshelf, not just a place where a bookshelf could go.
PIEBALDconsult suggest you use a List, you should probably do that. Be sure to Add[^] the items to the list, don't try to stuff them into positions that do not exist.
|
|
|
|
|
Hello,
Im doing a big final project that manages a dive shop.
This application will have data base.
What im looking for is some example of solution that works with data base(connect to DB , SQL , Query) that i can take and modify it for my needs.
Thanks.
|
|
|
|
|
I can offer you some insight into creating a Data Access Layer.
DatabaseAccessor[^]
There are many similar articles on here.
|
|
|
|
|
I understand that article is from 2007, but I'd completely disregard it. It was completely bad practice even "back then". Definitely is horrible practice today. Use a proper data access layer like EF, nHibernate, etc. At the very least, if you use barebones ADO.NET, you should not write queries in the C# code like that. Completely vulnerable to a script kiddie who knows SQL injection.
|
|
|
|