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

时间:2013-11-29 02:46:24

标签: c# asp.net

我正在尝试创建一个可以浏览文件夹的网页。我已经在单独的解决方案中完成了这一切并且一切正常,但是当我尝试将它集成到解决方案中时,多个项目也引用了PostSharp我得到了这个错误:

 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].

2 个答案:

答案 0 :(得分:0)

SharpSVN程序集可能无法加载,因为它引用了一些本机DLL(32位版本的SharpSvn-DB44-20-win32.dllSharpSvn-Sasl21-23-win32.dll)。如果那些不在系统搜索路径中的某个位置 - 这通常是ASP.NET的情况 - 那么SharpSVN可能无法加载。

我有一个similar problem我的一个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分发中复制它们。

当然,我可能完全不合适。让我知道。

答案 1 :(得分:0)

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

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

client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers + = new EventHandler(SVN_SSL_Override); client.Authentication.DefaultCredentials = new NetworkCredential(" "," ");

和这个方法

static void SVN_SSL_Override(object sender,SharpSvn.Security.SvnSslServerTrustEventArgs e){e.AcceptedFailures = e.Failures; e.Save = true; }"

刚刚补充道:

client.Authentication.UserNamePasswordHandlers + = delegate(object obj,SharpSvn.Security.SvnUserNamePasswordEventArgs args)             {                 args.UserName =" &#34 ;;                 args.Password =" &#34 ;;                 args.Save = true;             };

现在可行。