Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0

1

I've got error assembly when publishing to production

so far I've tried to:

  1. clean bin and obj
  2. rebuild solution
  3. manually add Microsoft.VisualStudio.Diagnostics.PerformanceProvider library
  4. set application pool to enable 32 bit aplication
  5. Intall visual studio on production server

    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.

c#
asp.net
asp.net-mvc
iis
automapper
asked on Stack Overflow Jun 7, 2018 by Wildan Muhlis

3 Answers

0

Solution 1:

Uninstall and re-install Visual studio

Solution 2:

Just remove the reference to this assembly from web.config files in framework directories.

Solution 3:

Open Visual studio with admin rights

answered on Stack Overflow Jun 7, 2018 by Prany
0

I encountered the same issue. I think it has something to do with dynamic assembly loading or DI (e.g. AutoMapper). In my case we ended up having a build machine (without VS installed) doing the build output and that worked.

answered on Stack Overflow Sep 10, 2019 by misha
0

following should unblock...

        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;
        }
answered on Stack Overflow Nov 16, 2019 by Abin

User contributions licensed under CC BY-SA 3.0