网站突发无法加载,报Cannot load a reference assembly for execution错误求助
Hey there, let’s work through this "Cannot load a reference assembly for execution" error you’re facing with your site on VS2017 and .NET Framework 4.7.1. Here are practical, tested fixes to resolve this issue:
Fix misconfigured assembly references
Sometimes assemblies get marked as "reference-only," which prevents them from being copied to the output directory at runtime.
Right-click your project → References → Find the problematic assembly → Right-click Properties → Make sure Copy Local is set toTrue, and uncheck Specific Version (unless you explicitly need a fixed version).Clean and rebuild your solution
Stale build cache often causes weird runtime issues:- Go to VS top menu → Build → Clean Solution
- Manually delete the
binandobjfolders from your project directory - Restart VS, then click Rebuild Solution
Repair .NET Framework 4.7.1 installation
A corrupted .NET installation might be the root cause:- Open Control Panel → Programs and Features → Find ".NET Framework 4.7.1" → Right-click Change → Select Repair
- If repair doesn’t work, uninstall it and download a fresh copy of .NET Framework 4.7.1 compatible with Windows 10 Home.
Verify project target framework
Double-check your project is actually targeting .NET 4.7.1:
Right-click your project → Properties → Application tab → Under Target framework, select.NET Framework 4.7.1, save changes, and rebuild.Check web.config assembly binding redirects (for web projects)
Incorrect binding redirects in web.config can block assembly loading. Open your web.config, locate the<runtime>→<assemblyBinding>section. Ensure the version redirects for your assemblies are correct, like this example:<dependentAssembly> <assemblyIdentity name="YourAssemblyName" publicKeyToken="your-token-here" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" /> </dependentAssembly>If you’re unsure, try commenting out suspicious redirects temporarily to test if the site loads.
Dig into detailed error logs
Open VS’s Output Window (View → Output), switch to the Build or Debug output stream. Look for specific assembly names that failed to load—this will help you target the exact issue faster.
内容的提问来源于stack exchange,提问作者Krunal

