VS 2019, VB, Class Library, getting error "Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral" during RegAsm - vb.net

It's my 1st time trying to build a .DLL in .Net, for use with a VB5 program...I'm a newbee
Windows 10, VS 2019, VB, building a Class Library Target framework is .NET Core 3.1.
RestSharp 106.15.0 in Assemblies, Newtonsoft.Json 13.0.1
getting error
"C:\Users\User\Desktop\PSMdata\aaaOther>regasm.exe IQProLnk.dll /tlb:IQProLnk.tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
RegAsm : error RA0000 : Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
I've looked at everything I could find doing a Google search.
I've tried adding a System.Runtime through NuGet, but all I could find is 4.3.1.... it still wants 4.2.2.0
As suggested by someone who did a C# program and had the same problem, I've added (to no avail):
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken= "b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
to "C:\Users<user>\AppData\Local\Microsoft\VisualStudio\16.0_cd2f1afe\devenv.exe.config"
Some one suggested "modify the app.config entry to match packages.config for the newVersion", but I cannot find either one of those config files. But this was for VS 2017 anyhow.
I've searched all the files in the IQProLnk subdirectories for any reference to System.Runtime and all I found was this in the IQProLnk.vbproj file after I added System.Runtime in NuGet
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>
Otherwise I don't know what it is that wants v4.2.2.0.
I hope I haven't been to verbose but did give enough information.
Thanks

Related

Azure shareclient works in one project and throws exception in another

I have a vb.net solution with a separate project containing a file class to access Azure files and 2 projects. In both I call the file class which contains this code
Dim mascThis as ShareClient
... mascThis is initialized ...
If mascThis.Exists.Value then ... do something ..
In one project this works, in the other I get the message
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I've seen this problem discussed before (assembly issues), but all projects are in the same solution in to which I added Azure.Storage.Files.Shares 12.8.0 via Nuget and only the "File class" project has a reference to it, the other projects don't.
So what am I missing here?
Please check if any of the below is your case.
Sometimes, we will have the situation where different parts(projects) of our solution depend on different versions of the same DLL i.e; assemblies with the same assembly name.
The error
Could not load file or assembly
'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
suggests , your project is looking for assembly version 4.0.4.1
Work arounds
i. Usually Nuget Package 4.5.3 contains assembly version 4.0.4.1.
Please check if both the projects in your solution can be worked on that assembly version and add that particular version as new version(ex:4.0.4.1) through binding redirect in the project where you are getting error. And keep the old version in place of old version.
Also Right click on the package reference and set 'specific version' to false under its properties
Example:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
In this example ,this way of adding specifies that the runtime should use version 4.0.6.0 in the Assembly versions between olderversion range 0.0.0.0-4.0.6.0
Else If above is not the case, the solution might need different versions.
ii.
Right click in the project properties and choose the ApplicationConfiguration file and App.config
Add the following settings in the app.config file.
To configure multiple assemblies with the same name through codeBases.
Sample code for some package say “A” :
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="A " publicKeyToken="3d67ed1f87d44c89" />
<codeBase version="3.0" href="...\A.dll"/>
<codeBase version="5.0" href="...\A.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
iii. See if you could solve that problem by using extern alias.
iv. Binding redirects are added if your app or its components reference more than one version of the same assembly .See Enable or disable autogenerated binding redirects | Microsoft Docs .If you do it manually ,you need to disable under project properties.
Manually you can add <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> in csproj file in property group.
Ex:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
References that can be helpful.
SO reference
Referencing Multiple Versions
load same assembly of different version-SO

ASP.Net Core dll binding redirect not working

I have a ASP.Net Core project which references a .Net Framework library (our own lib). This library references two 3rd party libraries. The two 3rd party libs reference RestSharp but different versions. The 3rd party lib that references that old RestSharp version fails with the error
Could not load file or assembly 'RestSharp, Version=105.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
In a .Net framework app, I would have created a binding redirect in the config file which would have worked, but I dont know how to get the same result in .Net Core app.
I tried adding the following binding redirect in the app.config file of the .Net Core app but that did not work. I also added a app.config file in our library with the redirect but that did not work as well.
<dependentAssembly>
<assemblyIdentity name="RestSharp" publicKeyToken="null" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-105.0.1.0" newVersion="106.3.1.3" />
</dependentAssembly>
Has anybody got a solution for this issue?

System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a has a higher version than referenced assembly

I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1.
I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below.
The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works.
Does anybody have any suggestion how to solve this issue?
Steps I've done:
Modify the setting for the project
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
<RazorCompileOnBuild>true</RazorCompileOnBuild>
</PropertyGroup>
I also added binding redirect in the web.config
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0"
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
Install .net core 2.1 on the server
I also deleted my .vs folder and close my visual studio and open it again.
Exception :
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:error CS1705: Assembly Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I had same problem. When I added the Views folder from the solution to the publish folder then the problem went away. For some reason Razor requires these source files to be present in the server AND up-to-date even when it compiles them also into .dll. Therefore it is strange indeed that the Views folder is not automatically copied during publish.
I personally made a junction like this
junction "MyProject\bin\Release\netcoreapp2.1\linux-x64\publish\Views" "MyProject\Views"
Alternatively, disabling the following line might help (have not tested but this issue seems to be related since in earlier versions of Net.Core there was no Razor compilation).
<RazorCompileOnBuild>true</RazorCompileOnBuild>
to
<RazorCompileOnBuild>false</RazorCompileOnBuild>

How to use app.config file with a C++/CLI to configure assembly binding in VS 2012?

I am currently using the Microsoft BCL Async library (here) across a project with a large number of interdependent assemblies all compiled against .NET 4 Full Profile, I have had to use assembly binding redirect in each project to get it to compile (as per issue 2 here).
The problem I now have is that I consume one of these libraries from a C++/CLR DLL project, it does not actually need to use async but I have the following compilation error:
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3268: The primary reference "ImInterface.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "ImInterface.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
I have added the same app.config file that I have used in all of the C# projects but it does not seem to be having any effect in the C++ project. Do I have to place it in a specific directory or perform any other steps to enable the app.config file to be recognised?
The content of my app.config file is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.11.0" newVersion="2.5.11.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.11.0" newVersion="2.5.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Any suggestions are appreciated!
Regards,
Anthony
I had the same problem and as it turned out, <SpecificVersion>True</SpecificVersion> helped.
Before you continue reading, note that the problem seems to only happen when the C++/CLI project is built using the "Visual Studio 2012 - Windows XP (v110_xp)" platform toolset! That is if you don't need to create a DLL which is compatible with WinXP, switch to "Visual Studio 2012 (v110)" instead and you should be fine.
Let me elaborate my scenario:
I have a C++/CLI console application project (ConsoleAppCLI) targeted for WinXP (v110_xp). ConsoleAppCLI references a library (AsyncLib) which has Microsoft.Bcl.Async installed via NuGet:
[ConsoleAppCLI.vcxproj] (C++/CLI, .NET 4.0 v110_xp)
|
|
[AsyncLib.csproj] (C#, .NET 4.0)
|
|
[Microsoft.Bcl.Async] (via NuGet)
I had the exact same problem and the app.config didn't help either, but what did help was the following:
Unload ConsoleAppCli.vcxproj
Edit the vcxproj File directly
Find the reference to the library which has the Async nuget package installed (in my case, a <ProjectReference> to AsyncLib.csproj)
Between <ProjectReference> and </ProjectReference>, ADD THE FOLLOWING: <SpecificVersion>True</SpecificVersion>
Note however, that ConsoleAppCLI was my top-level project in the dependency tree. If you have Assemblies which depend upon the C++/CLI assembly which produced MSB3268, you likewise have to add <SpecificVersion>True</SpecificVersion> to the reference (e.g. if i had an additional C# library which has ConsoleAppCli as dependency, i would have to make the reference to ConsoleAppCli <SpecificVersion>True</SpecificVersion> as well).
This solution is coming from over here, by the way.

Error Running Code Analysis in VS2012

I receive the following two errors when I try to compile my MVC4 web project:
CA0058 Error Running Code Analysis CA0058 : The referenced assembly 'DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' could not be found. This assembly is required for analysis and was referenced by: C:\Users\bflynn\Visual Studio Sites\mnp\bin\mnp.dll, C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\Microsoft.Web.WebPages.OAuth.dll. [Errors and Warnings] (Global)
and
CA0001 Error Running Code Analysis CA0001 : The following error was encountered while reading module 'Microsoft.Web.WebPages.OAuth': Assembly reference cannot be resolved: DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246. [Errors and Warnings] (Global)
I recently added the DotNetOpenAuth.AspNet package to the application, and it seems tied to that. I have Cleaned, Rebuilt, Open/Closed the program, Uninstalled/Re-installed the package, yet the errors persists.
I just ran into this too.
Don't upgrade DOA to 4.1
It looks like the aspnet dll has a specific version referenced. Altough it's .nuspec file says 4.0+ is ok...
Solution:
Uninstall-Package -Force each DotNetOpenAuth package (core /aspnet /oauth/openid etc)
Install-Package DotNetOpenAuth.AspNet -Version 4.0.4.12182
I used this to resolve the issue:
1. Uninstall-Package Microsoft.AspNet.WebPages.OAuth –RemoveDependencies
2. Install-Package DotNetOpenAuth.AspNet -Version 4.0.4.12182
3. Install-Package Microsoft.AspNet.WebPages.OAuth
I ran into the same issue the other day and reported it http://aspnetwebstack.codeplex.com/workitem/443
Problem was reported on 21. september 2012. (http://aspnetwebstack.codeplex.com/workitem/443)
It was closed on 5. june 2013 with message:
The next version of MVC will not have a dependency on DotNetOpenAuth. Use the recommended workarounds below.
So I used the workaround https://stackoverflow.com/a/12847018/1016682
Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API
See Yao's answer. The only solution I found that actually works for this.
I had the same issue. Though the code analysis issue got fixed, the web application wouldn't run because of the following error.
Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It turned that the web.config was not cleaned as part of the uninstall.
I had to remove the following dependentAssembly from web.config under the runtime/assemblyBinding section.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
</dependentAssembly>
</assemblyBinding>
</runtime>
The details can be read in http://www.bigcode.net/2013/07/error-running-code-analysis-in-vs2012.html