Getting a version 2.0 is not a compatible version when running NUnit - nunit

I am trying to run the sample tests for NUnit, and I am getting an error. I have the supportedRuntime versions set to v1.0.3705 up to v2.0.50727. I have the requiredRuntime version set to v2.0.50727. Is this the wrong setting?
The following is the error that shows:
Metadata file 'c:\Program Files\NUnit 2.4.8\bin\nunit.framework.dll' could not be opened -- 'Version 2.0 is not a compatible version.'

I got the same problem with the CSharp examples in 2.4.8 "right out of the box" with VS2005. Here's my solution.
In nunit.exe.config, the following block is commented-out by default. Put it back in.
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v2.0.50215" />
<supportedRuntime version="v2.0.40607" />
<supportedRuntime version="v1.1.4322" />
<supportedRuntime version="v1.0.3705" />
<requiredRuntime version="v1.0.3705" />
</startup>
It sounds like you did that but changed the requiredRuntime from the default of v1.0.3705 to v2.0.50727
After that, I opened the CSharp project in VS2005 and converted it. The nunit.framework references all had the icon that shows they are wrong. So I deleted the nunit.framework reference from all 4 projects:
cs-failures
cs-money
cs-money-port
cs-syntax
Then I added new references to C:\Program Files\NUnit 2.4.8\bin\nunit.framework.dll to replace them.
After that the project builds fine.

Related

NUnit - "Test load failed System.ApplicationException: Unable to find test in assembly"

I am using NUnit 2.6.3 and .NET framework 4.5.
I have a file, Test.NUnit, in my test project which contains:
<NUnitProject>
<Settings activeconfig="Debug"
appbase="E:\Test" />
<Config name="Debug" binpathtype="Auto">
<assembly path="bin\Debug\Test.dll" />
</Config>
<Config name="Release" binpathtype="Auto" />
</NUnitProject>
When I try to run this file I get an error message
Test load failed System.ApplicationException: Unable to find test in assembly
The problem is similar to this question. However, I can't get the answer to work.
I have a Test.dll.config file in my project which is located in E:\Test.
It contains:
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />>-->
<supportedRuntime version="v4.0.30319" />
</startup>
I have tried both versions of the supportedRuntime to show that I am using .NET framework 4.5.
I had a similar issue. Check your firewall blocking nunit-agent.exe trying to connect 127.0.0.1.
NUnit uses it for running tests and doesn't show the correct error if it can't connect to 127.0.0.1.

Build project - Nuget Error

The error occurs only on one machine.
Attempts
Wrong paths
I thought the path of any source may be wrong, so I opened the NuGet.Config to check and the 3 paths are correct and there!
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="Nightly ASP.NET Web Stack" value="http://www.myget.org/F/aspnetwebstacknightly/" />
<add key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
</activePackageSource>
</configuration>
Nuget.exe not exist
Checked on .nuget folder and .exe is in the directory!
Checked in Path of windows and there is!
I tried to run the command manually and it run successfully!
nuget install packages.config -source "" -NonInteractive -RequireConsent -solutionDir "W:\C
lients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ "
Full error:
Error 1 The system cannot find the path specified. CreditoImobiliarioBB.Domain
Error 2 The command ""W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB.nuget\NuGet.exe" install "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\CreditoImobiliarioBB.Model\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ " " exited with code -1. CreditoImobiliarioBB.Domain
Considerations
Only projects that have local packages (Source is key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository") is that they are in trouble. And recently the location of packages moved to another directory (in this case to W:\Cloud\Dropbox\Bind Defaults\Nuget Repository).
I had a similar problem recently, I fixed it by doing this:
Update Visual Studio to the latest version. (Extensions and Updates - Product Updates)
Update Nugget to the latest version. (Extensions and Updates - Visual Studio Gallery)
Clear the Package Cache. (Options - Package Manager)
Rebuild the solution.
Hope it helps.
I ran into a similar problem with NuGet.exe and WG.exe for WebGrease. I realized that with my Virus Protection turned on, it wasn't allowing the .exe files to come down properly. Once I disabled my Virus Protection, I was able to get everything I need (company is using McAfee).

Deploying MVC4: System.IO.FileNotFoundException [duplicate]

I have a small web application. Which was working fine until I added two genericHandler in my application.
I have made the following changes for the http handler
<system.web>
<authentication mode="Forms" >
<forms protection="All" timeout="720" defaultUrl="Default.aspx" loginUrl="Login.aspx" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<!--Code Log Handler-->
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" type="InfoDomeNewUI.Handler.SendOWA" path="SendOWA.ashx" />
<add verb="*" type="InfoDomeNewUI.Handler.SendSOS" path="SendSOS.ashx" />
</httpHandlers>
<customErrors mode="Off">
<error statusCode="404" redirect="Templates/PageNotFound.html" />
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<!--Code Log Handler-->
<add name="LogHandler1" path="SendOWA.ashx" verb="*" type="InfoDomeNewUI.Handler.SendOWA"/>
<!-- SMS SENDER-->
<add name="SendSOS" path="SendSOS.ashx" verb="*" type="InfoDomeNewUI.Handler.SendSOS"/>
</handlers>
</system.webServer>
Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I am using asp.net4.0 and C#. I am not using MVC
On local host it is working fine.
But when I am hosting the published code it is giving me the above error.
Stack Trace:-
[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Http.WebHost.SuppressFormsAuthRedirectModule.Register() +0
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +11708830
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +465
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLeve
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11697760
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4866485
It appears that Microsoft.Web.Infrastructure.dll is not being installed in the GAC, even if .net (4.0 or 4.5 or other) are installed successfully on Windows Server. On localhost (typically Windows client), it seems like it is being in the GAC when the tools/platform (Visual Studio etc.) are installed.
As one possible fix, please try the following:
Run the following command in the Package Manager Console. (If you are using Visual Studio, this can be reached via menu options "Tools --> Library Package Manager --> Package Manager Console:)
PM> Install-Package Microsoft.Web.Infrastructure
You will see the following messages if it is successfully installed.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully added 'Microsoft.Web.Infrastructure 1.0.0.0' to Web.
You will notice that Microsoft.Web.Infrastructure.dll has now been added as a Reference (can be seen in the references folder of your project in in Solution Explorer)
If you look at the properties of this reference you will notice that "Copy Local" has been set to "True" by default.
Now when you "Publish " your project, Microsoft.Web.Infrastructure.dll will be deployed.
I installed MVC4 via WPI and it helped me.
I had the same problem. When I tried the accepted answer (rockyb), I got the message that the package was already installed and assigned to my project. When I checked the references list, it was NOT referenced, however.
The Microsoft.Web.Infrastructure was installed in my solution's packages folder. Instead of using NuGet to add the package, I just used the Add Reference option. On the left side of the pop-up window, I chose Browse, and then pressed the Browse button on the bottom of the window. I navigated to the packages folder under the folder that my solution was in, then drilled down to the ...\mysolution\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40 and clicked on the Microsoft.Web.Infrastructure.dll. After clicking OK, the package showed up in my References list. I used the Web Deploy Package option to deploy my website and everything worked.
Why not copy Microsoft.Web.Infrastructure.dll file manually to the server BIN folder. This works for. My project is VS2010 Website.
This file can be located:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40
Just copy and paste it in the BIN folder.
You probably need to include this in the web.config if you don't have it already
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
Reference: http://thedeveloperblog.com/
I found the problem. Instead of adding a class (.cs) file by mistake I had added a Web API Controller class which added a configuration file in my solution. And that configuration file was looking for the mentioned DLL (Microsoft.Web.Infrastructure 1.0.0.0).
It worked when I removed that file, cleaned the application and then published.
After installing Microsoft.Web.Infrastructure through Nuget-Package Manager
PM> Install-Package Microsoft.Web.Infrastructure
Copy the Microsoft.Web.Infrastructure.dll manually from the Nuget-Package folder on your web application and then paste it in your bin folder of your web application deployed on the web server.
packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
It worked for me.
Update-Package -reinstall Microsoft.Web.Infrastructure didn't work for me, as I kept receiving errors that it was already installed.
I had to navigate to the Microsoft.Web.Infrastructure.1.0.0.0 folder in the packages folder and manually delete that folder.
After doing this, running Install-Package Microsoft.Web.Infrastructure installed it.
Note: CopyLocal was automatically set to true.
Sometimes needs to delete the package with force then reinstall it
its works for me.
try delete package
Uninstall-Package Microsoft.Web.Infrastructure -force
then install again
Install-Package Microsoft.Web.Infrastructure
I had the same problem and the "Microsoft.Web.Infrastructure.dll" appeared to be missing. I have tried few advises and installed MVC`s etc. and nothing helped. The solution was to install "Web Services Enhancements (WSE) 1.0 SP1 for Microsoft .NET" which includes Microsoft.Web.Infrastructure.dll.
Available at: http://www.microsoft.com/en-gb/download/details.aspx?id=4065
I had the same problem. I tried installing Visual Studio 2010 SP1 but it didn't worked.
Finally I get Microsoft.Web.Infrastructure.dll from the colleague. You can find the dll into your friends PC where the project is perfectly working. Try to search dll into Temp/Temporary ASP.NET Files. Go to Temp using %temp% into run window.
After getting dll into your pc, just add reference to your project and it will work.
Republishing the site fixed the issue for me.
Was facing the same issue and unfortunately nothing here was working. Finally, I came across this link: https://blogs.msdn.microsoft.com/jjameson/2009/11/18/the-copy-local-bug-in-visual-studio/
Turns out the solution is sort of dumb: set copy-local for the microsoft.web.infrastructure dll to False, then set it back to True.
By the way, I think what is happening is that there are two versions of the microsoft.web.infrastructure dll, one that is pre-installed in the GAC, and another one that is now a nuget package. I think one is masking the other, hence causing issues. In my particular case, on my build server, I need it to be copied over to a folder (this folder is then zipped and sent off to deployment). I guess the system had a copy locally and just thought "nah, it'll be fine"
I have a files only website. Added MVC 5 to webforms application (targeting net45). I had to modify the packages.config
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45"
to
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" developmentDependency="true"
in order for it to startup on local box in debug mode (previously had the top described error). Running VS 2017 on Windows 7...opened through File > Open > Web Site > File (chose root directory outside of IIS).
I had the same problem after upgrading a bunch of NuGet packages.
I have tried all kinds of deleting, cleaning, resintalling described here and beyong to no avail. The references did not have Microsoft.Web.Infrastructure despite the NuGet manager showed it was installed.
The problem was solved by replacing:
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
with
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
in packages.config. The culprit is apparently "net45".
Visual Studio 2022 .net.4.8
I just run this and is solved
you can install this dll using nuget package manager
PM> Install-Package Microsoft.Web.Infrastructure -Version 1.0.0

Moles creation does not create all objects

While trying to create a mole for some unit tests I noticed that some functions were not being 'moled'. Some functions were appearing in the xxx.moles.xml file while others were not.
To resolve this issue, I've tried reinstalling 'Pex and Moles', deleted files in the MolesAssembly folder, restarted the computer, etc.
Finally, I simply opened a console window and ran the moles.exe command from the command prompt.
"c:\program files\microsoft moles\bin\moles.exe" assembly.dll /op:"MolesAssemblies" /msbuild:"c:\windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
The first time I ran this, I received a message:
Moles : info : compilation : assembly metadata hash unchanged,
skipping code generation.
After deleting the moles in the MolesAssemblies folder, I ran the moles.exe command again and all my functions are now appearing in the xxx.moles.dll and xxx.moles.xml files.
Does anyone know why the mole generation does not work when building inside Visual Studio 2010, but it works perfectly from the command prompt?
I found the issue...I modified the .moles file before and only certain classes were added. I simply had to add more 'TypeName' and the classes/functions were included.
The reason that it 'worked' by using the moles.exe command was because I did not use the .moles file (I simply referenced the assembly). I changed the parameters for moles.exe to include the .moles file and the assembly and the results were identical to the output generated by Visual Studio. Once I notice that other parts of the code was breaking, I realized that the .moles file was incorrect.
I had something like this...
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
</Types>
</MoleGeneration>
</Moles>
I needed a second 'Add'
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
<Add TypeName="AdditionalClass"/>
</Types>
</MoleGeneration>
</Moles>
Be sure to REBUILD the test project, after modifying an assembly that is moled. Using the "clean" action on the test project will also fix this issue.

Running WatiN tests with ReSharper testrunner

I'm getting started with WatiN to test my web interface. The problem I'm having is the following:
When I start the tests from within TestDriven.net, I have no problem. If I use the ReSharper test runner, I get this predictable AppartmentState exception.
I tried using the different options described here: http://watin.sourceforge.net/apartmentstateinfo.html#testdriven. Nothing helps.
Any suggestions?
I've use Resharper test runner in most of my watin test projects. To get it to work use the same method as for nunit:
http://watin.sourceforge.net/apartmentstateinfo.html#nunit
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
With NUnit 2.5, RequiresSTA attribute should be the tool of choice.
Using Resharper 5.1 with VisualStudio 2010 Ultimate I found that I needed to change my Resharper options to disable "Shadow-copy assemblies being tested" (found in Resharper --> Options --> Tools --> Unit Testing).
Additionally, I also found that the correct naming for the config file is the one which includes the dll extension (so: assemblyname.dll.config).