Azure Service Bus InvalidOperationException - azure

I have a .NET Core app running which is listening to an Azure Service Bus topic.
When I run the app I get this error:
A sessionful message receiver cannot be created on an entity that does
not require sessions. Ensure RequiresSession is set to true when
creating a Queue or Subscription to enable sessionful behavior.
I think the code is running on a separate thread and I can't seem to find the point where the Exception is thrown.
I also don't have a D:\ drive which is where the SessionClient.cs file is located.
Is this D:\ drive in Azure, and if so does this mean there is code running in Azure?
How can I debug this?

Erase your queue and create it again wihtout the 'Require session' checked. Also check your code because maybe you have set the bool RequireSession to true. The fact is that you have enable or disable the sessions once you have configured the queue in the opposite configuration

You're getting the stacktrace that includes the reference of the sources compiled and deployed for that version of the package. The D:\ drive is irrelevant to the issue. What this is is a mismatch how you receive messages and how the entity is configured. You appear to have a sessionless entity, but in the code, you use a receiver that is configured to work with a session.

Related

Trying to add heartbeat for my console application

A discussion on github mentions that heartbeat is automatically sent when Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule& is added to the applicationinsights.config file. I want to create an alert in case the app hangs or crashes. Where can I track the heart beat on the AI instance? Also, currently its not sending anything . I am using .net framework 4.7.2. Am I configuring it wrong? I am not able to track the heartbeat on application insights instance. Where can I track it? Can someone provide a snippet for config file?
Currently, there is an issue involving this telemetry module AppServicesHeartbeatTelemetryModule .
Can someone provide a snippet for config file?
There is given a temporary workaround for WorkerServices.
Add application insights to worker service using services.AddApplicationInsightsTelemetryWorkerService().
Not only this DiagnosticsTelemetryModule adding to DI and also we need to configure it's heartbeat interval/module using the below snippet:
services.TryAddSingleton<ITelemetryModule, DiagnosticsTelemetryModule>();
services.ConfigureTelemetryModule<DiagnosticsTelemetryModule>((mod,opt) => mod.HeartbeatInterval = TimeSpan.FromSeconds(30));
services.AddApplicationInsightsTelemetryWorkerService();
The TelemetryConfiguration.Active is not recommended because Worker service is new SDK, its not touching .active or any other static singletons.
Where can I track it?
After Deploying, Look for "HeartbeatState" in customMetrics.
Note:
Disabling DiagnosticsTelemetryModule will cause the following settings to be ignored: EnableHeartbeat, EnableAzureInstanceMetadataTelemetryModule, EnableAppServicesHeartbeatTelemetryModule.
Enable Azure Monitor from the Portal.
References:
Configuring or removing default TelemetryModules (HeartBeat Telemetry Issue)
Enabling Hearbeat in App Services for .NET and .NET Core

Azure Service Fabric Activation Error 7148

I have a service fabric cluster which hosts numerous applications. One of the applications has a service type where the service is created, runs for a bit, and then is deleted. Everything works great, but the cluster virtually always has its state set to error because there will be a few of these in the "Unhealthy evaluations" section.
Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation.The service host terminated with exit code:7148
I've wrapped both the program's main and RunAsync in exception handlers, but never see anything in analytics. Is there any way to look up what exit code 7148 means? Thanks.
7148 is a general error code that indicates that something failed in SF in the process of setting up or activating your service's host process. So that's the reason that you're not seeing any errors or exceptions - your code is never getting a chance to run.
Examples of things I've seen that led to 7148:
The exe was not actually a windows exe due to corruption
The service's manifest had a reference to a cert or some other pre-req like an endpoint that was incorrectly configured (like a port that was already in use or the wrong thumbprint for a cert)
Something blew up inside Windows that cause the process creation to fail, like a failure to correctly configure host networking for a container
Most of the times when I see this I have to look at the windows error logs to see what's really happening. The SF folks are also trying to capture more common causes of failures and reporting them as better health errors rather than relying on 7148.

Convert azure web application to azure website

Within our company we've got a rather large serviceapplication running as a azure cloudservice. The service contains a webrole and a workerrole.
The webrole contains an MVC-application and the workerrole is running in the background. The workerrole is used to handle several large processes and a bunch smaller processes 24/7, this is checked every 5 minutes.
I've created an azure website for this application and wrote a small wrapper class which checks if configuration values needs to be taken from either the web.config file or cloud configuration files (.cscfg files). I've added the appropiate transformations to transform some extra settings and published the application to the azure website.
So far everything works good, but what i've expected a bit already indeed happened.. The workerrole isn't working anymore and is throwing errors. The first error i've seen was;
Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
So ofcourse i've taken the quick solution and went 'properties > copy local' and set it to true. After publishing this to the azure website i'm getting the following error;
Could not load file or assembly 'msshrtmi, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I can find out where this error is coming from, but it feels like this is the second of a whole other bunch of errors coming. On several sites I've read that azure websites just doesn't support workerroles (obviously).
This gives me a few options;
Find a solution so I can connect the azure website to the workerrole still running in the cloudservice. If this works I can drop the webrole and I'm able to connect multiple instances to one workerrole.
Find a solution to convert the workerrole to something (no idea what this possibly could be) supported by the azure website.
Forget the whole idea and stick to the cloudservice setting with the web- and workerrole.
Fragment from workerrole.cs
The facade makes a database call to check any newly added processes.
public override void Run()
{
// Only process if the web.config says we're allowed to do so.
while (true)
{
var process = Convert.ToBoolean(WebConfigurationManager.GetSetting("Process"));
try
{
if (process )
{
var username = WebConfigurationManager.GetSetting("UsernameWorkerRole");
if (string.IsNullOrEmpty(username))
{
var version = Assembly.Load("Ecare.Productie.WorkerRole").GetName().Version;
var versionString = String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build.ToString("000"), version.Revision.ToString("00000"));
username = ApplicatieConstanten.WorkerRoleName + " " + versionString;
}
IServiceFacade serviceFacade = new ServiceFacade(username);
serviceFacade.Start();
}
}
catch (Exception ex)
{
AuditingLoggingHelper.GetLoggerInstance(ApplicatieConstanten.WorkerRoleName).Error("Exception while starting service", ex);
}
Thread.Sleep(10000);
}
// ReSharper disable once FunctionNeverReturns
}
The main reason we're doing this, is because we have VS solution with an MVC-application (the web role) and the workerrole. We're currently publishing this to an cloud service in azure. Because of the development processes we're running seperate test, acceptation and production environments. Since it's a heavy process we're running quite expensive machines in azure, but that mostly only needed for the workerrole. The webpart is lightweight. So it's mainly an idea trying to reduce costs. So the idea is to convert the webrole to an azure website (this part is working already with just a small modification to read information from the web.config instead of the cloudconfiguration). But the workerrole currently isn't working because we haven't changed anything for that yet. An colleague of mine basically said "write a wrapper for the configpart, publish the azurewebsite to 1 or more testenvironments and point them to the same workerrole". But i'm having my doubts wether this is even possible..
Did anyone else ever ran into this sort of situation and found a solution for this? Any help finding a solution is greatly appreciated!
Find a solution so I can connect the azure website to the workerrole
still running in the cloudservice. If this works I can drop the
webrole and I'm able to connect multiple instances to one workerrole.
I'm guessing that you're using some kind of queue mechanism (Azure Storage Queues or Service Bus Queues) to facilitate communication between Web and Worker Role. If that's the case, then you can continue to use the same. Your website will push messages in a queue and your worker role will poll this queue and fetch messages and work on those.
Find a solution to convert the workerrole to something (no idea what
this possibly could be) supported by the azure website.
Do take a look at Azure Webjobs. In Web Apps world, they are the counterpart of Worker Roles.
UPDATE
Based on the comments, I think you should be able to port your code to run as Web Jobs. There are two ways by which you can do it:
If you create a Continuous Web Job, then you would have to put this 10 second sleep logic in your code itself. The job will continuously be running but will only wake up every 10 seconds. Similar to your current Worker Role implementation.
You could very well take out this 10 seconds sleep logic from your code by making your Web Job as a Scheduled Web Job where you schedule to run this every 10 seconds. I would recommend going down this route as you have decoupled your scheduling logic (10 second sleep) from your application. So tomorrow if you were to increase the sleep time, you would simply change the schedule in the portal without redeploying your code.
As Gaurav pointed, the equivalent to worker roles in the App Service space is Azure WebJobs.
Regarding this problem:
So far everything works good, but what i've expected a bit already indeed happened.. The workerrole isn't working anymore and is throwing errors. The first error i've seen was;
Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
So ofcourse i've taken the quick solution and went 'properties > copy local' and set it to true. After publishing this to the azure website i'm getting the following error;
Could not load file or assembly 'msshrtmi, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Microsoft.WindowsAzure.ServiceRuntime is specific to Cloud Services, and will not work in Web Apps (that's why you get the msshrtmi error with the web app). If you are still running a worker role, that file is in the instance GAC, and should be in your local machine's also. That said, Microsoft.WindowsAzure.ServiceRuntime can be referenced in the worker role project, but not the web app project.
I'm guessing you are using ServiceRuntime to get some configuration setting value using:
var value = RoleEnvironment.GetConfigurationSettingValue(settingName);
You can changed it to:
var value = CloudConfigurationManager.GetSetting(settingName);
as this method reads the configuration setting value from the appropriate configuration store (from MSDN).
The best solution here is to convert the Worker Role to a WebJob as #Graurav mentioned above.
If you want to connect the Web App to the Worker Role would be to use an Azure Queue or other intermediary storage where operations could be dropped form the WebApp and picked up by the Worker Role.

Transactions in NServicebus using Azure Service Bus Transport

I have several message handlers in a particular endpoint that do their work against a SQL Azure database (at the moment still using a local SQL 2012 instance). I have a command handler that publishes 2 events, call them X and Y. In the same endpoint I have a subscriber to X and a subscriber to Y. Both of these subscribers are internally using the same data access component, call that Z. Dependency injection is configured on a per-call basis, not shared.
Component Z is using Entity Framework 6 under the curtains. The issue I am having is that just opening the database is throwing a SqlException and complaining about MSDTC escalations.
I have temporarily wrapped the handlers in a TransactionScope.Suppress and that has stopped the error but I believe I'm missing something more fundamental.
Is it a simple matter of configuring the endpoint to be non-transactional? I would have thought this would just work seeing as I've configured to use Azure Service Bus as the transport mechanism. If I do this will NServiceBus still retry if an exception is thrown within the message handler? (Up to the SLR limits -- not part of the question, I also understand the idempotency issues).
#Phil,
First, you shouldn't be using MSDTC with SQL Azure - it's not supported. The feature is suggested, but only under review. DTC is not supported on Azure. Alternatively, you could look into the following suggestion to use SqlTransaction approach.
Second, transport you're using has nothing to do with your data access. Since you're using Azure Service Bus, it will not be part of your handler code. Making handler a transactional is to force an atomic change or roll-back. Regardless of your handler, will retry. Challenge is that when handler/endpoint is not transactional, and within handler first write to DB succeeded and second failed, first write won't be reverted. As for Azure Service Bus as a transport, it's not transactional in its nature (ie no DTC).
Which version of NServiceBus.Azure are you on? Do you have a stack trace of the exception? Where does it come from?
We push the sends and publishes out of the scope of the receive transaction scope explicitly to prevent promotion to the DTC, so that the transaction is local to the sql, so I doubt that is what is happening here.
From you description it looks like you are using a different data access instance for each handler (per call container config) and you have multiple handlers on the same message. If both of these open a new connection to the SQL you would see promotion as well (even if it is the same server)
Could that be it? That it throws on the second open?

"Service unavailable" with http handler

I am using IIS 6 on 2003. I have created a HTTP handler dll that inherits from IHttpAsyncHandler. The dll builds into the inetpub\www8080root\common\bin directory. It is meant to intercept all requests.
The web site is set to monitor port 8080. I have created a common folder in the www8080root directory and have created a virtual directory in II6 to point to it. I created a web.config file in the common directory
When I access http://localhost:8080/common/index.html all I get is
Service Unavailable
I am not sure where this message is coming from.
w3wp.exe does not start and there is nothing in the error log to indicate a problem.
I have run aspnet_regiis -r
I don't think it is occurring within the handler itself and without w3wp.exe I am unable to attach to the process. I have added Debugger.Break() but nothing happens.
I don't want to load IIS 7 as it conflicts with a legacy application.
The problem for me was that the identity that the worker process was impersonating was not a member of IIS_WPG. A little more detail in the message would have been nice.

Resources