【问题标题】:Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0无法加载文件或程序集“Microsoft.VisualStudio.Diagnostics.PerformanceProvider,版本=14.0.0.0
【发布时间】:2018-06-07 04:12:48
【问题描述】:

发布到生产环境时出现错误组装

到目前为止,我已经尝试过:

  1. 干净的binobj
  2. 重建解决方案
  3. 手动添加Microsoft.VisualStudio.Diagnostics.PerformanceProvider
  4. 设置应用程序池以启用 32 位应用程序
  5. 在生产服务器上安装 Visual Studio

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using AutoMapper;

    public class AutoMapperConfig
    {
        public static MapperConfiguration Configuration { get; private set; }

        public static void Init()
        {

            try
            {
                //   The code that causes the error goes here.
                var types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes().Where(t => t.GetInterfaces().Any(IsMapperConfigInterface)))
                .ToArray();

            Execute(types);
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();

                throw new Exception(errorMessage);
                //Display or log the error based on your application.
            }

        }

        private static bool IsMapperConfigInterface(Type type)
        {
            var isGenericMapping = type.IsGenericType &&
                         (type.GetGenericTypeDefinition() == typeof(IMapFrom<>) || type.GetGenericTypeDefinition() == typeof(IMapTo<>));

            var isCustomMapping = typeof(IHaveCustomMappings).IsAssignableFrom(type);

            return isGenericMapping || isCustomMapping;
        }

        private static void Execute(Type[] types)
        {
            Configuration = new MapperConfiguration(
                cfg =>
                {
                    LoadStandardMappings(types, cfg);
                    LoadReverseMappings(types, cfg);
                    LoadCustomMappings(types, cfg);
                });
        }

        private static void LoadStandardMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>) &&
                              !t.IsAbstract &&
                              !t.IsInterface
                        select new
                        {
                            Source = i.GetGenericArguments()[0],
                            Destination = t
                        }).ToArray();

            foreach (var map in maps)
            {
                mapperConfiguration.CreateMap(map.Source, map.Destination);
            }
        }

        private static void LoadReverseMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapTo<>) &&
                              !t.IsAbstract &&
                              !t.IsInterface
                        select new
                        {
                            Destination = i.GetGenericArguments()[0],
                            Source = t
                        }).ToArray();

            foreach (var map in maps)
            {
                mapperConfiguration.CreateMap(map.Source, map.Destination);
            }
        }

        private static void LoadCustomMappings(IEnumerable<Type> types, IMapperConfiguration mapperConfiguration)
        {
            var maps = (from t in types
                        from i in t.GetInterfaces()
                        where typeof(IHaveCustomMappings).IsAssignableFrom(t) &&
                              !t.IsAbstract &&
                              !t.IsInterface &&
                              t.GetConstructor(Type.EmptyTypes) != null
                        select (IHaveCustomMappings)Activator.CreateInstance(t)).ToArray();

            foreach (var map in maps)
            {
                map.CreateMappings(mapperConfiguration);
            }
        }
    }

Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Fusion Log:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/QHSSEOT/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\QHSSEOT\bin
Calling assembly : Microsoft.VisualStudio.GraphModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\QHSSEOT\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/848a2c79/7b606a28/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/848a2c79/7b606a28/Microsoft.VisualStudio.Diagnostics.PerformanceProvider/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/QHSSEOT/bin/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/QHSSEOT/bin/Microsoft.VisualStudio.Diagnostics.PerformanceProvider/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/848a2c79/7b606a28/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/848a2c79/7b606a28/Microsoft.VisualStudio.Diagnostics.PerformanceProvider/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/QHSSEOT/bin/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/QHSSEOT/bin/Microsoft.VisualStudio.Diagnostics.PerformanceProvider/Microsoft.VisualStudio.Diagnostics.PerformanceProvider.EXE.


Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Fusion Log:
=== Pre-bind state information ===
LOG: DisplayName = Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/QHSSEOT/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\QHSSEOT\bin
Calling assembly : Microsoft.VisualStudio.GraphModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\QHSSEOT\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

【问题讨论】:

  • 我想我过去曾遇到过这种问题。我通过再次卸载并安装 Visual Studio 来修复。如果可行,你可以试试这个
  • @Prany 在哪里重新安装?在开发设备或服务器上?
  • 在开发设备上
  • bin 文件夹是否应该有对应的.dll?有dll吗?
  • @AD8,不,Microsoft.VisualStudio.Diagnostics.PerformanceProvider 不应该存在于二进制文件夹中,我们不会在引用中添加它。但在发布项目时会自动引用。

标签: c# asp.net asp.net-mvc iis automapper


【解决方案1】:

解决方案 1:

卸载并重新安装 Visual Studio

解决方案 2:

只需从框架目录中的 web.config 文件中删除对该程序集的引用即可。

解决方案 3:

以管理员权限打开 Visual Studio

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。我认为这与动态程序集加载或 DI(例如 AutoMapper)有关。 在我的例子中,我们最终有一台构建机器(没有安装 VS)来执行构建输出并且工作正常。

    【讨论】:

      【解决方案3】:

      以下应该取消阻止...

              AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolveEventHandler;
              AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveEventHandler;
      
      
              private static readonly ResolveEventHandler AssemblyResolveEventHandler = (sender, resolveEventArgs) =>
              {
                  var assemblyName = GetAssemblyName(resolveEventArgs.Name);
                  var assemblyDllPath3 = Path.Combine(@"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PrivateAssemblies", $"{assemblyName}.dll");
                  var assembly = (File.Exists(assemblyDllPath3) ? Assembly.LoadFrom(assemblyDllPath3) : null);
                  return assembly;
              };
      
              internal static string GetAssemblyName(string fullAssemblyName)
              {
                  const string AssemblyNamePattern = "^([^,]+)([,].+)*$";
                  return Regex.Match(fullAssemblyName, AssemblyNamePattern).Groups[1].Value;
              }
      

      【讨论】:

        【解决方案4】:

        在将我的项目从 VS-2013 迁移到 VS-2019 时,我在服务器中遇到了同样的问题。我已通过将程序集复制到 GAC_MSIL(C:\Windows\Microsoft.NET\assembly\GAC_MSIL) 文件夹来纠正它。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-01-22
          • 2011-07-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-12-31
          • 2017-10-15
          相关资源
          最近更新 更多