Error using VS 2015 code analyzers - c#

Using Visual Studio 2015 RTM, I have a .NET 4.0 class library project.
I've added the Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package to the project. This results in the following Analyzers being listed for the project in Solution Explorer.
Microsoft.AnalyzerPowerPack.Common
Microsoft.AnalyzerPowerPack.CSharp
System.Runtime.Analyzers
System.Runtime.CSharp.Analyzers
System.Runtime.InteropServices.Analyzers
System.Runtime.InteropServices.CSharp.Analyzers
However in the Error List window, the following error appears:
Unable to load Analyzer assembly
C:\Dev\git\MySolution\packages\System.Runtime.Analyzers.1.0.0\analyzers\dotnet\cs\System.Runtime.Analyzers.dll
: Could not load file or assembly 'System.Runtime.Analyzers,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. Strong name validation failed. (Exception
from HRESULT: 0x8013141A)
(and similar for System.Runtime.CSharp.Analyzers and System.Runtime.InteropServices.Analyzers)
The first two analyzers do work correctly, but I'm not getting anything for the last four (probably related to the above errors).
Is there a way to get these to work, or is it possibly related to the project being .NET 4.0?

Thank you for reporting this issue. The System.Runtime.* analyzer assemblies uploaded to nuget are indeed only test-signed, and hence cause the assembly load failures. We are working uploading newer nuget packages for System.Runtime.Analyzers and System.Runtime.InteropServices.Analyzers which will have signed assemblies.
Meanwhile, you can get the non System.Runtime based FXCop analyzers by installing "Microsoft.AnalyzerPowerPack" from here: https://www.nuget.org/packages/Microsoft.AnalyzerPowerPack/. These do contain all signed assemblies and should work fine.
I'll post an update on this thread once we have uploaded signed System.Runtime analyzer packages.
Sorry for the inconvenience and thanks again for reporting it!
Regards,
Manish

Related

VS2019 RegPkg.exe throws Unhandled Exception

I've just installed Visual Studio 2019 with SDK and when i try to run RegPkg.exe, I see the following error. I don't have any other VS instances installed on the machine but I'm confused why the error is reporting about version 15.0.0.0 (which is VS2017).
Can someone please help me to resolve this error.
Unhandled Exception: System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.VisualStudio.Shell.Framework,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
at Microsoft.VisualStudio.Tools.RegPkg.Main(String[] arguments)
I just noticed I got the exact same error message, using VS 2017's version. So it has nothing to do with the version you are using. I don't even have 2019 installed.
Microsoft simply broke their SDK, which has apparently been broken for 2 years, and no one noticed. For reference, I'm using VS 2017 15.9.7, also with the VSSDK installed.
I have a NuGet reference to that DLL in a VSIX extension I build, so I had a copy in my .nuget package cache ("%USERPROFILE%.nuget\packages\microsoft.visualstudio.shell.framework\15.9.28307\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll"). I copied that version into the folder where regpkg.exe is located, and resolved the error (%VSSDK150INSTALL%\VisualStudioIntegration\Tools\Bin).
Probably not the best solution, but Microsoft needs to fix their product. I suspect it broke as part of their reorganization for the 2017 product, as they also added all the assemblies that extensions need for dependencies to NuGet. I guess they forgot to keep that assembly in the actual VS install folder.
EDIT: I've been looking into this more, and apparently the file actually exists in the lib sub folder right there with the exe. However none of the versions I've found actually work with CreatePkgDef.exe which was my backup plan, as it now throws this error instead:
CreatePkgDef : error : ArgumentException: No Visual Studio
registration attribute found in this assembly. The assembly should
contain an instance of the attribute
'Microsoft.VisualStudio.Shell.RegistrationAttribute' defined in
assembly 'Microsoft.VisualStudio.Shell.Framework' version '15.0.0.0'
Seems to work with regpkg.exe, though I haven't tried every combination of options.

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0' exception when starting Stateful Service

I have created a new Service Fabric application in Visual Studio 2017 (version 15.7.1) and added a new service using the .Net Core 2.0 Stateful Service template.
When I try to run the service it fails to start correctly and I can see the following exception in the Diagnostic Events:
Description='Replica had multiple failures during open on _Node_0.
API call: IStatefulServiceReplica.ChangeRole(P);
Error =
System.IO.FileNotFoundException (-2147024894)
Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The system cannot find the file specified.
I fixed this by installing the Nuget package System.ServiceModel.Primitives:
PM> Install-Package System.ServiceModel.Primitives
An answer which may be useful after a Windows 11 update.
In my case, after an update of Windows 11, the application wasn't working because of this error. I had the error Could not load file or assembly System.ServiceModel, version 3.0.0.0.
After long research, I uninstalled the .net framework and re-installed it and it worked.
For this, I used the programs/Uninstall a program/Add remove windows features.
Unchecked all .net framework cases and click on the Okay button.
After the uninstall process, I checked the same cases and click on the Okay button.
Bingo!
The System.ServiceModel.Primitives has what I think is a rather odd bug. If you are using a DLL with a System.ServiceModel.Primatives dependency, then you must also install it as a reference in the project that is using that DLL. If you do not the DLL will not know where to find it and you get the dreaded "could not load file or assembly..."
As Ragtimewilly indicated you can easily add the reference through Nuget.
There may be a better way to do this - but adding it through Nuget will do the trick.

How to resolve "The located assembly's manifest definition does not match the assembly reference." error?

I downloaded source code for pdfiumviewer from git hub. I made changes to one of the projects in that solution.Then I added that project to my application and added reference of that project to one my application's project.I had to uncheck the Signing option for the PDfiumViewer project, as some of the dll in that project are unsigned.I am able to build the application successfully.But at run time when I create an object of one of the class of PDfiumviewer project.It gives me the following error:
Could not load file or assembly 'PdfiumViewer, Version=2.11.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
The version number of the assembly is correct.So, why am I getting this error?
The problem was that I had added reference of old unmodifed PdfiumViewer dll to another project.Hence, there was conflict between the two dlls (old and customized) at runtime.I removed the old dll reference and it worked.
Ive also encountered this issue, my scenario was thou that I had to add a reference from another solution into my project removing the reference was not an option - what worked for me was reinstall SQLclient from nuget package managerer on both solution. Hopes it helo someone else
The issue here is that you have a library that references v2.11.0.0 of the Pdfium library. This library could be an assembly that you built earlier, or another assembly that came from Pdfium that references this version of the library. When you built your version of the library you probably didn't use this same version number, and it wouldn't have been strong named correctly. To fix this, you can add an assembly binding redirect in your applications configuration file to redirect the offending library to your custom built one.
I wrote a program to fix this issue automatically: https://github.com/BackTrak/DependencyFixup/releases/tag/1.0.0.0
I know this question is old, but hopefully this helps out others!

FileLoadException - Could not load file or assembly

All of a suddon, I'm getting a FileLoadException when getting an instance of a class from Ninject.
The exact exception is the following:
System.IO.FileLoadException: "Could not load file or assembly 'Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
When reading the error message, it seems quite clear that it tries to load an assembly of Quartz with version 2.3.3.0 but the specified version is another... but I don't get why it even loads version 2.3.3.0.
I searched the whole solution (inclusive the .csproj) for Quartz references and every reference states v1.0.1.2.
I've searched the path on the file system for Quartz.dlls but could only find dlls of version 1.0.1.2 so I don't understand why it tries to load 2.3.3.0.
Do you know of any steps I could try to solve this exception?
Thanks in advance
Check the class library that includes Quartz. Make sure that the platform version is consistent. You can do this by right clicking on the project file and selecting properties. Then check the assembly version in the first/top most tab.
Whatever platform version you have in that class library should be consistent with the other projects in the solution.
This happens when you install some other nuget package (like Quartz.Unity) which depends on Quartz. While installing that other package if you select 'lowest' option for dependency then it would set Quartz 2.3.3.0 as dependency. However, you have Quartz 2.4.1 installed in your package. So you get the error.
Solution: While installing that other package select 'highest' option for dependency if you have highest version installed in your project.

Watin Exception [duplicate]

I am getting the following WatiN error:
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembl y 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=db7cfd3acb5 ad44e' or one of its dependencies. The
located assembly's manifest definition do es not match the assembly
reference. (Exception from HRESULT: 0x80131040) File name:
'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=db
I copied the shDocvw.dll from System32 to the bin directory but still it is giving me the same problems.
If you've installed and referenced WatiN using NuGet in VS2010, you should already have the correct references, so they don't need to be removed and re-added. But you will still need to change the "Embed Interop Types" setting to False on the Interop.SHDocVw reference.
UPDATE: This answer was written before Nuget was released and applies only if you are NOT using Nuget to manage your dependencies. If you are using Nuget see the answer by #Nick Jones
I just had this issue today. You need to download the latest version of WatiN (I'm using 2.0.10.928) and reference the signed Interop.SHDocVw.dll that is provided by WatiN.
Try the follwoing:
Remove all other References to Interop.SHDocVw.dll
Right Click your solution and select 'Clean Solution'
Reference the Interop.SHDocVw.dll that is provided by WatiN
Build your solution.
Hope this helps.
UPDATE: Nick Jones is correct. This should not be an issue if you are using NuGet....but I was also getting this message when using MvcContrib.Mvc3.TestHelper-ci. At first glance it seems like the '-ci' packages is the way to go but I decided to use the MvcContrib.WatiN package for two reasons.
1) I don't get the "Could not load file or assembly" error message
2) The MvcContrib.Mvc3.TestHelper-ci is using an old version of WatiN.Core.dll (1.3.0.4000) where as the MvcContrib.WatiN package is using a newer version (2.0.0.99)
Check out the Properties of the Reference "Interop.SHDocVw.dll". Change the "Embed Interop Types" to False.
The problem is that it is not copying the dll file in your bin folder. But after this setting, it will do it properly.
I had the same error, and now its working fine.

Categories

Resources