System.IO.FileNotFoundException:未能加载文件或程序集.系统找不到SharpSvn.dll

本文关键字:程序集 系统 找不到 dll SharpSvn 文件 加载 FileNotFoundException IO System | 更新日期: 2024-05-25 12:18:37

我正在尝试创建一个可以浏览文件夹的网页。我在单独的解决方案中做到了这一点,一切都很好,但当我试图将其与多个项目集成在解决方案中时,我得到了这个错误:

 Unhandled exception (2.1.7.1, 32 bit, CLR 4.0, Release): System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:'_projects'...'Libraries'SharpSvn'SharpSvn.dll' or one of its dependencies. The system cannot find the file specified.
    File name: 'file:///C:'_projects'...'Libraries'SharpSvn'SharpSvn.dll'
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
       at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
       at PostSharp.Sdk.CodeModel.ModuleDeclaration.GetSystemModule()
       at PostSharp.Sdk.CodeModel.Domain.LoadAssembly(Assembly reflectionAssembly, Boolean lazyLoading)
       at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions)
       at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.GetAssemblyEnvelope()
       at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.^SgrhoGlQ(AssemblyRefDeclaration _0)
       at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.^+GwnKh4ZYHu3()
       at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.Execute()
       at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
       at PostSharp.Sdk.Extensibility.Project.Execute()
       at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
       at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation)
    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value         [HKLM'Software'Microsoft'Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM'Software'Microsoft'Fusion!EnableLog].

System.IO.FileNotFoundException:未能加载文件或程序集.系统找不到SharpSvn.dll

SharpSVN程序集可能由于引用了两个本机DLL(对于32位版本,SharpSvn-DB44-20-win32.dllSharpSvn-Sasl21-23-win32.dll)而无法加载。如果这些不在系统搜索路径中(ASP.NET通常是这样),那么SharpSVN可能无法加载。

我有一个类似的问题,我的一个NuGet包不能在MVC网站上工作,因为本地DLL没有加载。将它们放在网站的bin文件夹中是不够的,因为bin文件夹既不在搜索路径上,也不是应用程序文件夹。

尝试将以下方法添加到Global.asax.cs文件中的应用程序类中,并从Application_Start():调用它

public static void CheckAddBinPath()
{
    // find path to 'bin' folder
    var binPath = Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "bin" });
    // get current search path from environment
    var path = Environment.GetEnvironmentVariable("PATH") ?? "";
    // add 'bin' folder to search path if not already present
    if (!path.Split(Path.PathSeparator).Contains(binPath, StringComparer.CurrentCultureIgnoreCase))
    {
        path = string.Join(Path.PathSeparator.ToString(), new string[] { path, binPath });
        Environment.SetEnvironmentVariable("PATH", path);
    }
}

这将只将您的bin文件夹添加到应用程序的系统搜索路径中,这将允许SharpSvn定位它所依赖的本机DLL。只需确保文件确实在那里-如果没有,您可能必须从SharpSvn分发版复制它们。

当然,我可能完全偏离了目标。不管怎样都让我知道。

我写道:"当我评论这个方法时,错误就消失了:static void SVN_SSL_Override(object sender,SharpSvn.Security.SvnSslServerTrustEventArgs e){e.AcceptedFailures=e.Failures;e.Save=true;}"

不知道为什么,但有问题,所以我删除了:

client.Authentication.Clear();客户Authentication.SslServerTrustHandlers+=新的事件处理程序(SVN_SSL_Override);客户Authentication.DefaultCredentials=新的NetworkCredential("","");

和这种方法

static void SVN_SSL_Override(对象发送方,SharpSvn.Security.SvnSslServerTrustEventArgs e){e.AcceptedFailures=e.Failures;e.Save=true;}"

刚刚添加:

client.Authentication.UserNamePasswordHandlers+=委托(对象obj,SharpSvn.Security.SvnUserNamePasswordEventArgs参数){args。用户名="";args。密码="";args。Save=true;};

现在它起作用了。