How to set up ChatJS with ASP.NET 4.0? - signalr

i just want to set up ChatJs with asp.net 4.0. i read all steps that provided with it's documentation. but i can't install to my application.
here my web application built with 4.0 framework. so may be this chatjs support greater version with 4.5. Is there any body know how i install this chat application with asp.net 4.0 with sql server 2008.
i successfully set up all basic files like chatjs and signalR to my web app but here at startup.cs file gives some compile time error.
here is my startup.cs file code :
using ChatJs.Admin;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(Startup))]
namespace ChatJs.Admin
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
this.ConfigureAuth(app);
app.MapSignalR();
}
}
}
here is my compile time errors:
Error 1 'ChatJs.Admin.Startup' does not contain a definition for 'ConfigureAuth' and no extension method 'ConfigureAuth' accepting a first argument of type 'ChatJs.Admin.Startup' could be found (are you missing a using directive or an assembly reference?) F:\EasyWeb\App_Code\Startup.cs 11 18 F:\EasyWeb\
Error 2 'Owin.IAppBuilder' does not contain a definition for 'MapSignalR' and no extension method 'MapSignalR' accepting a first argument of type 'Owin.IAppBuilder' could be found (are you missing a using directive or an assembly reference?) F:\EasyWeb\App_Code\Startup.cs 12 17 F:\EasyWeb\
please help me..

About the absense of the ConfigureAuth method:
You are refering to this call:
https://github.com/ChatJS/ChatJs-Demo/blob/master/ChatJs.Admin/Startup.cs#L17
The reason why it's apparently missing is because Microsoft determined that the best place to put all the ASP.NET startup code is in the App_Start folder, so there's a partial class for Startup there. The ConfigureAuth method is here:
https://github.com/ChatJS/ChatJs-Demo/blob/master/ChatJs.Admin/App_Start/Startup.Auth.cs#L11
About the absense of the MapSignalR method:
The MapSignalR method is defined in the class OwinExtensions from the Microsoft.AspNet.SignalR.Core assembly. This is specific to SignalR and it will only run on .NET 4.5.
Running ChatJS 2.0 in the .NET Framework 4.0
ChatJS 2.0 will run on .NET 4.0, but only if you reference SignalR 1 instead of 2. There's no reason why ChatJS uses SignalR 2 appart from it being the latest version. Please notice that Microsoft changed the way SignalR is initialized from version 1 to 2 so the SignalR part of the tutorial won't apply.

Related

Why is ASP.NET failing to recognize the derivation of an Exception?

We are maintaining a Kentico 11-based site (.NET Framework 4.6.1 running on IIS 10/Windows Server 2019). In testing code that throws an Exception derived directly from System.Exception, the system throws HttpCompileException with this message:
C:\<path>\B2CTokenProcessor.ascx.cs(28): error CS0155: The type caught or thrown must be derived from System.Exception
This is B2CTokenProcessor.ascx.cs line 28:
catch (IdTokenException x)
and this is the definition of IdTokenException:
public class IdTokenException : System.Exception
{
public IdTokenException(string message) : base(message) { }
}
In a situation this simple, an error like this is entirely baffling to me. If the definition of IdTokenException were missing or unreachable, I'd expect to see a type could not be found message (though, in fact, when I substitute an undefined name in that catch no error is logged by the CMS or in the Event Log). The only thought I have at all is that IdTokenException is defined in a NuGet package that was imported into the project; this Exception is not raised on the development site, but happens on a test site to which the site project and NuGet package DLLs have been deployed.
Why is .NET not seeing this type as being derived from System.Exception?
I still don't understand why this manifested in the test environment and not in the development environment which is running the same .NET environment, but what solved this problem in this case was creating and installing a new version of the NuGet package that targets the same framework version as Kentico (Framework 4.6.1 as noted in the question), rather than targeting .NET Standard 2.0 as it was originally built. I suppose there is something on that dev box that includes the .NET Standard 2.0 framework definitions.

ASP.NET Core 3.1 project that is referencing a .NET 4.7.2 project in the same solution error 'System.Web.Configuration.WebConfigurationManager'

I have an ASP.NET Core 3.1 project that is referencing a .NET 4.7.2 project in the same solution. It compiles without problems but at runtime I get an error:
Could not load type 'System.Web.Configuration.WebConfigurationManager'.
I have installed the Microsoft.Windows.Compatibility package in the ASP.NET Core project, but that did not help.
Am I missing something or will this not work without some major refactoring of the .NET 4.7.2 project to not use that System.Web.Configuration.WebConfigurationManager namespace?
I have an ASP.NET Core 3.1 project that is referencing a .NET 4.7.2 project in the same solution. It compiles without problems but at runtime I get an error:
Could not load type 'System.Web.Configuration.WebConfigurationManager'
ASP.NET Core is a cross-platform framework, and ASP.NET Core use different configuration settings, for more information, please check:
https://learn.microsoft.com/en-us/aspnet/core/migration/proper-to-2x/?view=aspnetcore-3.1#store-configurations
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1
I suppose that your .NET 4.7 project might be a class library and would be called by other applications.
As above error indicated System.Web.Configuration.WebConfigurationManager could not be compatible with .NET Core application.
If possible, you can try to modify your class library (.NET 4.7 project) to pass retrieved data (you configured within web.config, or appsettings.json) from your caller app to class library method instead of retrieving data via WebConfigurationManager in class library.
Besides, you can also to modify and add additional method to make it working with ASP.NET Core configuration settings, like below.
public class MyClassLibrary
{
private readonly IConfiguration Configuration;
public MyClassLibrary()
{
}
public MyClassLibrary(IConfiguration configuration)
{
Configuration = configuration;
}
public void MethodForNet()
{
var val = WebConfigurationManager.AppSettings["mykey"];
//code logic here
}
public void MethodForCore()
{
var val = Configuration["AppSettings:mykey"];
//code logic here
}
//other methods
}

Can someone confirm .NET Core can't run a legacy .NET class library that uses System.Configuration.ConfigurationManager

I have some legacy (.NET 4.6) code that uses ConfigurationManager to access AppSettings. I'm trying to use this class library in an Azure Function v3 and it fails with error:
Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Before I spend the time to remove the dependency on System.Configuration it would be great to get confirmation (documented) that this specific scenario is not supported -- I can't find it anywhere.
Am I missing something simple for the interop or is it unsupported?
Azure Function version 2 and above based on .Net core, you cannot use the existing .net Framework (4.6) library if they are not compatible.
When you will use existing .Net framework class library, you have to put your all configuration in .Json file. There is no concept of AppSetting in function. If you have only ConfigurationManager class issue, you can do below changes
.Net Framework 4.6
public string DatabaseId
{
get
{
return ConfigurationManager.AppSettings["DatabaseId"];
}
}
**.Net Core 3.1 **
public string DatabaseId
{
get
{
return Environment.GetEnvironmentVariable("DatabaseId");
}
}
If you don't want to touch your existing code, you can use Azure Function v1 with ConfigurationManager.
Updated Answer
ConfigurationManager is back, you can see this link but I didn't found any documentation, how to use new configuration Manager. New ConfigurationManager is .netstandard 2.0 compatible.
My looking Source code I'm assuming it will read app setting from XML/JSON file but not sure how we can utilize this in .netstandard.
I have install System.Configuration.ConfigurationManager Nuget in my sample application (Console, Web and Function) but didn't get any values from JSON file.

Trying to reference a .NET 4.6.1 class library from a .NET Core project

Screenshots => http://imgur.com/a/NWsbh
I'm trying to reference a .NET 4.6.1 Class library in a .NET Core 1.0.0 project. It's added to references but whenever I try to include the "using" statement in a controller I get "the type or namespace could not be found error."
Any suggestions?
You can either only target .NET 4.6.1, and that way you would not support .net core. Or you can add #if NET461 directives in your code, and that way it will be able to find the type and namespace in the if.
your problem is that the code is unsupported in .net core, and therefore cannot build for .net core
You need to set .NET 4.6.1 as the framework for the project. In your project.json, replace the "frameworks"-section with:
"frameworks":
{
"net461": {}
}

Validate request with Request.Unvalidated() in ASP MVC 3 RC and .NET 4

I have the same problem as below:
ASP.NET MVC 3 ValidateRequest(false) not working with FormCollection
I have tried to add a reference to the System.Web.Helpers dll, and added a using System.Web.Helpers in my controller, but it wont accept Unvalidated() as a method under Request. Im using .NET 4 and MVC 3 RC.
The Unvalidated() extension method is defined in the System.Web.WebPages.dll assembly, not System.Web.Helpers.dll (but still in the System.Web.Helpers namespace)
Sorry for the confusion.

Resources