Could not load file or assembly 'Microsoft.AspNet.Web.Optimization.WebForms' or one of its dependencies. The system cannot find the file specified - vb.net

I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />

Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)

Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization

Related

No transpilation on IIS production server

First off, a lot of this technology is new to me, so I apologize for the noob question. Also, this is my first post to SO (after years of reading), so forgive the formatting.
I have a web application that I am running via MSVS 2017. I am writing my front end with React.js. After installing the appropriate packages via nuget, I have something that works when I run both the debug and release versions on my local dev machine (using iisexpress).
However, after I commit my source changes, and it gets pushed to the test server (IIS), the app runs fine. But, the JSX files that are returned from the test server are not transpiled. I just get the raw JSX file. Whereas, on my local machine, the returned file is transpiled.
I have a ReactConfig.cs file with a single static Configure method, where I have a call to add my JSX file via ReactSiteConfiguration.Configuration.AddScript, but that appears to be unnecessary because I still get a transpiled result even when it is commented out. At the top of my ReactConfig.cs file I have seomthing similar to:
[assembly: webActivatorEx.PreApplicationStartMethod(typeof(MyApp.Api.Controllers.MyController), "AutoMapperStart")]
So, then I am left with the question of how is the transpiling occuring on my dev machine, but not the deployment machine.
In my web.config file, I have tried both:
<httpHandlers>
<add verb="GET" path="*.jsx" type="React.Web.BabelHandlerFactory, React.Web" />
</httpHandlers>
and
<remove name="Babel" /><add name="Babel" verb="GET" path="*.jsx" type="React.Web.BabelHandlerFactory, React.Web" preCondition="integratedMode" /></handlers>
But neither seems to make a difference on the deployed server.
If anyone has suggestions of what I should look at next, it would be greatly appreciated.
Update:
I notice the relevant item that is allowing my dev environment to do the transpilation is the second code section above in my web.config file. However, that I don't see the same lines on the server. Are web.config file typically 'hand edited' per deployment, perhaps?
So, here is what I eventually figured out that worked for me.
First, yes, the web.config file is deployed with as a template. And then hand configured as necessary.
Second, and more importantly, there are two parts to getting the server to render JSX to pure JS.
I needed the following in the web.config file:
<system.webServer>
<handlers>
<remove name="Babel" />
<add name="Babel" verb="GET" path="*.jsx"
type="React.Web.BabelHandlerFactory, React.Web"
preCondition="integratedMode"/>
</handlers>
</system.webServer>
And finally, in the assemblyBinding section:
<dependentAssembly>
<assemblyIdentity name="JavaScriptEngineSwitcher.Core" publicKeyToken="c608b2a8cc9e4472" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.9.0" newVersion="2.4.9.0" />
</dependentAssembly>

The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime" from TeamCity

I'm getting the above error from our TeamCity build.
I have tried adding the following lines to the web.config.
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
I have also installed the latest Windows SDK for .NET4.5.2.
Neither of these have resolved the error.
Any ideas?
Finally found a solution to this problem. I added a reference to the System.Runtime.dll assembly to my project. I added a reference to the following file to my project (substitute your own version of .NET in the path as necessary). You could always copy the file to your project folder and link it from there as an alternative.
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades
This worked for me and hopefully will work for someone else.

VS 2015 IntelliSense: Assembly Not Referenced Error

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.

Sub-folder web.config namespaces remove broken in 4.0?

Similar to this question
I am porting a web application to 4.0. It has a root web.config that adds a namespace:
<namespaces>
<add namespace="Insignia.Catalog2"/>
...
</namespaces>
There is a sub-folder to this app with its own web.config:
<namespaces>
<remove namespace="Insignia.Catalog2"/>
<add namespace="Insignia.Catalog"/>
</namespaces>
.Catalog and .Catalog2 have overlapping class names. This worked great in ASP.NET 2.0 thru 3.5 but seems broken in 4.0 - that is, I now get compiler errors about the colliding class names.
Well I figured it out. While the 'remove' tag WAS removing .Catalog2, another DLL had changed to include a reference to that namespace. Using a control from that other DLL brought .Catalog2 along with it! Fixing the reference solved the problem.

Assembly reference not resolving in the Web.config

I am developing WCF service hosted by IIS. I need to add KnownType attribute to my base class. One way of adding KnownType attribute is to add a section into the Web.config file like this:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="MyBase, MyBaseDll">
<knownType type="MyDerived, MyDerivedDll"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
But I got error message when my mouse is over the MyBase. The Error message is “Invalid Module Qualification: Failed to resolving assembly MyBaseDll”. Same error message for MyDerivedDll.
Additional information:
Both MyBaseDLL.dll and MyDerivedDLL.dll are in the IIS /bin folder. Both DLLs reference no other assembly other than .net system assemblies
Have you tried giving the full name of the assemblies and full name of the types (namespaces and all) ...
<add type="MyNamespace.MyBase,
MyBaseDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX">
<knownType type="MyNamespace.MyDerived,
MyDerivedDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX"/>
</add>
What happens when you run the service? The error message could be bogus. For instance, ReSharper sometimes gets confused about assembly references in config files.
OTOH, other times, it's correct.