Suppressing Microsoft Fakes warnings - visual-studio-2013

I'm using Microsoft Fakes to shim a couple WindowsAzure components for testing. Following the advice in vs 2012: Shims compile, I updated my .fakes file to just generate the shims I actually need:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="false">
<Assembly Name="Microsoft.WindowsAzure.Storage" Version="2.1.0.0"/>
<StubGeneration>
<Clear/>
</StubGeneration>
<ShimGeneration>
<Clear/>
<Add FullName="Microsoft.WindowsAzure.Storage.CloudStorageAccount"/>
<Add FullName="Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient"/>
<Add FullName="Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer"/>
<Add FullName="Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob"/>
<Add FullName="Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient"/>
<Add FullName="Microsoft.WindowsAzure.Storage.Queue.CloudQueue"/>
</ShimGeneration>
</Fakes>
But I'm still getting the "Some fakes could not be generated..." warning. All the specified shims are being generated, and commenting any of those above lines out causes my test project to fail to build. If I turn on diagnostics, I see dozens of messages like:
Warning 2 Cannot generate shim for Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient+<>c__DisplayClass1: type is not supported because of internal limitations.
Everything works, I just want to suppress the warning so it stops confusing our CI server. Is there a warning number for the non-diagnostic message I can just stick in the test project to ignore?

You can remove types from the shimgeneration using
<Remove TypeName="c__DisplayClass" />
That will remove out all the types containing the above string.
See msdn link

I solved this by going into my Fakes folder and deleting the fakes for that assembly, then going into the References folder and deleting the fakes DLL for that assembly. Then I right-clicked on the assembly in references, and chose Add Fakes Assembly (again).
After it did all the fakes creation stuff (takes a few minutes), I built the project again and all the errors went away.

Related

Running MSBuild custom tasks and MSBuildRuntimeType difficulties

Main strategy:
Here we have a library NugLibEnforceCore, which contains a custom MSBuild task and we will put it in a folder: The solution folder.libs
First step is to build this library and put it in the proper folder.
Then we may try to build the Consumer project, which has build.targets and will try to run that custom tasks.
Projects and tasks are the bare minimum needed things for what expected and they don't have anything special.
The .targets file in the Consumer project:
<PropertyGroup>
<LibFolder>$(SolutionDir).libs</LibFolder>
<!-- <LibFolderPart2 Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.1\NugLibEnforceCore.dll</LibFolderPart2> -->
<LibFolderPart2 Condition="'$(MSBuildRuntimeType)' == 'Core'">NugLibEnforceCore.dll</LibFolderPart2>
<LibFolderPart2 Condition="'$(MSBuildRuntimeType)' != 'Core'">net472\NugLibEnforceCore.dll</LibFolderPart2>
</PropertyGroup>
<UsingTask
TaskName="TestTask"
AssemblyFile="$(LibFolder)\$(LibFolderPart2)"
/>
<Target Name="DoTheTask" AfterTargets="Build">
<Message Text="=== Trying TestTask ===" Importance="high" />
<TestTask />
<Message Text=" == TestTask is finished" Importance="high" />
</Target>
Here I share the issues and some difficulties I experienced and the approaches I tried related to the topic.
Tried to reproduce an issue which was irritating and happened time to time for me.
I was able to use custom tasks, but want to find the reasons and solve this issue forever.
1. Approach 1: ALL based on .net core - Build via Visual Studio Build Menu
get this error:
Error MSB4062
The "TestTask" task could not be loaded from the assembly
...\MSBuild13 Enforce Core\.libs\net472\WeRTheBest.NugLibEnforceCore.dll.
Could not load file or assembly 'file:///...\MSBuild13 Enforce Core\.libs\net472\WeRTheBest.NugLibEnforceCore.dll' or one of its dependencies.
The system cannot find the file specified.
Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. Consumer ...\MSBuild13 Enforce Core\Consumer\build\build.targets 27
2. Approach 2: ALL based on .net core - Build via dotnet msbuild command
dotnet msbuild NugLibEnforceCore\NugLibEnforceCore.csproj
get this error:
Error:
=== Trying TestTask ===
...\MSBuild13 Enforce Core\Consumer\build\build.targets(27,5):
error MSB4062: The "TestTask" task could not be loaded from the assembly
...\MSBuild13 Enforce Core\Consumer\build\.libs\netstandard2.1\NugLibEnforceCore.dll.
Could not load file or assembly '...\MSBuild13 Enforce Core\Consumer\build\.libs\netstandard2.1\NugLibEnforceCore.dll'.
The system cannot find the path specified.
Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
...\MSBuild13 Enforce Core\Consumer\Consumer.csproj]
3. Approach 3: Multi-target (.Net Core & .Net Framework) - Build via Visual Studio Build Menu:
will cause other difficulties, which I may bring more details on the next steps here if needed or as we continue this discussion.
Brief:
In the first approach when the project is based on ".net standard" why MSBuildRuntimeType is trying to take net472 library?!
In the second approach, it can't understand the same path used in the first approach and is looking for:
...\[Solution]\Consumer\build\.libs\netstandard2.1\NugLibEnforceCore.dll
instead of
...\[Solution]\.libs\netstandard2.1\NugLibEnforceCore.dll'
In the last build I commented/removed "netstandard2.1" for easier builds, cause it is currently a single-target assembly.
We know that the files are in the proper location, you can also put the library manually and take a test if needed, the only thing that matters is be able to run the consumer project's tasks without any issues and worry.
I can share videos about it if needed.
The answers briefly are:
Build and run custom tasks under visual studio doesn't support .net core, so it is looking for .net framework versions of your libraries.
There is no support for getting solution folder in MSBuild.
Some references:
ref 1
ref 2
ref 3

GENERATEFAKES fails with CS0234

My project builds for my teammates, but not for me.
Project:
Errors:
I deleted reference to mscorlib fake, recreated Fake for System, but got the same error.
If I try to add reference to mscorlib, I get message:
A reference to
'C:\Windows\Microsoft.NET\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
could not be added. This component is already automatically referenced
by the build system.
I tried to add <Reference Include="mscorlib" /> to the project file, but this did not resolve the issue.
I use VS 2017.
Will appreciate any clue.
Thank you #Abhitej, for the answer. It resolved the issue. In addition to switching to higher version of framework I added tags like <Remove FullName="System.Security.Cryptography.CryptoStream"/> for each failing class to both ShimGeneration and StubGeneration in .fakes file.
In most cases like this one its tied to the version of .Net Framework installed on the box. As long as your test project targets the highest version of the Framework on your box, this should work out. Also when dealing with System* namespace please be sure to only generate fakes for types you need excluding others. That should help Fakes deal with API changes over versions and resolve any build errors you might be seeing because of this.
-Abhitej.

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.

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.

Mixed Mode Library and CRT Dependencies - HELP

Alright, after doing a ton of research and trying almost every managed CPP Redist I can find as well as trying to copy my DLLs locally to the executing directory of the app I cannot figure out what dependencies i'm missing for this mixed mode library.
Basically I have a large C# application and I'm trying to use a mixed mode library I made. On the development machine it works perfect (of course) but deployed when the library needs to be loaded for use it exceptions out because of missing CRT dependencies (I assume).
I have used dependency walker to check all the DLLs referenced and ensured they exist on the deployment machine with no luck, I'm wondering if maybe it's some dependencies that need to be registered that I am missing, but i can't figure out what.
I get the following exception when code tries to instantiate a class from the mixed mode library.
Exception Detail:
System.IO.FileLoadException: Could not
load file or assembly 'USADSI.MAPI,
Version=1.0.3174.25238,
Culture=neutral, PublicKeyToken=null'
or one of its dependencies. This
application has failed to start
because the application configuration
is incorrect. Reinstalling the
application may fix this problem.
(Exception from HRESULT: 0x800736B1)
I am compiling the library using VS2008 SP1 with /clr:oldSyntax specified.
The intermediate manifest looks like this:
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>
I can provide any more information as needed, unfortunately i'm not well versed in making mixed mode libraries so this has thrown me off.
If anyone can offer any advice I would greatly appreciate it!
Did you deploy the CRT libraries on the target machine? Long shot: since you have a dependency on 32-bit code, you should set Target Platform in the Build property tab to x86.
EDIT: trouble-shoot side-by-side resolving problems with the Sxstrace.exe utility, available on Vista.
Typically I've found that the pragma comment style manifest decleration's to be much more error free, from a developer maintenence and an over all build action perspective. The XML manifest's are natoriously snafu.
The fimiluarity with how the linker operates and the usual compilation of C code and the fact that you simply tak this in, onto one of your source files, keeps everything a bit feeling more "together";
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
I had a similar problem the first time I deployed a VS 2005 app on a target machine -- had to bring over the MSVCRT80 DLL. Are you saying you already have the 2008 VS runtime library there?
ETA: Also, dumb question, but are you sure you have both the CRT Runtime (linked to above) and the .NET Runtime, with the same version you compiled against (probably 3.5)? You probably already know this (especially considering your score) but they're 2 different things.
I found a solution that seems to work although I don't like it very much.
I had to copy the folders:
Microsoft.VC90.CRT & Microsoft.VC90.MFC
From: Program Files\Microsoft Visual Studio 9.0\VC\redist\x86
Into the deployed application directory, I just can't figure out why this seems to work and the redistributables did nothing.
EDIT: Looking at the manifest I probably don't need to copy the MFC directory
Best way to solve this problem is to download process monitor which is free from:
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Add a filter to watch only your process and it will show you all file access the process tries. This will show you exactly which dll it can't find.
I always use this when faced with the same problem - if only microsoft filled in the filename in the thrown exception it would all be easier.

Resources