WebSocketTransport not available in Class Library (Portable) - c#

I am trying to figure out why NuGet is not downloading the correct version of Microsoft.AspNet.SignalR.Client.
To make this as easy as possible to understand, here are my projects:
A WPF project, targeting .NET 4.6
A UWP project, targeting .NET 4.6 according to the new project dialog
A Class Library (Portable) project, targeting .NET 4.6 and Windows Universal 10.0, according to the "Targets" property.
All 3 projects have the NuGet package Microsoft.AspNet.SignalR.Client, and both the WPF and UWP project have the class Microsoft.AspNet.SignalR.Client.Transports.WebSocketTransport available. If I copy the class created in the WPF project to the UWP project, it finds all the references and it doesn't give me any error; however, if I try to do the same to the Class Library, it fails to find the WebSocketTransport class.
If the Class Library project has the same target as the UWP project, why isn't the WebSocketTransport class available?
Class Library (Portable) project.json:
{
"supports":
{
"net46.app": {},
"uwp.10.0.app": {}
},
"dependencies": {
"Microsoft.AspNet.SignalR.Client": "2.2.0",
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
Universal Windows project.json:
{
"dependencies":
{
"Microsoft.AspNet.SignalR.Client": "2.2.0",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks":
{
"uap10.0": {}
},
"runtimes":
{
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
Is there any way I can make the Class Library project download the NuGet package that contains the WebSocketTransport method? The SignalR hub I need to use allows only WebSockets.

I was able to "hack" this by using the AutoTransport class, which seems to have chosen the WebSockets transport correctly upon contacting the Hub, otherwise it would have failed to connect:
await connection.Start(new AutoTransport(new DefaultHttpClient()));

Related

create a nuget to share between linux and windows

I have an asp.net form application using .net 4.6.1 running on windows
and a linux application using .netcore 1.1
I want to make a nuget that can be shared between both application.
I created a .net core library and it works pretty fine with my linux application
here is its project.jso
{
"version": "0.1",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"StackExchange.Redis": "1.2.0"
},
"frameworks": {
"netstandard1.4": {
"imports": "netcoreapp1.0"
}
}
}
I can add my nuget package to the windows application and build it with no error, but when I want to run the application I'm getting all erros like:
Could not load file or assembly 'System.Diagnostics.DiagnosticSource,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
i'm using .net 4.6.1 so I believe it's .net core that is nagging
i can check in here and confirm that it's a .net core library.
I also setup the .net library in the production server. but still i'm getting the same error.
I tried all possible combination and version that i thought it would be logical. and have no clue how to solve it.
Im not sure why you say you are using net 4.6.1. Because you are using netstandard1.4 as framework, looking at your project.json file.
Try the following project.json file:
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"StackExchange.Redis": "1.2.0"
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
}
}
}
Make sure the production server has the runtime installed and Microsoft.NETCore.App-1.1.0

How to test a controller in .NET Core

I have an ASP.NET Core application (NetCoreApp1.1) Web API project and I would like to test a controller of that project. I added a .NET Core class library (targeting NetStandard1.6).
Now the problem I have is that according to Why doesn't Microsoft.NETCore.App support netstandard1.6? I can't reference the Web API project from that class library.
My question is then, does this mean that unless the controllers are placed somewhere else I won't be able to test them anymore? Maybe there is a way to do so but I haven't been able to achieve it in VS 2017 RC.
Test projects should be console applications, not class libraries. A console application references Microsoft.NETCore.App and shouldn't have any problems referencing your Web API project.
A simple example of the project.json for a working test project is:
{
"dependencies": {
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"xunit": "2.1.0",
"MyApiProject": {
"target": "project"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dotnet"
}
},
"testRunner": "xunit",
}
If you're using .csproj in VS 2017, it'll look different, but the principle should be the same. The test project can reference the API project locally, and uses a test runner like Xunit to run tests.

Why can't I use embedded resources (resx) when targeting .netstandard 1.3?

(Question subtitle: Are resources not supported in .netstandard 1.3 or is my project file just messed up?)
I just created an example portable class library in Visual Studio 2015 Update 3 and added a sample resource file. Initially, the file project.json looks like this:
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
Fine: No compile errors!
After that, I used the project properties to target .NETStandard 1.3.
Now project.json looks like this:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": {}
}
}
Now I get the following build error - which means basically the the build action EmbeddedRessource is not supported:
I'm really no expert with project.json, but for me the things look inconsistent - and I have no idea, where the problem is.
in the first project.json: if I support net46, why is it importing net452?
in the second project.json: if I use netstandard1.3, why is there a dependency to the library in version 1.6?
and finally, what is .NETPortable, Version=v5.0? The renaming of .NET Core has taken place early this year - why are we still referencing version 5.0? Even MSDN doesn't know <TargetFrameworkVersion>5.0</TargetFrameworkVersion> which is specified in the csproj
For me, this seems like netstandard isn't only about the available libraries, tooling seems involved, too. But that does not explain, why it worked for dnxcore50.
You need Diagnostics.Tools and Resources.ResourceManager.
I got this working (for .NET Standard 1.4 though) by installing the pre versions, at this time:
"System.Diagnostics.Tools": "4.3.0-preview1-24530-04"
"System.Resources.ResourceManager": "4.3.0-preview1-24530-04"

What's difference between .NetCoreApp and .NetStandard.Library?

.Net Core 1.0 has been released couple days ago, and i've started playing with it. I've created simple solution, with one project (class library => .NetStandard.Library) and second, console application (.NetCoreApp). The point is, console application has reference to library, but i cant use types form that library. Are those two frameworks incompatible? Am i missing something?
project.json for console application:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"ConsoleApplicationLibrary": "1.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
project.json for library:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
I've figured it out, that it works, and code compiles, but visual studio still highlights types from library as unknown.
The most likely issue is that .Net Core is expecting ConsoleApplicationLibrary to be a NuGet package. If you want to reference a project, use "ConsoleApplicationLibrary": {"target": "project", "version": "1.0.0-*"}.
After you do that, don't forget to restore packages.
Ok, it's strange, but after disabling resharper, restarting VS and rebuilding solution, it works fine. It seems there is prolem with resharper support for .net core. (resharper v.9.1.3). From this: resharper ultimate blog i understand that only ultimate version supports .net core for now.
.NetCoreApp is a platform and .NetStandard.Library is a library supposed to be cross platform (portable class library) for various .NET platforms runtimes.
You can include a direct reference (package) of NetStandard.Library in any of your .NET platform project that is supported, for ex .NETCoreApp (Dot Net Core 1.X)
Reference: https://learn.microsoft.com/en-us/dotnet/articles/standard/library
I had the same issue and it turned out I needed to update Resharper to it's latest version. I had v9.1.1 so I updated it to 2016.3.2 and that fixed the issue.

ASP.NET 5 Web Application that references the new Class Library (package)

I am in the process of creating a large solution that contains an ASP.NET 5 MVC Web App which targets the following frameworks:
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
I have several of the new Class Library (package) in my solution for the business layer, data layer, etc.. All of these libraries target the following frameworks:
"frameworks": {
"net451": { },
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
I have a few test projects which target the following frameworks just like my MVC web app does:
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
After doing much research I mostly found that anything that is a project like my mvc app and test libraries should target dnx and projects that act as class libraries should just keep their defaults and target net/dotnet5.4.
Can someone please tell me what I am doing wrong because from my MVC Web Application I am unable to reference items from my class libraries (DAL, BLL) unless I add dnx451 to them...
You have "dnxcore50" in your Web application and "dotnet5.4" in your dll, which are probably different sets of referenced libraries. Either your Class Library should target "dnxcore50" or your Web App should target "dotnet5.4" with all it's dependencies
I just kind of resolved similar issue.
Actually, the issue is not the inability to reference your class libraries, but lack of support from Intellisense. You can manually reference your class library in project.json of your application and then use classes from your class library in your application. And application will build and run just fine. At lease mine did build and run. But VS will still highlight your classes form class library with red color and show "Cannot resolve symbol" warning message.
To add support of Intellisense I removed "dnxcore50" from project.json of application and added "net451". So, now I have the following project.json in application:
"frameworks": {
"net451": { },
"dnx451": { }
},
I cannot just reference only "net451" because I can't start the application then. DNX just exits with code 1. But with both "net451" for Intellisense support and "dnx451" for DNX support I'm able to continue work on my project and wait for proper solution in RC2 of ASP.NET Core.

Categories