-1

I implemented a code in ASP.NET core webapp using MVC. After closing Microsoft Visual Studio, when I start my project again it shows the following error when I run it again. Although previously before closing Microsoft Visual Studio it was working fine.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Photo of the error

Warning:

Severity    Code    Description Project File    Line    Suppression State
Warning MSB3106 Assembly strong name "C:\Users\Anirudh\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.1.9\lib\netstandard2.0\Microsoft.VisualStudio.Web.CodeGenerators.Mvc.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\). C:\Users\Anirudh\source\repos\MvcMovie\MvcMovie\MvcMovie.csproj C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets   2110    

After Clicking on warning It is taking me to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

<ResolveAssemblyReference
        Assemblies="@(Reference)"
        AssemblyFiles="@(_ResolvedProjectReferencePaths);@(_ExplicitReference)"
        TargetFrameworkDirectories="@(_ReferenceInstalledAssemblyDirectory)"
        InstalledAssemblyTables="@(InstalledAssemblyTables);@(RedistList)"
        IgnoreDefaultInstalledAssemblyTables="$(IgnoreDefaultInstalledAssemblyTables)"
        IgnoreDefaultInstalledAssemblySubsetTables="$(IgnoreInstalledAssemblySubsetTables)"
        CandidateAssemblyFiles="@(Content);@(None)"
        SearchPaths="$(AssemblySearchPaths)"
        AllowedAssemblyExtensions="$(AllowedReferenceAssemblyFileExtensions)"
        AllowedRelatedFileExtensions="$(AllowedReferenceRelatedFileExtensions)"
        TargetProcessorArchitecture="$(ProcessorArchitecture)"
        AppConfigFile="@(_ResolveAssemblyReferencesApplicationConfigFileForExes)"
        AutoUnify="$(AutoUnifyAssemblyReferences)"
        SupportsBindingRedirectGeneration="$(GenerateBindingRedirectsOutputType)"
        IgnoreVersionForFrameworkReferences="$(IgnoreVersionForFrameworkReferences)"
        FindDependencies="$(_FindDependencies)"
        FindSatellites="$(BuildingProject)"
        FindSerializationAssemblies="$(BuildingProject)"
        FindRelatedFiles="$(BuildingProject)"
        Silent="$(ResolveAssemblyReferencesSilent)"
        TargetFrameworkVersion="$(TargetFrameworkVersion)"
        TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
        TargetFrameworkMonikerDisplayName="$(TargetFrameworkMonikerDisplayName)"
        TargetedRuntimeVersion="$(TargetedRuntimeVersion)"
        StateFile="$(ResolveAssemblyReferencesStateFile)"
        InstalledAssemblySubsetTables="@(InstalledAssemblySubsetTables)"
        TargetFrameworkSubsets="@(_ReferenceInstalledAssemblySubsets)"
        FullTargetFrameworkSubsetNames="$(FullReferenceAssemblyNames)"
        FullFrameworkFolders="$(_FullFrameworkReferenceAssemblyPaths)"
        FullFrameworkAssemblyTables="@(FullFrameworkAssemblyTables)"
        ProfileName="$(TargetFrameworkProfile)"
        LatestTargetFrameworkDirectories="@(LatestTargetFrameworkDirectories)"
        CopyLocalDependenciesWhenParentReferenceInGac="$(CopyLocalDependenciesWhenParentReferenceInGac)"
        DoNotCopyLocalIfInGac="$(DoNotCopyLocalIfInGac)"
        ResolvedSDKReferences="@(ResolvedSDKReference)"
        WarnOrErrorOnTargetArchitectureMismatch="$(ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch)"
        IgnoreTargetFrameworkAttributeVersionMismatch ="$(ResolveAssemblyReferenceIgnoreTargetFrameworkAttributeVersionMismatch)"
        FindDependenciesOfExternallyResolvedReferences="$(FindDependenciesOfExternallyResolvedReferences)"
        ContinueOnError="$(ContinueOnError)"
        Condition="'@(Reference)'!='' or '@(_ResolvedProjectReferencePaths)'!='' or '@(_ExplicitReference)' != ''"
        >

      <Output TaskParameter="ResolvedFiles" ItemName="ReferencePath"/>
      <Output TaskParameter="ResolvedFiles" ItemName="_ResolveAssemblyReferenceResolvedFiles"/>
      <Output TaskParameter="ResolvedDependencyFiles" ItemName="ReferenceDependencyPaths"/>
      <Output TaskParameter="RelatedFiles" ItemName="_ReferenceRelatedPaths"/>
      <Output TaskParameter="SatelliteFiles" ItemName="ReferenceSatellitePaths"/>
      <Output TaskParameter="SerializationAssemblyFiles" ItemName="_ReferenceSerializationAssemblyPaths"/>
      <Output TaskParameter="ScatterFiles" ItemName="_ReferenceScatterPaths"/>
      <Output TaskParameter="CopyLocalFiles" ItemName="ReferenceCopyLocalPaths"/>
      <Output TaskParameter="SuggestedRedirects" ItemName="SuggestedBindingRedirects"/>
      <Output TaskParameter="FilesWritten" ItemName="FileWrites"/>
      <Output TaskParameter="DependsOnSystemRuntime" PropertyName="DependsOnSystemRuntime"/>
      <Output TaskParameter="DependsOnNETStandard" PropertyName="_DependsOnNETStandard"/>
    </ResolveAssemblyReference>

Noobie
  • 3
  • 4
  • Have you seen [Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies](https://stackoverflow.com/questions/42755274/visual-studio-2017-could-not-load-file-or-assembly-system-runtime-version-4/42755305)? – Andrew Morton Mar 13 '21 at 11:09
  • I'm new to it and I didn't get how to fix it. – Noobie Mar 13 '21 at 11:46
  • Where I can find app.config and package.config? – Noobie Mar 13 '21 at 12:03
  • The easiest way would be to search for files with those names in the solution directory (and its sub-directories) - it's packages.config with an s in case you typo it. As it looks like you're using .NET Core 2.1, I'm not sure that it will actually have those files, in which case you could search in the files for the text "System.Runtime, Version=4.2.1.0" and use your judgement to work out which one it originates in. – Andrew Morton Mar 13 '21 at 14:27
  • Does Nuget Package Manager give you an option to update packages that happens to include System.Runtime? – Andrew Morton Mar 13 '21 at 14:28
  • No I haven't received any option to update packages. – Noobie Mar 13 '21 at 18:49
  • I've tried literally everything on that page. I can find app.config, but not Systerm.Runtime and so packages.config. I've updated the question as well, which shows the warning I received. – Noobie Mar 13 '21 at 20:06
  • It might have got lost at the end of my earlier comment: did you search in the files in the solution directory for the text "System.Runtime, Version=4.2.1.0"? Using Windows Explorer to search might not be the best way, something like Agent Ransack would be better. – Andrew Morton Mar 13 '21 at 20:20
  • Yes! No search result is available. – Noobie Mar 13 '21 at 20:25
  • In light of your edit, [aspnet core 2.0 dotnet run running with warning](https://stackoverflow.com/questions/46490700/aspnet-core-2-0-dotnet-run-running-with-warning) might help. You really need to search for parts of the error messages to track down what might be broken. – Andrew Morton Mar 13 '21 at 20:26
  • I have add the code it is taking me to after clicking the warning. – Noobie Mar 13 '21 at 20:31
  • There was an update to VS2017 recently: did the problem happen after installing that update? – Andrew Morton Mar 13 '21 at 20:40
  • I am using visual studio professional 2017 version 15.9.34. Microsoft .NET Framework Version 4.6.01586 – Noobie Mar 13 '21 at 20:57
  • Have you done too much work in the project to re-create it anew? You can copy-and-paste code from the broken project. – Andrew Morton Mar 13 '21 at 21:00
  • No! I was just following documentation: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-view?view=aspnetcore-5.0&tabs=visual-studio – Noobie Mar 13 '21 at 21:03
  • Ahh, if you're starting out then I suggest using VS 2019 Community Edition and .NET 5, and using a simple "Hello, World!" project to investigate version control. Version control gives you the opportunity to take steps back when things go wrong. There are a lot of things to find out about, and many of them can be free (avoid Azure and other cloud offerings in case there are unexpected bills from them). – Andrew Morton Mar 13 '21 at 22:45
  • Actually this is my company's laptop and I can't install any software from myself on this laptop. – Noobie Mar 14 '21 at 08:50
  • You didn't mention it, so have you tried the answers from my [earlier comment](https://stackoverflow.com/questions/66612437/after-closing-microsoft-visual-studio-when-i-start-my-project-again-it-shows-th?noredirect=1#comment117764340_66612437)? – Andrew Morton Mar 14 '21 at 17:17

1 Answers1

0

I have solved this issue. Kindly choose ".sln" file when opening project. It will automatically load the project folder.

Noobie
  • 3
  • 4