I'm working on a .net Core project, using the .net Core framework, I wanted to use DropNet package with .net Core so I added a reference to net452 framework inside my project.json:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8",
"net452"
]
}
},
Now when I try to create a DropNet client object in my controller class I've got an error:
Error CS0012 The type 'IWebProxy' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. Test3..NETCoreApp,Version=v1.0
Ok in order to fix that error I've installed microsoft.netcore.portable.compatibility package, and the error is gone, the thing is that when I do that and execute the project and try to get access to the View that I'm returning from the controller action where I'm using DropNet I get a FileNotFoundException :
FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
I'm having that problem only with that view, this is my Action Method:
public IActionResult Test()
{
DropNetClient client = new DropNetClient("gsfgsgsfg438", "6ysgsgs234cf", userToken: "w5gdfgsdfg3434d4", userSecret: "239usfgsghsf3434wyqo");
return View();
}
The problem is that DropNetClient line, if a comment that line, the view is showed, but if that line is active in there, the FileNotFoundException is thrown...
Please, don't abuse the import statement. It is there to override nuget validation when restoring packages, to install libraries which are compatible (PCL which target .NET 4.5 and Windows 8/8.1+) but do not yet have the netstandard1.6 target.
Don't EVER use it to force import net452 libraries into a .NET Core application. It won't work!!! .NET 4.5.2 libraries aren't compatible with .NET Core!!!
You only have two options:
Don't use any libraries which do not support netstandard, netcoreapp or portable-net45+win8!!!
If you need some libraries that only run with net452 and there is no replacement, then target net452 instead of netcoreapp1.0
Related
I have a legacy assembly that is still on .NET Framework 4.8 and references System.Windows.Forms.dll (for non-UI reasons, actually) and I would like to use it inside a .NET Interactive Notebook through also existing code that loads this assembly using Assembly.LoadFrom.
However, if I do that, I end up getting an exception Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.. So in my opinion, essentially the runtime is not looking into the .NET 4 GAC, because it is not a .NET 4 CLR and then expecting the assembly to be located in the same folder.
In applications that are under control, we had some good success simply changing the target framework moniker to net6.0-windows in that case, but recompile obviously is not an option for interactive notebooks.
I have seen that there is a runtimeconfig.json in the Nuget cache folder for the entry DLL:
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
However, changing the tfm setting there did not seem to work, either. What am I doing wrong?
I forgot to paste the solution here in case anybody runs into the same problem. I actually just copied the assembly from the GAC into the application folder and then, .NET Core was able to find the assembly.
I have created a console windows service .Net5.0 and now I want to use RestClient and I am getting the below error. From my service, there is a class library called Permit which I have referenced because of some functionality I want, and it is using RestSharp(106.8.0)
This is what I have done to try to fix the problem
From my windows service I have installed the same RestSharp(106.8.0) as the class library(Permit).
Downgraded/upgraded to the lower or higher versions.
Installed RestSharp.CoreNet -Version 106.8.0 / 05.2.4.0(Error:Unable to find package
RestSharp.CoreNet with version (>= 106.8.0))
Besides the above attempts, I still get the same error. How can I solve these conflicts?
Severity Code Description Project File Line Suppression State
Error CS0433 The type 'RestClient' exists in both 'RestSharp.CoreNet, Version=105.2.4.0,
Culture=neutral, PublicKeyToken=null' and 'RestSharp.DotNetCore, Version=105.2.4.0,
Culture=neutral, PublicKeyToken=null' x.Service
C:\Users\x\source\repos\development\x.Service\AuthRepository.cs 58 Active
This is from class library called Permit
This is from console windows service
I am attempting to get access to the underlying JSON object (request body) within a service call in service stack. The reason I wish to do this is to create a PATCH version of an existing service, which will only attempt to update fields that were in the JSON. Seems simple enough:
public object Patch(AddUpdateContactRequest request)
{
var json = this.Request.GetRawBody();
var keysToUpdate = JsonSerializer.DeserializeFromString<Dictionary<string, string>>(json);
return Put(request);
}
However, I get an exception from service stack when GetRawBody() is called (when service stack is calling in to .NET core):
Message: "Could not load type
'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly
'Microsoft.AspNetCore.Http, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60'."
Source: "ServiceStack"
StackTrace: " at ServiceStack.Host.NetCore.NetCoreRequest.GetRawBody() in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line
211"
TargetSite: {System.String GetRawBody()}
TypeName: "Microsoft.AspNetCore.Http.Internal.BufferingHelper"
It seems to be referencing version 3.0 of Microsoft.AspNetCore.Http, but this version does not have the namespace Microsoft.AspNetCore.Http.Internal.BufferingHelper. It looks like a version mismatch issue, but I cannot seem to make it work. I cannot see any dll version conflicts locally, I am implicitly referencing the latest version of .NET core and have the latest SDK/hosting package installed.
If this is .NET Core 3.0 this is due to a breaking change in .NET Core 3.0 which has been resolved in the latest v5.7.1 packages on MyGet.
I've just created a new API using ASP.NET Core 2.0.
I haven't coded anything yet. I just want to test the initial API template.
When I try to start my project I receive the following error:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Could not load file or assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
I do not receive any errors when building the project.
The assemby can be found at the following directory: 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.abstractions\2.0.2'.
Is that correct? Where should the 'Microsoft.AspNetCore.Hosting.Abstractions' assembly be located and why can't VS find it?
I had the same error attempting to debug a simple Azure Function App (this is using .NET core) created from the Function App template in Visual Studio 2017. Attempting to run in debugger gave me the same error. It turned out to be I had updated the Microsoft.NET.Sdk.Functions package from version 1.0.6 to 1.0.12. That was my problem. Reverted the update back to 1.0.6 and it worked fine. Hope this helps!
Please re-install the nuget package or upgrade to the latest at: https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Abstractions/
TL;DR
I'm writing a Xamarin.Android app and want to reference the NuGet package of a library of mine that is a dotnet-targeted DNX class library. When I do this, the compiler spits out the warning
The type 'DateTime' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, ...
and the IDE complains with messages like
Argument type 'System.DateTime [mscorlib, Version=2.0.5.0, Culture ...]' is
not assignable to parameter type 'System.DateTime [mscorlib, Version=4.0.0.0, ...]'
although the builds succeed and the code works. How can I change that in the library / the project.json?
Long story
At work we're currently porting our projects to project.json-type ones (Package, DNX, whatever the name is). At the moment, we're running the beta 7 Visual Studio integration and, in general, everything works out just fine.
I now want to reuse one of our model libraries within an ASP.NET 5 and a Xamarin.Android project (from a NuGet feed).
Since we had absolutely no luck with class libraries targeting .NET 4.5.1 in the Xamarin project I migrated the model library to a DNX project targeting net45, dnx45 and dotnet (in favor of dnxcore50, as described here), the frameworks part in the project.json being
"frameworks": {
"net45": {
"frameworkAssemblies": {
"mscorlib": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Collections.Concurrent": "4.0.0.0"
}
},
"dnx45": {
"frameworkAssemblies": {
"mscorlib": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Collections.Concurrent": "4.0.0.0"
}
},
"dotnet": {
"dependencies": {
"System.Collections": "4.0.0",
"System.Linq": "4.0.0",
"System.Runtime": "4.0.0",
"System.Reflection": "4.0.0",
"System.Runtime.Extensions": "4.0.0",
"System.Threading": "4.0.0",
"System.Text.RegularExpressions": "4.0.0",
"System.Text.Encoding": "4.0.0",
"System.Collections.Concurrent": "4.0.0"
}
}
},
Although this article suggests using net45 as a target for monoandroid51 projects, the dotnet library is instead referenced by the Android project whenever I add the NuGet package to it.
The package.json then contains
<package id="My.Awesome.Lib" version="1.2.3-foo9" targetFramework="monoandroid51" />
and the .csproj there has
<Reference Include="My.Awesome.Lib, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\My.Awesome.Lib.1.2.3-foo9\lib\dotnet\My.Awesome.Lib.dll</HintPath>
<Private>True</Private>
</Reference>
This works out so far unless I have version numbers higher than 4.0.0 in the dependencies part and basically combusts when I do, however the following
However when I build the project, I'll get the compiler warning
1>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1706,3):
warning MSB3277: Found conflicts between different versions of the
same dependent assembly that could not be resolved. These reference
conflicts are listed in the build log when log verbosity is set to detailed.
right after the library reference. Within Visual Studio, whenever I pass a value from the Android project to one of the library types, I'll get the red squiggly lines with a message stating
The type 'DateTime' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, ...
as well as
Argument type 'System.DateTime [mscorlib, Version=2.0.5.0, Culture ...]' is
not assignable to parameter type 'System.DateTime [mscorlib, Version=4.0.0.0, ...]'
which makes perfect sense, since the Xamarin BCL is labeled as runtime version v2.0.50727, whereas my library is v4.0.30319.
I'm now wondering if I need to target some PCL something or if there is something else I'm missing.
This is not YET supported. To support this scenario, nuget will need to also be updated to take in charge the new monikers that are being thought about to simplify the references.
In the future, you would just target netstandard1.4 instead of dnxcore50 and you would have everything running and compatible with Xamarin.
.NET Standard Platform
This is where things will be going. To simplify the madness of targeting multiple platforms. This is where I got my netstandard* moniker and of course, until it hits release... this is still subject to change.