Using Moles for TDD with HttpWebRequest - moles

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.

Related

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?

Scaffolding a migration programatically in entity framework 5 code first

I am working on a system which scaffolds a migration from inside our code using ToolingFacade.
The system worked fine in entity framework 4.3.1. After the Upgrade to 5.0 I see that the correct entity framework version is loaded when starting out tool, however when I call the scaffold method I get the following exception:
Could not load type 'System.Data.Entity.Migrations.Design.ToolingFacade+ScaffoldRunner'
from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
Does anyone know why calling a method in entity framework 5.0 requires an older version dll?
I ran into this issue recently when using EF6. Visual Studio required me to re-install EntityFramework via the Package Manage console to get things working again. Note that when I did so, the console output suggested that it had no idea that EF was installed before; somehow the association had been lost. Perhaps this is why the tooling assembly or assemblies weren't being loaded.
In any case, reinstalling the package via the console (and a restart of Visual Studio) solved the problem for me.

Missing an assembly reference Crystal Reports in Visual Studio 2010 on Windows 8

I installed Crystal Reports for VS 2010 from http://www.sdn.sap.com
When I create new Crystal Report in the CrystalReport.cs class there are few errors:
The type or namespace name 'Engine' does not exist in the namespace
'CrystalDecisions.CrystalReports' (are you missing an assembly
reference?)
I manually browsed the CrystalDecisions.CrystalReports.Engine.dll and added it to the References but still gives me the error
The same error gives me for CrystalDecisions.ReportSource
The same error gives me for CrystalDecisions.Shared
Also the CrystalDecisions.CrystalReports.Engine doesn't exist when I go to Add Reference .NET tab ..
For all those who has still this problem:
Somehow i figured out that there are problems with .NET 4, with .NET 4.5 & VS2012 they just work fine.
I haven't tried Ally's solution but that maybe is the right answer to my problems, but whatever i switched to vs2012 & 4.5 so they work just fine.
Thanks
You Must Change Version Of .Net In Project Properties. In Tab Application, Change Target framework To .Net Framework 4. I exactly had problem. In fact, initial .Net Framework When I created Project was .Net Framework 4 Client Profile. As I told, I changed to .Net framework 4.
Problem solved perfectly.

Build error complaining that it cannot find System.Data.Entity in asp.net application

I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have followed the Nerd Dinner tutorial for a large part. The problem is that when I try to build, it is constantly giving me a build error saying:
Error 43 Could not load file or
assembly 'System.Data.Entity,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The system
cannot find the file specified.
This error is coming from the file "ASPNETCOMPILER" apparently. Some things that I have already checked are:
There is a reference to System.Data.Entity in the project references already.
I have .Net 4.0 installed on the system.
Any ideas on what could be wrong?
Try copying the System.Data.Entity.dll into your bin folder, or target your system to use .NET 2.0, as that should copy it over automatically.
Posting back for community goodness, the first comment in this thread by "DonSleza4e" seemed to solve my problem.

Why doesn't my Entity Framework app work on production server?

I get following error when deploying on test server with II6 and Framework 3.5 SP1 installed.
The located assembly's manifest
definition does not match the assembly
reference
My development machine is a 64bit pc with Visual Studio 2008.
Any suggestions?
Looks as though the .net assembly is unable to find the correct version that you are after. Make sure you put the assembly definition in the GAC. You may need to look at the GAC and remove the old version and then rebuild.
In other words, go to your production server and look for any assemblies (.dll files) that are currently loaded on that server. The version on your production server may not match the reference of your local machine's project.
Once you find it remove it and replace it with what your application is using.