Using PrecompiledMvcEngine FindView throws InvalidOperationException and looks for View cshtml files - asp.net-mvc-3

I got an InvalidOperationException when the MVC controller tried to FindView while using the PrecompiledMvcEngine.
Using on a machine that has VS2012, MVC4 and deployed to IIS

After looking at the source code of ControllerBase.FindView to ViewEngineCollection.FindView to VirtualPathProviderViewEngine to PrecompiledMvcEngine, found that _mappings in PrecompiledMvcEngine had a count of 0. (Tx to Reflection and Open source.)
The reason is that there was not Type assignable to WebPageRenderingBase in my project's DLL. On decompiling my dll, it actually had the compiled views, and the views extended from WebPageRenderingBase.
After writing a unit test to do the same thing that PrecompiledMvcEngine does to load views, found that they are using different versions of the WebPageRenderingBase class. RazorGenerator.Mvc uses System.Web.WebPages v1.0.0.0 to precompile at build time. The PrecompiledMvcEngine uses System.Web.WebPages v2.0.0.0 when loading types from the compiled assembly. Fixed this by changing my MVC csproject to also load v1.0.0.0 at runtime.
Changed
<Reference Include="System.Web.WebPages" />
which picked up 2.0.0.0 to
<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
forcing it to always pick up 1.0.0.0. This problem will often be faced if you are deploying precompiled views to a machine with VS2012 and MVC4 installed, without specifying the correct version in the csproj file

Related

Unit tests not discovered in Visual Studio 2019

The tests are present at Test Explorer but run command has no effect.
Looking at Output windows, for Test outputs it shows many errors like this:
MSTestAdapter failed to discover tests in class 'UnitTests.Adhoc' of assembly 'some test.dll' because Method not found: 'System.String Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.get_DisplayName()'..
Found out that had some assembly conflict not signal by visual studio as usual on the references tree node.
Removing Microsoft.VisualStudio.TestPlatform.TestFramework reference and adding again did the trick.
Here de difference at the project file:
Before:
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
After:
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
For me, the other solutions didn't work as I e.g. did not have a reference to the package 'Microsoft.VisualStudio.TestPlatform.TestFramework'. It turned out that the solution for me was updating the Target Framework of the test projects from .NET Core 2.0 to .NET Core 3.1. Everything was working as before when changing that.
I'm not sure what caused the issue, but I think it was a combination of three packages.
For full reference, these are the ones (with version) I am now using with .NET Core 3.1:
Microsoft.NET.Test.SDK
MSTest.TestAdapter 2.1.1
MSTest.TestFramework 2.1.1
On Visual Studio 16.5.2
My problem was that I had tests in one specific class that weren't recognized.
Turns out I'd cut and pasted a TestInitialize method that contained a TestContext that I wasn't using. For instance:
[TestInitialize]
public void ClassInitialize(TestContext context)
When I removed the unused TestContext all my tests were recognized:
[TestInitialize]
public void ClassInitialize()
You can go to the test options (Test -> Options) and turn up the logging level to trace, and then you might find more information. for me, it was because the test classes were not public, even though te.exe (https://learn.microsoft.com/en-us/windows-hardware/drivers/taef/) found the tests fine even when the classes were non public
[MSTest][Discovery][C:\Users\mgrandi\Code\git\blah\src\Services\blah\Test\blah.Tests\bin\Debug\net472\blah.Tests.dll] UTA001: TestClass attribute defined on non-public class blah.Tests.blah.Common.BondObjectSanitizerTest

Could not load file or assembly 'Microsoft.Configuration.ConfigurationBuilders.Azure, Version=1.0.0.0

Tying to build a freshly cloned project, when i build i get this error
Could not load file or assembly 'Microsoft.Configuration.ConfigurationBuilders.Azure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
Things I've tried
Removing the reference and adding back in
changing build properties from debug to release
disabling strong name verification via command line using the command "sn -Vr
Microsoft.Configuration.ConfigurationBuilders.Azure.dll"
i've tried updating the reference to latest / previous versions
Everything I try and nothing seems to work, any other ideas?
In app.config or Web.config, delete the following:
, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
download this nuget package and this will work for you.
.NET Framework:
For me the issue was that I had to change the Version=1.0.0.0 in my web.config to match what was loaded and referenced in the web application references. Right click [Microsoft.Configuration.ConfigurationBuilders.Azure] and go to properties and you'll see the version at the bottom. For me it was Version=2.0.0.0.

System.Web.Helpers does not exist in namespace: WebImage

While I know this has been "answered" about 50 million times, I haven't found an answer that fixes the issue for me, so I feel like I have no choice but to ask again.
Previous suggestions:
Razor pages in MVC are giving a compile error with System.Web.Helpers not being found
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
I have added this to my web.config, but the issue remains.
Type or namespace name does not exist
I only have one project, and the targetFramework is 4.0.
I installed Microsoft.Web.Helpers 1.15 (2.0 is incompatible with MVC3.) The Microsoft.Web.Helpers.dll is in my bin folder.
The odd thing is that there's Microsoft.Web.Helpers and System.Web.Helpers. I need System.Web.Helpers in this case, because I'm using WebImage in my code.
As I keep telling people, it's when I ask for help that I find the answer. In my case, somehow in the process of destroying my Solution earlier by upgrading to Microsoft ASP.NET Helper Library 2.0 and then trying to undo that action, System.Web.Helpers stopped being a referenced assembly in my project. Simple fix!
Of course, fixing that led me to the next Assembly Reference error. I think I'll be here all night.

PortableLibrary Could not load file or assembly

I have asp.net 4 webforms website which references PortableLibrary project. In the website I serialize classes from PortableLibrary. When I deployed the project to webserver machine with IIS6 I'm getting following error:
Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
the portable library project references System.Xml (v4.0.31029).
When I tried to deploy clean project without references, just with simple serialization of string object, it worked fine.
A tried assemblybinding in web config but without success.
Why I'm getting this error? I have no idea from where comes the '2.0.5.0' version of system.xml.
answer from here: http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981
which worked for me
We'll have clearer docs around this when we release, however, you need to have Update for Microsoft .NET Framework (KB2468871)[1] installed on the web server. You will also need to remove the the binding redirect - this will actually have the reverse effect of disabling the feature. :) [1] http://www.microsoft.com/downloads/en/details.aspx?FamilyID=41bdce1f-3cb3-44bb-9b33-23a1b8c99ac3&displaylang=en

Could not load file or assembly 'System.Data.Entity

I am working within a Solution (a jokes website). The Solution has 2 Projects:
Model (C# Class Library)
MVC 3 Empty Application
I am trying to get my view to list the Jokes in the Database, but I get the following error:
Could not load file or assembly 'System.Data.Entity, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified
As you can see from the Error message, I have already added the System.Data.Entity to the web.config of the MVC 3 application.
No matter what I do, I seem to be unable to fix the error! I have added using statements for the Entity class, to the HomeController and the Index.cshtml.
To use an external Entity Framework model (embed in a DLL for example) with ASP.NET MVC 3 you must :
Add the following reference to your MVC project : System.Data.Entity (Version 4.0.0.0, Runtime v4.0.30319)
Add the following line in your web.config
...
< compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
To resolve this error:
Go to references section in your project
Right click it and than go add library package reference.
search in online tab for entity framework
you will get a lot of installed packages if u have internet connection enabled
Select EF4 package, and finally, add it
If you have any entity frame work installed and you are getting an error then click for add reference and in Browse tab go to below location:
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
Select to find System.Data.Entity.dll and then add it. This will resolve this issue.
I was getting the same error, and it was because the MVC3 project used Entity Framework 4.1, and my domain model (in a class library project, same solution) grabbed 4.2 when I added the reference.
I uninstalled EF from my Web project, then reinstalled, now both have 4.2 and are working fine.
Currently working with the Apress title, Pro ASP.NET MVC Framework (Freeman).
another way to solve this is to add empty edmx file (Add -> Class -> Data -> ADO.NET Entity Data Model) and delete it afterwards.
I am not sure what the Visual Studio Wizard does, but it`s a common problem at my machine and i always fix it like that.
Make sure you have referenced the System.Data.Entity assembly in your project. Not only in the web.config assemblies section but also those assemblies being referenced. Also make sure that the System.Data.Entity, V4.0.0.0 is present in the GAC on the server you are running this application.

Resources