The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime" from TeamCity - teamcity-9.0

I'm getting the above error from our TeamCity build.
I have tried adding the following lines to the web.config.
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
I have also installed the latest Windows SDK for .NET4.5.2.
Neither of these have resolved the error.
Any ideas?

Finally found a solution to this problem. I added a reference to the System.Runtime.dll assembly to my project. I added a reference to the following file to my project (substitute your own version of .NET in the path as necessary). You could always copy the file to your project folder and link it from there as an alternative.
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades
This worked for me and hopefully will work for someone else.

Related

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

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

How to resolve warning messages of type: No way to resolve conflict between DLLs

I have a Windows service application made with VB.NET under Visual Studio 2013 and using NET Framework 4.5. I am using Nuget in this project.
Once I build the solution (it builds successfully) I get below warning messages in the results window:
No way to resolve conflict between "Microsoft.ReportViewer.ProcessingObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" and "Microsoft.ReportViewer.ProcessingObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "Microsoft.ReportViewer.ProcessingObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" arbitrarily.
No way to resolve conflict between "Microsoft.ReportViewer.DataVisualization, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" and "Microsoft.ReportViewer.DataVisualization, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "Microsoft.ReportViewer.DataVisualization, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" arbitrarily.
No way to resolve conflict between "Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" and "Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" arbitrarily.
No way to resolve conflict between "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from version "9.0.0.0" [] to version "11.0.0.0" [C:\MyProjects\WindowsServices\MyService\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll] to solve conflict and get rid of warning.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3276: Microsoft.Common.CurrentVersion.targets Found conflicts between different versions of the same dependent assembly.
Please set the "AutoGenerateBindingRedirects" property to true in the project file. For further information, see http://go.microsoft.com/fwlink/?LinkId=294190.
I have been searching for information about this, and I have found some posts and blogs talking about that:
No Way to Resolve Conflict Between dlls
No Way to Resolve Conflict Between dlls
I have tried to clean up all the references in the VB.NET project that were not being used but above warning messages continue appearing.
Also I have gone into Manage NuGet Packages but I have not seen any duplicate packages in the list.
I don't see the duplicates anywhere (vbproj project file, app.config, etc.). Where can I find those duplicates? Where are the duplicates? How to search for the duplicates?
Finally, I know there is another way to resolve those conflicts (I have not tried yet) and it consists on adding binding redirects for all the assemblies that are conflicted in the app.config file. For example, in case of ClosedXML DLL:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ClosedXML" publicKeyToken="fd1eb21b62ae805b" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.85.0.0" newVersion="0.85.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Instead of adding manually confliting assemblies in the app.config file, I know it can be done automatically by Visual Studio by adding the property entry below in the vbproj project file:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
as explained here.
Anyway, I would like to resolve those conflicts without binding redirects for all the conflicted assemblies in the app.config file. So Is that possible? If so, how?
Also I have some other questions in mind:
Binding redirects for conflicted assemblies in the app.config file
is a good practice?
Why those conflicts between assemblies happen? I do not understand it at all, so please could you explain me this?
What happens if I not resolve those conflicts and I ignore them (since solution is build successfully without errors)? Is it mandatory or highly recomended to resolve them for any kind of reason that I currently do not know?

Could not load file or assembly 'Microsoft.AspNet.Web.Optimization.WebForms' or one of its dependencies. The system cannot find the file specified

I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)
Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization

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>

MSBuild: building website using AspNetCompiler - adding references?

I'm attempting to build a ASP.NET website using MSBuild - specifically the AspNetCompiler tag. I know that, for my project, I need to add some references. Within Visual Studio I have several references, one is a project reference and the others are some DLLS (AjaxControlToolkit etc). I'm happy not referencing the project and referencing the DLL instead - however I just can't work out how to add a reference. I've looked up and down and this is what I've found so far:
<Target Name = "PrecompileWeb">
<AspNetCompiler
VirtualPath = "DeployTemp"
PhysicalPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\WorkingDirectory\VSS"
TargetPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\PreCompiled"
Force = "true"
Debug = "true"
Updateable = "true"/>
</Target>
Also - I've picked up this bit of code from around the web somewhere, which I thought might help:
<ItemGroup>
<Reference Include="My.Web.DataEngine, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\AutoBuild\CruiseControl\Projects\Components\My.Web.DataEngine\bin\Debug\My.Web.DataEngine.dll</HintPath>
</Reference>
</ItemGroup>
What I want to do is add a attribute to the AspNetCompiler tag, something like:
References="#(Reference)"
but MSBuild isn't very happy about this.
I've been a bit stuck in not being able to find decent references on doing this anywhere: so I'd really apprechiate some pointers or reference material etc. (or just the answer!)
Thanks for you help.
-tom
The aspnet_compiler tool doesn't have a reference property.
Have you looked at using Web Deployment Projects (2005 version)?
You can add references to assemblies used during the compilation of an ASP.NET application by adding to the <assemblies> element, under <compilation> if your web.config. For example:
<compilation targetFramework="4.6.2" debug="true">
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
Read more here: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bfyb45k1(v=vs.100)