Before v2:
RouteTable.Routes.MapHubs();
In v2, MapHubs does not exist anymore. The wiki says to add a Startup class and a Configuration method and a call to app.MapHubs().
namespace MyAssembly
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//Before v2
//RouteTable.Routes.MapHubs();
app.MapHubs();
}
}
}
But the method is never called, no error occurs, and ... no hub are setup.
I suppose there is some code to add to global.asax.cs
What is the secret ?
Try defining [assembly : OwinStartup(typeof(MyAssembly.Startup))] to see if your Startup class is being picked up.
EDIT: removed lines not relevant.
Solution !
<appSettings>
<add key="owin:AppStartup" value="MyNameSpace.Startup, MyNameSpace" />
</appSettings>
plus update both MVC4 (not to prerelease, but to latest stable version) and SignalR/owin nugets.
plus fix bugs in js client :
if disconnectTimeout=999000 then it is disabled. Must be set server-side with: GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(999);
note: server side can not set a value < 6 (signalr throws an exception if DisconnectTimeout < 6). So use this magic number.
webSockets: set connection.socket = null in sockettransport, otherwise the call to start fails after a (manual) call to stop
serverSentEvents: prevent error caused by a reconnection attempt when the window is unloading
chrome fails with exception if signalr hub url not available (temporarily) : Instead of giving up try the next available protocol / try to reconnect.
I was able to get the 2.0 beta working by
Removing all references to the older version of SignalR, ie nuget uninstall of the library and double checking /bin
Installed SignalR 2.0.0-beta2 via Package Manager Console Install-Package Microsoft.AspNet.SignalR -Pre
Following the steps in the 1.x to 2.0 migration outlined here
And most importantly changing the project config to use Local IIS Web server instead of Visual Studio Developer Server (Cassini).
More info in the question/answer I posted here
In web.config there must be a fully qualified name of the class, e.g.
<appSettings>
<add key="owin:AppStartup" value="**My.Name.Space.Startup**, **AssemblyName**" />
</appSettings>
I had a problem when I put namespace instead of assembly name, but with the fully qualified name it works without any other changes to web.config!
UPDATE: I also followed the steps from the link: http://www.asp.net/vnext/overview/latest/release-notes#TOC13, i.e. removed a NuGet package "Microsoft.AspNet.SignalR.Owin"
Related
I have created a simple, stripped down project to try to get this to work: ASP.NET Core 6 WebAPI project, hosted as a Windows Service, just trying to get it up and running with the sample WeatherForecast controller. I have added NuGet package for Microsoft.Extensions.Hosting (6.0.1) and Microsoft.Extensions.Hosting.WindowsServices (6.0.0). My program.cs looks like:
using IRDSPrototype.Configuration;
using IRDSPrototype.Services;
using Microsoft.Extensions.Hosting.WindowsServices;
var webApplicationOptions = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
var builder = WebApplication.CreateBuilder(webApplicationOptions);
builder.Services.AddHostedService<IRDSHostingService>();
builder.Host.UseWindowsService();
builder.WebHost.UseUrls(UriServices.GetBaseUri().AbsoluteUri);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
await app.RunAsync();
I created a background service as well:
public class IRDSHostingService : BackgroundService
{
public ILogger Logger { get; }
public IRDSHostingService(ILoggerFactory loggerFactory)
{
Logger = loggerFactory.CreateLogger<IRDSHostingService>();
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Logger.LogInformation("IRDS Hosting Service is starting.");
stoppingToken.Register(() => Logger.LogInformation("IRDS Hosting Service is stopping."));
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
Logger.LogInformation("IRDS Hosting Service has stopped.");
}
}
I also created a service installer via Wix. When I run the installer it gets to the point of "Starting services" and fails with a message 'Verify that you have sufficient privileges to start system services'. When I check Windows Application Log, I see that error and a also see an error for:
Application: IRDSPrototype.exe
CoreCLR Version: 6.0.822.36306
.NET Version: 6.0.8
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceProcess.ServiceController, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.ServiceProcess.ServiceController, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
My publish directory and Wix manifest do include the System.ServiceProcess.ServiceController.dll.
I installed the service via sc.exe and the install succeeded, but starting the service gives an Error 5: Access Denied message. Unlike with the installer, though, this didn't generate any messages in the Windows log. I checked permissions on the folder containing the executable, giving full permissions to NETWORK SERVICE and LOCAL SERVICE. That didn't help. So I'm kind of stuck on what to do now. All my internet searches basically guided me to the setup I have now and it still doesn't work. So I'm at a loss. Anyone have any suggestions of what I'm missing here?
Thanks,
Dennis
Edit: So I'm whittling down the problem. It turns out I needed the version of System.ServiceProcess.ServiceController.dll that was published to my 'runtimes' folder under the .Net 6.0.0 runtime. So that error no longer shows up in the Event Viewer. The only erro that shows in the Event Viewer now is:
Error 1920. Service 'IRDS Prototype' (IRDSPrototype) failed to start. Verify that you have sufficient privileges to start system services
I have it installing as a Local Service and I believe I've given Local Service full permissions on the proper folders but I will check that. Still looking for suggestions though.
Edit #2: Getting closer. The problem I had when installing through sc.exe was that my binPath was wrong. I wasn't including the exe file in the binPath. Now I can install my service through sc.exe and it starts and works properly. The service still won't start when installed via my Wix installer though. So now I'm down to a Wix issue. Anyone with experience installing Windows services via Wix?
OK, it turns out what I needed to do was publish as a single executable:
Notice the "Deployment Mode: Self-contained" choice and "Produce single file" checked. After publishing that way, I only had to add the executable (no other files) to my Wix manifest and the generated installer worked fine. I'm guessing I was missing a dependency somewhere that I didn't know about. But it's weird that I was able to install and start the service from the same publish directory as I was trying previously with Wix via sc.exe. Anyway, it works now. Thanks to Md Farid Uddin Kiron for redirecting me back to the official page, which I read a little more carefully this time and found the little blurb about this being recommended.
I am working on a WebApplication which uses MVC5 and WebApi 2 with Owin. I recently updated Microsoft Asp.Net NuGet packages (Microsoft.AspNet.Mvc, etc.) from version 5.2.2 to 5.2.3, and the Owin NuGet packages (Microsoft.Owin, etc.) from 3.0.0 to 3.0.1. I also updated Microsoft.AspNet.Identity.Owin from version 2.1.0 to version 2.2.0
I then updated the corresponding Ninject WebApi packages (Ninject.Web.WebApi, etc.) from 3.2.3 to version 3.2.4 in order to get it to compile, but did not update Ninject.Web.Common.OwinHost, since this was at the latest version (3.2.3).
When I try to run the application, I get the following error:
Error loading Ninject component ICache
No such component has been registered in the kernel's component container.
Suggestions:
1) If you have created a custom subclass for KernelBase, ensure that you have properly implemented the AddComponents() method.
2) Ensure that you have not removed the component from the container via a call to RemoveAll().
3) Ensure you have not accidentally created more than one kernel.
The Kernel that I am creating in the OwinStartup class using is being disposed from the Owin.AppBuilderExtensions.CreateOwinContext() method, which is indirectly from OwinBootstrapper.Execute().
This has only started happening since updating the Asp.Net NuGet packages to 5.2.3. Before updating the packages, OwinBootstrapper.Execute() is still called, but does not cause Owin.AppBuilderExtensions.CreateOwinContext() or KernelBase.Dispose() to be called.
I have not changed any of the code in OwinStartup, and my Ninject Kernel is still being created using:
public virtual void Configuration(IAppBuilder app)
{
app.UseNinjectMiddleware(CreateKernel);
app.CreatePerOwinContext(CreateKernel);
}
I have tried updating the NuGet packages one at a time, and the specific update that causes the issue is Microsoft.AspNet.Identity.Owin to 2.2.0 Are there any known compatibility issues with Ninject and AspNet.Identity.Owin 2.2.0?
This from Hao: I think that should be fine, so long as ninject takes care of disposing the per request objects somehow
By looking at the previous source code and current source code, it looks like they are expecting a IDisposable object and calls it immediately at the end of its life cycle (aka request).
I also noticed that other CreatePerOwinContext they provide when installing OWIN such as app.CreatePerOwinContext(ApplicationDbContext.Create); was never disposed (in 2.1.0)? This seems like a big memory leak as they instantiate some classes every time there is a request.
To go around the problem when using CreatePerOwinContext with Ninject StandardKernel, I tried with the following code:
app.CreatePerOwinContext(
(Microsoft.AspNet.Identity.Owin.IdentityFactoryOptions<IKernel> options, IOwinContext context) => kernel,
(Microsoft.AspNet.Identity.Owin.IdentityFactoryOptions<IKernel> options, IKernel instance) => {}
);
Basically, I do nothing in the dispose callback.
I do not know if this will lead to some memory leak but it definitely makes the app work again.
I try to use Azure Table Storage for the persistence of timeout data and I experience an error on environments other than my local development machine.
My local machine is creating the timeout tables on Azure and is able to poll timeout data successfully. But, if I host the same software on premise on another server it failed to fetch the timeouts. I receive the following error:
2015-02-12 09:43:50,638 [10] WARN NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver - Failed to fetch timeouts from the timeout storage
System.NullReferenceException: Object reference not set to an instance of an object.
at NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver.Poll(Object obj) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Timeout\Hosting\Windows\TimeoutPersisterReceiver.cs:line 88
at System.Threading.Tasks.Task.Execute()
It seems that the TimeoutPersister is null at the point it wants to fetch data from it.
I host NServiceBus using the NServiceBus.Host. My endpoint configuration looks like this:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
public void Customize(BusConfiguration configuration)
{
configuration.UsePersistence<AzureStoragePersistence>();
configuration.EndpointName("MyEndpoint");
configuration.UseTransport<RabbitMQTransport>()
.DisableCallbackReceiver();
configuration.DisableFeature<Sagas>();
configuration.ScaleOut().UseSingleBrokerQueue();();
}
}
And my app.config contains:
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=myrabbitmqserver;virtualhost=myhost;username=me;password=secret" />
</connectionStrings>
<AzureTimeoutPersisterConfig ConnectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=myaccouuntkey;" TimeoutManagerDataTableName="TimeoutManager" TimeoutDataTableName="TimeoutData" />
Does anyone have any idea what I am doing wrong or can anyone point me in the right direction investigating what the problem can be?
Update 1
It seems that the NServiceBus.Azure assembly is not loaded on the other machines. So azure persistence features are not initialized resulting in NullReferenceException when using the TimeoutPersister.
Update 2 After some NServiceBus debugging I noticed that an exception was thrown when extracting the types from the NServiceBus.Azure.dll assembly. It is unable to load the referenced assembly Miscrosoft.Data.Services.Client.dll 5.6.0.0. This assembly is indeed not in the bin folder. The present version is 5.6.3.0. The NServiceBus.Azure NuGet package supports versions >= 5.6.0.0 < 6.0.0.0, but somehow it's still expecting version 5.6.0.0. It still feels weird that it is working on my development machine? Maybe there are some old versions of the Microsoft.Data.Services.Client.dll installed on my machine as part of the Azure SDK, which are found during the assembly loading.
Update 3
I indeed had somewhere at my system the older 5.6.0 version available. Downgrading the Microsoft.Data.xxx packages to version 5.6.0 solved the issue for now. Does anyone have the same issues using 5.6.3 versions and found a solution for that?
Update 4
Since 2015-02-13 a new version of NServiceBus.Azure is released and now it requires Microsoft.Data.Services.Client version 5.6.2.0. I am still not able to use the 5.6.3 version. Adding a assembly binding redirect will not help either.
The binding redirect must be added to the NServiceBus.Host.exe.config instead of the app.config. Pretty annoying because visual studio automatically updates the app.config.
Information from Yves Goeleven:
The reason is that default load behavior of the CLR is at the process level, which includes the host config, once the host is loaded we actively switch over to the appdomain level (using topshelf) from then on it uses the endpoint's config...
But if the CLR needs to resolve the reference prior to the switch to the appdomain, you will have to put the redirect at the host level (and at the endpoint level I guess)
It should work with 5.6.3 version. Try adding assembly bindingRedirect in the following way:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
</dependentAssembly>
I'm working on an umbraco 4.7.0 project and I have upgrated from 4.7.0 to 4.7.1
It's worked like a charm in my localhost but I have a problem after installing it on the staging server :
When I connect to the backend, I have the javascript error : "Jquery(xx).mask(...) : function does not exist" and any key press execute the umbraco Save function.
The jquery mask plugin is used in umbraco 4.7.1 to add a date mask to the publish date in the property tab.
The Jquery mask plugin is new in Umbraco 4.7.1 and is being included by "DateTimePicker.cs" with [ClientDependency(ClientDependencyType.Javascript, "MaskedInput/jquery.maskedinput-1.3.min.js", "UmbracoClient")]
See : https://hg01.codeplex.com/umbraco/rev/d2304aa897d4
However, even if I delete on the Staging server the bin,umbraco and umbraco-client folders and replace them with the ones from my local computer (where it works) the bug is still here.
But if I change
< compilation defaultLanguage="c#" debug="false" batch="false" targetFramework="4.0">
to
< compilation defaultLanguage="c#" debug="true" batch="false"targetFramework="4.0">
in the web.config THEN it works...
Does someone understand what happened ? How can I make it works with compilation debug=true ??
Thank you very much
Fabrice
As nobody answered this question, I asked on the umbraco forum here :
http://our.umbraco.org/forum/getting-started/installing-umbraco/25196-Error-loading-javascript-after-installing-Umbraco-471
The answer is :
"it's the outdated client dependency cache to blame (when you set debug="true" in your web.config this cache is turned off by design). Try simply to clean the contents of the client dependency cache folder (by default it's App_Data/TEMP/ClientDependency)."
I have recently added a WCF service reference to my program. When I perform a clean install of this program, everything seems to work as expected. But, when I install the program on a client which already has a previous version (without the new service reference) installed, I get a exception telling me the default endpoint for this particular service could not be found.
It seems that the appname.exe.config is not being updated with the new endpoint settings. Is there any reason for this and how can I force the installer to overwrite the config file? I'm using the default Visual Studio 2008 installer project with RemovePreviousVersions set to True.
Update:
My program encrypts the settings section after the first run with the following code
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
When I do not run the program before installing the new version the app.config gets updated.
You are right that it is the config file that is not updated.
There are several possibilities:
The installer has the old version of the config file
The installer does not have a config file and the program is using the old one on the machine
Try uninstalling the project first, then install and check that the config file has been copied in.