NUnit-console wants me to install .NET 3.5 - nunit

I'm trying to run some NUnit tests written in Visual Studio on the command line using NUnit console. The tests are built using .NET 4.5.
To run them, I'm typing:
nunit3-console mytests.dll
And I keep getting a pop-up which tells me "an application on your PC needs the following Windows feature: .NET Framework 3.5 (includes .NET 2.0 and 3.0).
I've tried forcing NUnit to use 4.5 by saying
nunit3-console /framework:net-4.5 mytests.dll
But I get the same thing.
I tried installing .NET 3.5, but it can't be installed (I guess because I don't need it as I already have 4.5).
The tests run fine when run from Visual Studio using ReSharper or in the NUnit GUI...
I've created a really simple solution (tried with .NET 4 and .NET 4.5) which has a NuGet reference to NUnit 2.6.4 and one class (below):
[TestFixture]
public class Class1
{
[Test]
public void MyTest()
{
Assert.Pass();
}
}
I still get the same error.
How can I fix this?

That executable itself (nunit3-console) must have been produced by C# compiler to target .NET Framework 2.x/3.x (for the so called compatibility). Thus, when it runs on a pure .NET Framework 4.x Windows, you see the other compatibility feature by Microsoft, where it always prompts and asks to install .NET Framework 3.x (you must do that via Programs | Add/Remove Windows feature). Both of them are ridiculous as people should rarely use .NET Framework 2.x/3.x (though Microsoft will keep supporting .NET Framework 3.x as part of Windows).
To get rid of that prompt, you can enable .NET Framework 3.5 (which also gives you the bits to compile against .NET Framework 2.x/3.x). Or you modify its nunit3-console.exe.config file to use <supportedRuntime> to force .NET 4.x is used to load this executable.
I guess the NuGet version contains a proper .exe.config, while the MSI version not. You can analyze further for sure.

Related

Why does NuGet package reference incorrect .NET framework/standard?

tl;dr:
I have a .NET Framework 4.7.2 project consuming a NuGet package which supports .NET Standard 2.0. That package, in turn, requires another package which supports .NET Standard 2.0. However, when run, the latter package uses net461 binaries rather than netstandard2.0.
How do I force a NuGet package & its dependencies to use .NET Standard 2.0?
Are there special steps required to consume a .NET Standard package from a .NET Framework 4.7.2 project?
Specifics:
I am trying to get the NuGet package for SparkplugNet (which uses the MQTTNet package) working in a .NET Framework 4.7.2 project - just the basic "How to use" SparkplugB example. Both projects support .NET Standard 2.0. After some debugging (details below), it appears MQTTNet is trying to use code paths specific to .NET Framework 4.6.1, rather than .NET Standard 2.0, and crashing with no feedback whatsoever.
To troubleshoot, I built SparkplugNet and MQTTNet from source. As far as I can tell, the crash comes from hitting .NET 4.5/4.6.1-specific code in CrossPlatformSocket.ConnectAsync(), specifically this line (in context):
await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, host, port, null).ConfigureAwait(false)
When I debug, _socket is a System.Net.Sockets.Socket which doesn't appears to have a BeginConnect() method, at least in the source file my debugger pulled. I am not sure why it branches to that code when .NET Standard 2.0 would be a better fit.
Back to a 4.7.2 project consuming SparkplugNet & MQTTNet via NuGet package.... If I look at the reference paths, SparkplugNet is properly pointed at the netstandard2.0 folder, but MQTTNet points to packages\MQTTnet.4.1.3.436\lib\net461\MQTTnet.dll. If I change the hint path manually in the project file, MSBuild appears to pull from the netstandard2.0 folder, but it still crashes. I assume it is the same cause, though I'm having trouble debugging using NuGet packages. Also, I'm hoping for a better solution than hacking hint paths.

C# application .Net 2.0 Couldn't run in Windows XP

I built a .Net 2.0 Application for Windows XP but I made it in Windows 7.
The application contains a Mysql.data connection and CrystalReport. When I try to run it on Windows XP, the application does not run, giving an error message of:
The application failed to initialize properly (0xc000007b).
I tried to rebuild application in Windows XP, but when I rebuilt and ran it in Visual Studio, the following error occurs:
Could not load file or assembly or one of its dependencies. The module was expected to contain an assembly manifest.
How can I fix this?
Please try the following:
1.Uninstall the .NET Framework 3.5 from Add/Remove Programs (in the Control Panel) on Windows XP or Programs and Features on Windows Vista/Windows 7.
Even if the uninstall fails, go on to step 2.
2.After the Framework 3.5 has been uninstalled or if it failed, download and run the .NET Framework removal tool.
Here's the link to Aaron Stebner's Framework Removal tool on Windows Live Skydrive:
http://cid-27e6a35d1a492af7.skydrive.live.com/self.aspx/Blog_Tools/dotnetfx_cleanup_tool.zip?wa=wsignin1.0&sa=17797669
Aaron Stebner is a Microsoft employee. The tool he's developed is linked on that page and makes easy work of cleaning up damaged .NET Frameworks from your system so they can be reinstalled. When you run the tool, choose the .NET Framework 3.5 from the list and choose to cleanup. After this is done, reinstall the .NET Framework 3.5 that Design 3 needs by running the Expression Design 3 setup package again. It will detect that the .NET Framework 3.5 is missing and reinstall it for you. After that's done, try running Design 3 again.
3.If that still fails to resolve the problem, go to START, RUN and type CMD to run a command prompt. Type CHKDSK /R and hit ENTER. Hit the letter Y and restart the machine. Allow the machine to do the check disk scan. After this is done and it goes back into Windows, try Expression Design again.
more information here

C++/CLI and Entity Framework 5

I thought I'd try using EF 5 with C++/CLI in VS2012, so that I could try Code First. The package downloads via NuGet fine, but isn't visible to the solution.
On investigating, the Package Manager says that the package is not compatible with the version of the Framework being used by the solution, and requires 4.0 or 4.5... but the config for the project (a plain Win32 console app) says it is using v4.5.
Has anyone come across this and found a way to fix it?

Using Moles for TDD with HttpWebRequest

I am using VS2010 with SP1 (also have VS2012 installed on the same machine). Moles 1.0
The project is using .NET 4
I added moles assembly to system.dll and get the following error on compile
Error 46 The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?) [C:\Test\obj\Debug\Moles\s\m.g.csproj] C:\Test\m.g.cs Test
IReadOnlyList .NET 4.5 as far as I know.
Anyone else got this issue?
Updated Solution
I was able to get Pex to run in VS 2010 with .Net Framework 4.5 installed. Maybe others have explained that this is the solution but my issue (being new to Moles and Pex) is that many of the explanations were vague. Thanks to the author of these posts because they got me headed in the right direction:
http://feherzsolt.wordpress.com/2013/02/13/moles-and-net-4-5/
http://www.daedtech.com/using-moles-with-the-system-assembly
So the solution is to create a new .moles file (System.moles) in the test project at the same level that Pex created the yourAssemblyUnderTest.moles file and add the following to the file.
<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
<Assembly Name="System" ReflectionOnly="true" />
</Moles>
You may have to clean (or manually delete the obj folder contents) and rebuild but this solution worked for me. I also noticed that the first build would report build errors, but the errors would go away on subsequent builds.
Alternative Solution
I know this isn't THE solution but it is a (poor) workaround that allows Pex to run...plus this was too long for a comment. If anyone knows how to get PEX to run on a machine with the 4.5 .Net Framework PLEASE respond.
This was my scenario. I have a machine with the .Net Framework 4.5 and I have Visual Studio 2010 and 2012 installed. I installed Pex (en_visual_studio_2010_pex_0.94.51023.0_power_tools_x64_598803.exe) and could run Pex in a VS 2010 project that was targeting .Net Framework 4.0. I could run Pex and it identified issues...but once I promoted issues to Unit Tests the unit test project wouldn't compile because of the following build error
The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?)
After much searching, and reading that Pex or Moles was replacing 4.5 .Net Framework assemblies with 4.0 versions I decided to uninstall 4.5, install 4.0, and give it a try. Running on 4.0 works just fine and I didn't need to define Mole type filters to get it to work. Then I tried tried to upgrade to the 4.5 Framework again...but sadly I end up right back where I started with the IReadOnlyList namespace issue.

EF 5.0 Enums Not Generating

BACKGROUND
I'm using VS 2010 on a machine where I installed .Net 4.5 which I've read was an in-place install (overrode the .net 4.0 version).
I have projects still targeting 4.0 and 4.5 option is not available but was told it's ok since 4.5 was an in-place install. I then installed EntityFramework -pre via nuget and notices when I ran Upgrade-Database -Script commands, it would not generate enum properties.
I then found this. I tried doing everything from scratch again but it was still adding EntityFramework 4.4 instead of 5.0. So I manually changed all references to point to the 5.0 version to make sure I have EF 5.0 version. All compiled.
PROBLEM
When I run
Enable-Migrations -EnableAutomaticMigrations
I get "No classes deriving from DbContext found in the current project.
Edit the generated Configuration class to specify the context to enable migrations for."
So I manually made sure that my class is correct as in:
internal sealed class Configuration : DbMigrationsConfiguration<DataContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
DataContext subclasses DbContext.
When I run
Update-Database -Script
I get "No migrations configuration type was found in the assembly 'MyProject'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration)."
MyProject does have the configuration class I mentioned above and in Package Manager Console I am choosign the right dropdown for my project containing Migrations folder and this Configuration class.
QUESTION
What do I do to make sure when I install EnittyFramework via nuget that it adds the 5.0 version and not 4.4 even though I have .Net 4.5 installed?
If I can't do anything related to the question above, what can I do to make sure Upgrade-Database spit out a script?
Entity Framework 5.0 isn't out yet. There are prereleases, but you need to specifically enable prereleases in order for NuGet to display them.
However, keep in mind that EF 5.0 won't support everything in .NET 4.0 that it will in .NET 4.5. Yes, .NET 4.5 overwrites .NET 4.0, but if your project is in VS2010, it will be configured to build for .NET 4.0, not .NET 4.5. It cannot assume .NET 4.5 features, because the result needs to run on systems that don't have .NET 4.5. You're targeting .NET 4.0, after all, and enum support isn't in the EntityFramework DLL you get from NuGet, it's in the System.Data.Entity DLL that's part of the .NET runtime, so it cannot be added in .NET 4.0. You can install the Visual Studio Beta to create applications that target .NET 4.5.
In short: "was told it's ok since 4.5 was an in-place install" -- no, it's not ok for your purposes.