VS 2015 IntelliSense: Assembly Not Referenced Error - intellisense

I just switched to VS 2015. I have an older MVC 5 app that runs against 4.52. In VS 2013 it's perfectly fine.
In VS 2015 I'm getting red squigglies under my #Html.TextBoxFor() with an error indicating:
The type 'Expression<>' is defined in an assembly that is not
referenced. You must add a reference to assembly 'System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The project builds and runs just fine -- but I am concerned about the IntelliSense error that never happened in VS 2013. Okay, so I try to add the reference to System.Core as recommended in the error above and then I get this error:
A reference to 'System.Core' could not be added. This component is
already automatically referenced by the build system.
Again, this is fine in VS 2013.

I had the same issue, but in the mean time I've found the answer:
I had to add the following references to my web.config (add inside the opening system.web tag):
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
I also changed the target framework from 4.5.1 to 4.5.
p.s Close and reopen Visual Studio after changing it.

I have tried most of these, what eventually worked for me was unloading the project, edit the csproj file, and add the following:
<Reference Include="System.Core" />

In my case (VS 2019) I have to add this in .csproj file after unload the project
<Reference Include="System.Core" />
need to change in ProjectGuid tag like below:
<ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid>
then reload the project and add this tag to web.config like below:
<compilation debug="true" ...>
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
...
</assemblies>
</compilation>
and after that just rebuild the project and all the error is gone in my case.

Only deleting solution and getting solution from source control solved this for me, removing .vs folder and starting VS2015 as "devenv.exe /resetuserdata" did not solve my problem, event removing MEF component cache did not solve as per Razor intellisense not working in VS 2015 answers.

In my case, it worked after changing the tag <ProjectGuid> in .csproj file to <ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid> and reopening the solution. All of the solutions posted above did not work for me.

From updating from 4.5.2 to 4.6.1 I got these exact errors in my views. Building and running the solution worked absolutely fine. After trying all the solutions already posted here, (and also checking intellisense for working, clearing caches, removing bin and obj folders, loading and reloading the project) nothing worked whatsoever (system.core was already being built correctly and adding in those references to the Web.config did nothing). I did my own digging and eventually found that in the project where the error was occurring the Web.config file contained two compilation debug target frameworks and a different httpRuntime target framework. Like so:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.1" />
...
The solution was to resolve this by removing the extra compilation debug target framework and to ensure all target frameworks were the one I wanted (4.6.1)
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
...
Double check this if nothing else works. Hope that helps someone!

If anybody is facing this issue with
VS 2017 , .net framework version 4.8 and MVC version 5.2.7
Then check your Microsoft.CodeDom.Providers.DotNetCompilerPlatform version, If you have 2.0.1 version installed then downgrade it to 2.0.0
Then check the MVC version, you have to downgrade it to 5.2.4
Then downgrade Microsoft.AspNet.WebPages 3.2.7 to Microsoft.AspNet.WebPages 3.2.4
and Microsoft.AspNet.Razor 3.2.7 to Microsoft.AspNet.Razor 3.2.4
try to run the application now, it will work.

I tried these and other solutions on other Stack Overflow threads. None worked.
What worked was repairing the installation of Visual Studio which is found in the System Settings, Apps & features sub-menu (click on VS and choose "Repair"). It took a couple of hours, but then the problem disappeared.

Related

Could not load file or assembly 'System.Web.Http, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

Using Visual Studio 2015 & Sitecore 8.0
I have created a new MVC project with .Net Framework 4.6.1, copied, and referenced the Sitecore.kernel.dll & Sitecore.mvc.dll. Replaced the existing web.config & global.asax with the sitecore files.
Added a plain HTML page in the solution and tried to browse it (from VS). The page opens with this error
Could not load file or assembly 'System.Web.Http, Version=5.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified.
This HTML page is not published to Sitecore yet. I'm guessing, the Sitecore.mvc.dll wants MVC 5.1.0 and the MVC in VS project is 4.0.
So, I tried the following steps.
Run install package command in package manager console for MVC 5.1.1 which shows the error
Unable to load the service index for source
https://api.nuget.org/v3/index.json.
Deleted the %AppData%\NuGet\nuget.config and restarted VS2015
Manually browsed https://api.nuget.org/v3/index.json, but the page doesn't load - Secure connection failed. But this - http://api.nuget.org/v3/index.json will promt to download the json. So, in the nuget changed https to http, but its the same error - Unable to load the service index...
I'm not even able to start my first Sitecore MVC project when this happens.
I replaced the sitecore web.config with the regular VS project's web.config and now I'm able to browse the page. I set its Copy To Output Directory to Do not copy, so that it will not get published.
Will I be able to proceed with my Sitecore development this way without any major issues in future.
You need to do a few things to fix this:
Your VS project should be updated to have the web.config file from the Sitecore installation. You must have the Sitecore version of that file or Sitecore will not run correctly
You should add a binding redirect for the MVC file that makes everything use the latest version:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
etc....
</runtime>
Make sure that the web.config file in your /views folder contains the correct versions of all the MVC assemblies. This is mine for a .net 4.6 application:
<configSections>
<sectionGroup name="system.web.webPages.razor"
type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host"
type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
<section name="pages"
type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host
factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="Sitecore.Mvc" />
<add namespace="Sitecore" />
</namespaces>
</pages>
</system.web.webPages.razor>
Once that is done, your Sitecore installation should pick up the latest MVC binaries correctly.

Precompile not working with Razor views in MVC 4

I'm trying to precompile razor views but during the build VS2010 throws errors such as "#ViewBag does not exist in the current context." The project builds and runs fine when views are not precompiled.
In order to turn on view compilation I set the following node in the project file:
<MvcBuildViews>true</MvcBuildViews>
The section below exists in the Views Web.config file.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Xml"/>
<add namespace="System.Xml.Linq"/>
</namespaces>
</pages>
</system.web.webPages.razor>
Any ideas why the project won't build?
Geeze, do I ever feel like an idiot. Turns out there were some cshtml files in a _temp folder that resided inside of the project folder. Even though the folder was excluded from the solution the compiler was picking up the files contained therein. Moving that _temp file out of the project folder fixed the issue.

Assembly Version Conflict .net 4

Does anyone know about resolving this error??
The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms**9.0.0.0**__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms**10.0.0.0**__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'
I have referenced v10, when I check my GAC i found three versions of Microsoft.ReportViewer.WebForms. v9, v10, v11..! cant even able to remove older version of assembly from GAC.
I have resolved this with trail and error method. Assembly version was not updated in config file for some reasons. changed the version to 10 manually like this:
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
</httpHandlers>

MVC 4 Beta side by side installation error

I just installed the MVC 4 Beta now my MVC 3 application does not compile with the following error:
The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' and 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' C:\Users\michaeljo\Documents\src\patientgive\Phc.Mvc\Infrastructure\PasswordStrengthAttribute.cs
It would appear this has been moved to a different assembly and since both assemblies are in the GAC it does not know which to use.
After installing MVC4 beta today, a few of my MVC 3 projects would not compile. (ModelClientValidationRule conflict) The fix was:
Edit:
ProjectName.csproj
Change
<Reference Include="System.Web.WebPages"/>
To
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
Ok try this solution...
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
3.Locate the following assembly references:
<Reference Include="System.Web.WebPages"/>
<Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
4.Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
REFERENCE
also try this
I Found this answer here for me the second edit combined with the first solved the problem.
Just remove the reference of System.Web.WebPages. This will build your project successfully.

How to set web.config to "debug=false" via MSBuild Extension Pack?

I have an WCF Service Application and the web.config is set to debug mode (debug = true):
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
I would like to set that to "debug=false" via MSBuild Extension Pack (version 3.5.8.0), so that the released version is always automatically in non-debug mode.
Obviously I need to use the XmlFile class, but it doesn't do anything.
My build file looks like this:
<Target Name="Test">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(MSBuildProjectDirectory)\$(BuildDir)\ServiceClient\web.config" XPath="/configuration/system.web/compilation[#name='debug']" InnerText="false"/>
</Target>
When I run the build script, I only see this:
Test:
XmlFile: C:\MyProject\Build\ServiceClient\web.config
Update Attribute: /configuration/system.web/compilation[#name='debug']. Value:
No errors, no warnings...nothing.
I can see that MSBuild found the web.config and did something with it, because "Date Modified" in the Explorer is set to right now, which wasn't the case before I ran the script. But there is no visible change in the file. I used a diff tool to compare the file versions before and after MSBuild, and they are identical.
I also tried to set Key and Value instead of InnerText, but that doesn't help either.
Any idea what I'm doing wrong?
Try this:
<Target Name="Test">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="web.config" XPath="/configuration/system.web/compilation" Key="debug" Value="false" />
</Target>
I am using extension pack version 3.5.8.0