AspNet Core 1.1. referencing .net 4.6 project fails on runtime - asp.net-core

I have an ASP.NET Core 1.1. web application and I have successfully referenced it to a .NET 4.6 class library.
When a call is made from one of the web application's controllers to one of the public methods of .NET 4.6 class library I am getting the following exception:
"Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified."
Any ideas, how I can correct that?

Related

Asp.Net Core 3.1 MVC web application compile error with SqlDateTime

I am having trouble migrating my web app from 2.2 to 3.1 regarding the use of SqlDateTime. To make sure it wasn't an issue with my migration I created a new MVC web application using the standard asp.net core 3.1 template in Visual Studio 2019 16.4. When I add a variable and assign it to SqlDateTime I get a compilation error...
The type 'SqlDateTime' exists in both 'System.Data.Common,
Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and
'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
Previously it used to work when using System.Data.SqlClient but I know that this has been replaced in 3.0 with Microsoft.Data.SqlClient however the latter doesn't have SqlDateTime so the only way to get it is by using System.Data.SqlTypes but this produces the compilation error. I haven't even included System.Data.SqlClient so I'm a bit confused as to why it is being referenced by the compiler anyway. Any ideas?
You have 2 options.
Downgrade to 3.0, it's not supported in 3.1.
Make your own struct with the MinValue of January 1, 1753
Check here for the value and supported versions

.NET Core 2.0 console app: Could not load file or assembly System.ServiceModel version 3.0.0.0

Possibly related to ASP.NET Core 2.0 Could not load file or assembly System.ServiceModel
We are currently developing a console app using .NET Core 2.0 as framework that references a .NET Framework 3.5 WCF library.
When we execute the console app an error appears in the debug output:
Could not load file or assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
What do we have to do to get this assembly visible to the Dotnet Core 2.0 console app?

asp.net core web api + could not load assembly exception

I am creating a fresh ASP.net core web API.
I have referenced a project DLL in my web API which is again referring to system.web.application.services.dll.
The solution is building fine but getting the below exception when I call POST verb from POSTMAN.
Error details:
Could not load file or assembly 'System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified
It sounds like you're referencing a .NET Framework 4.6 (or below) DLL in your .NET Core project. You have two options:
Add a reference to System.Web.ApplicationServices in your project. You may have to browse for the actual DLL (System.Web.ApplicationServices.dll), which you should be able to find in C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
(I think this will work) Change your project to target the full .NET Framework instead of .NET Core.
You might run into other roadblocks after doing this, but it's a step in the right direction.

Self-contained Asp.net core (1.0.1) app cannot find RestSharp dll

I have an ASP.Net Core (1.0.1) web app. One of the packages it consumes itself consumes RestSharp. When built, the RestSharp dll is indeed in the app root. But when I deploy and browse to the app, I get the following error:
Application startup exception: System.IO.FileLoadException: Could not load file or assembly 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=8d483824b1b4e30c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=8d483824b1b4e30c'.
Let me be clear, here... the dll is the correct version: 105.2.3.0.
Now, if I register RestSharp to the GAC, all is well and the website works. But this is a .Net Core self-contained app and it shouldn't be looking in the GAC at all (should it??).
I'm really lost and confused. I honestly don't know what's going on, so I really could do with some help.
App folder after publishing:
MyApp/
MyApp.exe
....
....
etc.
RestSharp.dll (v105.2.3.0)
web.config
appsettings.json
UPDATE:
Sorry, I should have also mentioned that I'm targetting net46.
As mason rightly pointed out: You said "This is a .NET Core self contained app". But that's not true if you're targeting .NET Framework 4.6.

How do I add a .NET Core Class Library dll to ASP.Net core project

when I add a .NET core class library dll to my ASP.NET core project and try to use it in my code, I get the following:
FileNotFoundException: Could not load file or assembly
'Test.Core, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. The system cannot find the file specified.
I'm on .NET Core 1.1 for both projects. The dll is referenced in the project. I assume I need to add the reference of this class dll in some config file but I searched everywhere and couldn't find where.
Any help would be appreciated
Patrick
Until they fix the issue in 1.1, if possible, if you jump back to 1.0 this should not be a problem as i can get it working fine on 1.0.