Request.CreateResponse missing - asp.net-web-api

Visual Studio 2019 new project Core, webAPI template project.
Controller file that comes with the project starts as such (I added .Net namespaces)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Net.Http;
using System.Web;
namespace testwebapi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase
{
public HttpResponseMessage Get(string gender = "All")
{
Request.CreateResponse()
}
}
}
however the .CreateRequest() does not exist. Request is (AspNetCore.Http.HttpRequest ControllerBase.Request) and I think that is wrong but I do not know how to do it correctly.

looks like I was using the wrong project type.
it does not appear to exist in the Core version of Api web. I still need to learn the difference and why that is

Related

IApplicationBuilder does not includes a definition for UseHealthChecks

As suggested at the tutorial for kubernetes health check I like to implement the health chack at my .NET Core WebApi at class startup.cs at method Configure.
But the method .UseHealthCheck() is unknown.
I don't know what creates this problem. I guess all usings are there?!?
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/health");
app.Run(async (context) =>
{
await context.Response.WriteAsync(
"Navigate to /health to see the health status.");
});
here the using:
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
How to fix this problem?
Thanks for your help!
Frank
Thanks mxmissile!
I add the NuGet package
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
and there for also and first
Microsoft.AspNetCore.Http.Features 2.2.0
Microsoft.AspNetCore.Http.Abstractions 2.2.0
Microsoft.Net.Http.headers 2.2.0
Now the method is known.
I've found you only need to install these two
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
Microsoft.Extensions.Diagnostics.HealthChecks 2.2.0

.Models does not appear in using ProjectName."Models" in asp core2 empty application

I'am starting on an empty template and following implemented stuffs on aspcore2 mvc template but when I tried to do using MyProject.Models the .Models does not appear only the .Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Webeu.????
namespace Webeu.Controllers
{
public class HomeController : Controller
{
}
}
Solved it by adding a new Model in Models folder. I guess that how it works(The Models folder must not be empty to do this).

MvvmCross ShowViewModel method missing

I followed the documentation on testing on the MvvmCross website. I'am able to register my mock dispatcher and everything works except when any of my view models executes ShowViewModel. This gives me a System.MissingMethodException.
My test class is a class library (.Net 4.5).
I have a WPF application, and everything works fine in there. But for some reason, my test class library gives me this problem. I've removed/reinstalled all NuGet packages, unchecked/checked all references to my PCL where the view models I'm testing are located.
1) Why am I getting this exception?
1.1) Could it be some dll that I'm missing?
2) Where is the actual concrete definition for ShowViewModel? The only reference I can find is in MxvNavigationObject, but that's an abstract class.
Is your Viewmodel class (where I hope you are trying to call it) inheriting from MvxViewModel? as that is where the ShowViewModel method is (via MvxNavigatingObject)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MvvmCross.Core.ViewModels;
namespace App1.ViewModels
{
public class MainViewModel : MvxViewModel
{
public MainViewModel()
{
ShowViewModel(typeof(SecondViewModel));
}
}
}

SHA256CryptoServiceProvider not working in Xamarin

I create cross-platform project Xamarin.Forms (shared) in Visual Studio 2015, add one page; and I need SHA256CryptoServiceProvider, but i have a problem:
"Error CS0246: The type or namespace name 'SHA256CryptoServiceProvider' could not be found (are you missing a using directive or an assembly reference?)"
MD5CryptoServiceProvider - working good.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Xamarin.Forms;
namespace App1
{
public partial class Page1 : ContentPage
{
public Page1 ()
{
InitializeComponent ();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
}
}
}
It is because this class... really doesn't exist. Why? Using Xamarin, you are using portable .NET which lacks some of the full .NET features. I'm afraid you need to use some external libraries like PCLCrypto to fulfill your needs, or implement it by yourself (this is what I've done when I needed hash function in my Xamarin App)

asp.mvc unit test viewresult problem

I am trying to write my first test class. There is something wrong with the ViewResult.
var result = controller.Delete as ViewResult;
ViewResult is uderlined and says "the type or namespace "ViewResult"couldn't be found.."
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Bordo.WebSite.AdminUI.Controllers;
What am I missing?
Thanks.
Make sure that you have referenced the System.Web.Mvc assembly in your unit test and that your unit test project targets .NET 4.0 otherwise you might not see it in the Add Reference list.
Also shouldn't this line:
var result = controller.Delete as ViewResult;
be:
var result = controller.Delete() as ViewResult;
assuming Delete is a controller action?
ViewResult is in the System.Web.Mvc namespace so you are missing:
using System.Web.Mvc;
If its not an option you can browse to references and add a reference to System.Web.Mvc
What version of .NET and Visual Studio are you using?

Resources