I have a test project for a web service and, when I run tests in debug mode, everything works ok. However, when I just run tests, I get following error, for a referenced assembly that I try to obtain code coverage:
Class Initialization method WebServiceTest.wstest.MyClassInitialize threw exception. System.IO.FileLoadException: System.IO.FileLoadException: Could not load file or assembly 'TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=57f286581e1d278a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A) ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A).
Everything I found said to register TestAssembly in GAC. Is this what should I do? Why is it working in debug mode?
Thank you
I had the same problem, and the link below helped me...
http://weblogs.asp.net/soever/archive/2005/07/23/420338.aspx
VS.NET 2005: Code coverage for signed assemblies
I am currently working on an application using VS.NET 2005, and because all the TDD tools like unit testing and code coverage are available I started to use them.
When I started code coverage on my signed application I got the following exception:
Test method X threw exception: System.IO.FileLoadException: Could not load file or assembly 'Y, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Z' or one of its dependencies. HRESULT: 0x8013141A Strong name validation failed. ---> System.Security.SecurityException: Exception from HRESULT: 0x8013141A Strong name validation failed at X.
Not so strange if you think about it. Assembly is signed, code coverage needs code instrumentation, means modifications of the assembly, resulting in incorrect assembly so the validation failed.
Solution is to resign the assembly after instrumentation.
If you open the localtestrun.testrunconfig file (or something similar) in your solution items (double-click it), you can enable resigning in the Code Coverage section. This solves the problem.
It is also possible to simply disable all signed assembly checking on a particular machine by executing:
sn.exe -Vr *
Use with care, however, as this opens a security vulnerability. We use this on our internal virtual machine that measures coverage for us. Take a look at the usage for sn.exe as it is possible to narrow the scope of that command.
I am working with VS.Net Ultimate 2012
and this solution helped me:
Right click on Test Project-> properties-> Build Tab-> switch Generate serialization assembly to off-> done
Related
I am trying to generate a report with Qr codes I am using this video as a guide
https://www.youtube.com/watch?v=BW99WK6SQKI
I did tests before and it worked and then it stopped working and it just shows me that error nothing more.
I am working with ASP.net MVC + Report Viewer
I looked for the error in the forums and I can't find a solution...
Error while loading code module: ‘QRCoder, Version=1.3.6.0, Culture=neutral, PublicKeyToken=null’. Details: Could not load file or assembly 'QRCoder, Version=1.3.6.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. C:\DevOps\Project\Report\Qr.rdlc
IDE
IMAGEN PROPERTIES
**REPORT PROPERTIES
PublicKeyToken value should not be null. You need to get the PublicKeyToken from QrCoder dll and use it.
To find the Public key token.
Open visual studio developer command prompt.
Run sn -Tp <AssemblyName>
e.g. sn -Tp c:\libraries\QRCoder.dll
Use Public key value in PublicKeyToken=<Value>
I faced the same error, I cleaned the project inside the solution and build it as "Release" (Because the problem appeared in the production environment), found the problem fixed.
"Could not load file or assembly 'Microsoft.WindowsAzure.Storage' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
Recently got this error when starting a debug of my ASP.NET MVC project.
Just out of the blue, haven't touched any of Azure files or configs, or added something since my last succesfull build.
Read this thread but it didn't provide the correct solution for my error:
Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics' or one of its dependencies
Not sure what kind of files I should display and what parts are imporant. Please someone help?
Try running Fusion Log (Assembly Binding Log Viewer) to determine which dependent assembly is missing (or if the application actually can't find the Microsoft.WindowsAzure.Storage for some reason).
Edit: quick tutorial from Hansleman that should get people on the right track: Back to Basics: Using Fusion Log Viewer to Debug Obscure Loader Errors
I am getting this error.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1704: An assembly with the same simple name 'MyMVCAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.
My solution has 2 ASP.Net MVC projects - splitting the main content and the areas. The main project doesn't have a reference to the 2nd one. Instead, it gets all MVC DLL's in the folder and stores it into the IOC container, which takes care of registering all the controllers.
I get the error when I set the output of my 2nd ASP.Net MVC project into the bin folder of the main one. (I've set all my views in the Areas solution to Copy Always.)
I also tried post-build action of copying the DLL into the main bin instead of setting the output, but the results are the same.
What should I do?
In addition, I have the following setup:
It is set to use the Local IIS Server instead of the VS Dev Server.
In the Output window, I see that the local web server is loading all the DLL's from the GAC and Temporary ASP.Net files folder. The problem I see is that it is also trying to load my DLL file from my Solutions folder.
Any ideas why it is trying to get that sole DLL from the Solution too? It doesn't have that behaviour for the other projects.
UPDATE:
Here's a strange behaviour:
[1] I clear all copies of the offending assembly.
[2] I removed the post-build action that copies that assembly to my main MVC project bin folder.
[3] I run the main project. It works without any issues, but of course the missing assembly does not get loaded.
[4] I manually copy that assembly to the mian MVC project bin folder.
[5] I run the solution. It is getting the error again!
Can someone explain why it is trying to load this very same assembly from two different places?
Ok this may be a clue to the problem: Because I am copying the assembly to the main MVC project's bin folder, it is also getting copied into the Temporary ASP.NEt folder. At the same time, because the project is not being referenced by any other project in the solution, it is also copying the same assembly into IIS. How can I prevent this from happening? If I exclude the step of copying the assembly into the main MVC bin, it does not get loaded into IIS at all. Why is it behaving that way?
This error points out that two references have the same assembly
identity because the assemblies in question lack strong names, they
were not signed, and thus the compiler has no way of distinguishing
between them in metadata. Thus, the run time ignores the version and
culture assembly name properties. The user should remove the redundant
reference, rename one of the references, or provide a strong name for
them.
Can explain that like below.
Below sample creates an assembly and saves it to the root directory.
// CS1704_a.cs
// compile with: /target:library /out:c:\\cs1704.dll
public class A {}
Below sample creates an assembly with the same name as the previous sample, but saves it to a different location.
// CS1704_b.cs
// compile with: /target:library /out:cs1704.dll
public class A {}
Below sample attempts to reference both assemblies.The following sample generates CS1704.
// CS1704_c.cs
// compile with: /target:library /r:A2=cs1704.dll /r:A1=c:\\cs1704.dll
// CS1704 expected
extern alias A1;
extern alias A2;
UPDATE
If both assemblies are strong-named (signed), the CLR will always load from the GAC.
You can follow below mentioned steps :
Determines the correct assembly version by examining applicable
configuration files, including the application configuration file,
publisher policy file, and machine configuration file. If the
configuration file is located on a remote machine, the runtime must
locate and download the application configuration file first.
Checks whether the assembly name has been bound to before and, if so,
uses the previously loaded assembly. If a previous request to load the
assembly failed, the request fails immediately without attempting to
load the assembly.
Checks the global assembly cache. If the assembly is found there, the
runtime uses this assembly.
Probes for the assembly (for more info check below mentioned article )
for more information check How the Runtime Locates Assemblies
I hope this will help to you.
I had a similar problem playing around with a test container project having added the wrong reference. I removed it and found that after a solution clean and a rebuild the issue was two DLL's in the bin directory clashing. Having removed them and rebuilt everything was fine.
Using ASP.NET MVC4 with EF4.3
Running Enable-Migrations from PM Console
System.Management.Automation.RuntimeException: The project 'MyProj'
failed to build. The project 'MyProj' failed to build.
The project builds (control-shift-B)
Is there any way to get more detail on this error to diagnose?
This can also happen if you are building a 64-bit application. Switch to "Any CPU", at least temporarily while building the migrations, and the problem may go away. This is just one thing that can cause that error, though.
Executing "Enable-Migrations" from the package manager console requires a reference to a specific DbContext. For example
PM> Enable-Migrations -ContextTypeName myMvcApp.Web.Infrastructure.ContextDb
You do not need to install a 3rd party assembly or any other assembly other than the EntityFramework 4.3+ (the command above is for EF 5.0. This is not a well documented but essential feature of the EF.
Turns out I had run this earlier, on a project where there was no dbContext. This created a migrations Configuration class that said "fill in the name of the class", which was failing to build.
This was causing one of my projects to silently fail to compile.
Removing the Configuration class solved my problem.
Let's be clear. This error is a confusing one because the message suggests that the project won't build whereas it clearly does compile in Visual Studio.
It happened to me after refactoring namespaces for ApplicationDbContext and other security classes to match the folder structure from
namespace {projectname}.Models
to
namespace {projectname}.Models.Account
Reverting this namespace refactoring fixed the issue.
Sometimes, rarely, ReSharper is not your friend.
In my case I had errors in my project. I have cleared all other errors in my project.
Then it works well.
In my case there was a message in the Visual Studio output window that made much more sense.
PosmasterDBContext' does not contain a definition for 'Products' and
no extension method 'Products' accepting a first argument of type
'PosmasterDBContext' could be found (are you missing a using directive
or an assembly reference?)
I knew right away that somewhere in my code, I changed Products to Product
Once I reverted it to Products, the error disappeared.
I'm attempting to use the community TFS Build Extensions Azure activities to deploy to Azure as part of a TFS Build.
I've added activities from TfsBuildExtensions.Activities.dll and TfsBuildExtensions.Activities.Azure.dll and I'm able to any activity from TfsBuildExtensions onto my build process and they work properly
The problems start when I drag an activity from TfsBuildExtensions-Azure. The activity's title in the Gui display remains blank except for the generic activity icon. The properties pane shows that the properties for this activity cannot be edited. Finally, upon saving this build process template, it fails with the following error:
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceManagement, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'ServiceManagement, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.Signature.GetSignature(SignatureStruct& signature, Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Signature..ctor(IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
What am I doing wrong or what reference am I missing?
I downloaded the source of the project and found that there is a reference to a ServiceManagement.dll in the project file, and the dll can be found in their source control.
Downloading the dll from their source, and adding it to the project references has resolved the issue.
I found a reference on MSDN Blogs to a ServiceManagement.dll that revolves around deployment to azure, but it seems the original sources for the dll have disappeared.
Idea- confirm that you are using .NET 4.0 Framework target and not .NET 4.0 Client Profile. Sometimes the latter causes seemingly 'obvious' assemblies to fail to load because they have dependencies that are not in client profile.
Not a solution per se, but for another way of going about debugging, you might want to turn on fusion logging and use Fusion Log Viewer to view assembly binding errors. At least that will tell you where the runtime is looking for these assemblies that it isn't finding.
Here are some clear instructions from Scott Hanselman on how to do this:
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx