I am following a tutorial to become familiar with server side rendering involving asp.net core and react, but I am hitting a roadblock on the HelloWorld. I am doing this alongside another co-worker and he is not getting this same issue. I have uninstalled and reinstalled all dependencies with npm to make sure there were no installation issues.
I have tried to find some answer as to what I am missing, an import etc, but cannot seem to find anyone with the same exact issue. I had looked at similar IApplicationBuilder exceptions but the solutions they usually have is try this import statement etc etc. I have uninstalled and reinstalled all my dependencies with npm. I have recreated the project three times
Below is the Configure method from my Startup.cs file.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware();
} else {
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
}
app.UseWebpackDevMiddleware(); is throwing the following error:
"Severity Code Description Project File Line Suppression State
Error CS1061 'IApplicationBuilder' does not contain a definition for 'UseWebpackDevMiddleware' and no accessible extension method 'UseWebpackDevMiddleware' accepting a first argument of type 'IApplicationBuilder' could be found"
In Package Manager run Install-Package Microsoft.AspNetCore.SpaServices.Extensions
Related
When I try to deploy my project it fails with the following message:-
Startup.cs(75,25): error CS1061: 'IMvcBuilder' does not contain a definition for 'AddRazorRuntimeCompilation'
and no accessible extension method 'AddRazorRuntimeCompilation' accepting a first argument of type 'IMvcBuilder'
could be found (are you missing a using directive or an assembly reference?)
I found an answer here How to fix 'IMvcBuilder' doesn't contain a definition for 'AddXmlDataContractSerializerFormatters' however after installing the suggested MVC formatter package(s) The issue persisted.
The only way I have been able to deploy is to comment out the following lines in my startup class
var builder = services.AddRazorPages();
if (Env.IsDevelopment())
{
builder.AddRazorRuntimeCompilation();
}
Maybe I need to update something on the deployment server? It is the organisation's first DotNet Core 3.1 application
You need to install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation, but not the latest version. Something compatible with .Net Core 3.x.
E.g.
Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 3.1.19
In my Main method of .net Core app Iam getting this error and I dunno where should I look for solution.
this is my main method:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
This is error message I am getting when hit F5 to fire project:
System.MissingMethodException: 'Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.'
I've just come across this issue using aspnet core 2.0, in my case upgrading the other default packages (AspNetCore, AspNetCore.Mvc, NetCore.App) to 2.0 did the trick, despite installing 2.0 the packages (apart from App insights) were 1.1.x initially
If you use Microsoft.AspNet.OData, this error occurs from NuGet version 7.5.15 and above. Downgrading to 7.5.14 may resolve this issue.
For .NET Core 3.1, for some reason Visual Studio wasn't giving me the hint that I need to add using Microsoft.Extensions.DependencyInjection;. Manually adding that fixed it for me.
Downgrade package ApplicationInsights to version 1.1.2 from 2.0 solved
I had similar issue when using Sql nuget and upgrading that fixed the issue.
IDbContextFactory had to be changed to IDesignTimeDbContextFactory
I also experienced this error with Microsoft.AspNet.OData version 7.5.17 and downgrading to 7.5.14 resolved this error.
After building and successfully running a self-hosted NancyFx application on windows with visual studio I went on and tried to run the application on linux with mono. I was able to build the solution (using xbuild) but when running the app I get a strange error:
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.TypeLoadException: Could not load type 'System.Net.HttpListener'
from assembly 'System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Initialize (IDictionary`2 properties) <0x413ae4f0 + 0x000eb> in <filename unknown>:0
For some reason, the app tries to initialize class HttpListener from the System assembly, but HttpListener lives in System.Netassembly. I looked in the GAC folder and found that System.Net is there as expected. I moved a copy to the bin folder where the other dependencies of the app live but that didn't solve the problem. Any help would be appreciated!!
here is my OWIN-related code:
// Startup.cs
using Owin;
namespace MyApp
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseNancy();
}
}
}
// Program.cs
using System;
using Microsoft.Owin.Hosting;
namespace MyApp
{
public class Program
{
static void Main(string[] args)
{
var url = "http://127.0.0.1:8080/";
using (WebApp.Start<Startup>(url))
{
Console.WriteLine("Running on {0}", url);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}
}
}
}
Yep, wrong assembly indeed.
Im not sure why yet, but I'm having the same issue with CENTOS only using mono 4.3.178. Debian Jesse using version 4.2.x had no issues. Several other Debian Jesse boxes I use to test seem to have no issues with 4.3.x. In my case I'm listening on an alternate port.
RedHat Strikes Again :/
A MUCH deeper stack trace into the IL seems to indicate that gcc on the machine you built mono on, and also the build essentials package have some extremely dated libs and even the compiler. I was surprised to see the number of warnings, nearly 70,000 as opposed to a typical 400 depending on the diversity of libs you have. I have about 10 hours to figure this out, so hopefully its not too bad.
I'm attempting to minify my .JSX files with ASP.NET Minification and Optimization via System.Web.Optimization.React. I've installed the MVC4 React Package as well as the Optimization package, but whenever I try to include a bundle I get the following:
React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.IReactEnvironment
The InnerException is always null
My bundles are setup as follows:
bundles.Add(new ScriptBundle("~/Bundle/Scripts/ReactJS").Include(
"~/Scripts/React/react-0.12.2.js",
"~/Scripts/React/react-with-addons-0.12.2.js",
"~/Scripts/React/JSXTransformer-0.12.2.js"
));
bundles.Add(new JsxBundle("~/Bundle/Scripts/ReactCalendar").Include(
"~/Scripts/React/Calendar/Main.react.jsx",
"~/Scripts/React/Calendar/Components/Calendar.react.jsx",
"~/Scripts/React/Calendar/Components/CalendarEvent.react.jsx",
"~/Scripts/React/Calendar/Components/CalendarControls.react.jsx",
"~/Scripts/React/Calendar/Components/CalendarTimeSlots.react.jsx"
));
And included in the view as:
#section scripts{
#Scripts.Render("~/Bundle/Scripts/ReactJS");
#Scripts.Render("~/Bundle/Scripts/ReactCalendar");
}
The error is always thrown on line:
#Scripts.Render("~/Bundle/Scripts/ReactCalendar");
Anyone got any ideas on how to solve / debug this one? Let me know if more info is needed.
I'm not sure if this is the same issue I was facing, but I googled the exact same error, found this SO topic as the first hit, with no definitive answer, so I thought I'd offer my solution.
I'm using .NET 4.5 in an MVC app, and React.Web.Mvc4 v3.0.0.
I managed to work around this issue with the help of this comment on Github.
Here's my entire ReactConfig.cs:
using React;
using React.TinyIoC;
using React.Web.TinyIoC;
namespace NS.Project
{
public static class ReactConfig
{
public static void Configure()
{
Initializer.Initialize(AsPerRequestSingleton);
ReactSiteConfiguration.Configuration
.SetLoadBabel(false)
.AddScriptWithoutTransform("~/React/dist/server.bundle.js");
}
private static TinyIoCContainer.RegisterOptions AsPerRequestSingleton(
TinyIoCContainer.RegisterOptions registerOptions)
{
return TinyIoCContainer.RegisterOptions.ToCustomLifetimeManager(
registerOptions,
new HttpContextLifetimeProvider(),
"per request singleton"
);
}
}
}
Then, I'm callingReactConfig.Configure explicitly from Application_Start.
"Unable to resolve type: React.IReactEnvironment" with no InnerException generally means ReactJS.NET is not initialising properly for some reason. In web apps, ReactJS.NET handles initialisation through the use of WebActivator. Make sure your project is referencing React.Web, React.Web.Mvc4 and WebActivatorEx, and all the corresponding .dll files are ending up in your app's bin directory.
Also, you do not need to (and should not) include JSXTransformer in your JavaScript bundles, as ReactJS.NET does all the JSX compilation server-side.
Something looks like changed from React.Web.MVc4 version 4.0.0. versions before didnt have that problem.
as stated here
Install the React.Web.Mvc4 package through NuGet. You will also need to install a JS engine to use (either V8 or ChakraCore are recommended). See the JSEngineSwitcher docs for more information.
To use V8, add the following packages:
JavaScriptEngineSwitcher.V8
JavaScriptEngineSwitcher.V8.Native.win-x64
ReactConfig.cs will be automatically generated for you. Update it to register a JS engine and your JSX files:
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.V8;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(React.Sample.Mvc4.ReactConfig), "Configure")]
namespace React.Sample.Mvc4
{
public static class ReactConfig
{
public static void Configure()
{
ReactSiteConfiguration.Configuration
.AddScript("~/Content/Sample.jsx");
JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName;
JsEngineSwitcher.Current.EngineFactories.AddV8();
}
}
}
If anyone needs this, just install this nuget and it will resolve this issue.
System.Web.Optimization.React
I am getting this error
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?)
This is my code
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(VirtualClassroom.Startup1))]
namespace VirtualClassroom
{
public class Startup1
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I searched a lot and tried as per stack overflow answer
'Owin.IAppBuilder' does not contain a definition for 'MapSignalR' I had
1.Added Microsoft.Owin //version 2.0.1
2.Added Microsoft.Owin.Security //version 2.0.1
3.Added Microsoft Asp.Net SignalR
But still I am getting the same error. Please help. Thanks in advance!!
It looks like you have an old version of Microsoft.AspNet.SignalR.Core.dll, go to nuGet and install this package and you should see this extension method...
You should then see a bunch of these methods public static IAppBuilder MapSignalR(this IAppBuilder builder); under OwinExtensions.
EDIT: Based on comment
Go to references, and click on properties of this reference...
The version should be similar to below...