बिन निर्देशिका प्राप्त करने के लिए, string path = Assembly.GetExecutingAssembly().Location;
नहीं हमेशा काम करता है (विशेष रूप से जब निष्पादन असेंबली को एएसपी.NET अस्थायी निर्देशिका में रखा गया है)।
इसके बजाय, आप string binPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");
का उपयोग इसके अलावा, आप शायद FileLoadException और BadImageFormatException ध्यान में रखना चाहिए चाहिए।
यहाँ मेरे कार्य समारोह है:
public static void LoadAllBinDirectoryAssemblies()
{
string binPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin"); // note: don't use CurrentEntryAssembly or anything like that.
foreach (string dll in Directory.GetFiles(binPath, "*.dll", SearchOption.AllDirectories))
{
try
{
Assembly loadedAssembly = Assembly.LoadFile(dll);
}
catch (FileLoadException loadEx)
{ } // The Assembly has already been loaded.
catch (BadImageFormatException imgEx)
{ } // If a BadImageFormatException exception is thrown, the file is not an assembly.
} // foreach dll
}
स्रोत
2011-04-08 18:56:34
आप शायद यह भी चाहता हूँ यह सुनिश्चित करने के लिए एक चेक जोड़ने के लिए कि आप असेंबली को वास्तव में नहीं चला रहे हैं :) – Wolfwyrd
'पथ' चर में निर्देशिका फ़ाइल नाम शामिल है, इसे' Path.GetDirectoryName (पथ) ' – cjk
के साथ छोटा करने की आवश्यकता है उपरोक्त टिप्पणी को दर्शाने के लिए अद्यतन किया गया है। –