Unable to create DataCacheFactory instance in debug - c#

I'm working on web project that will run on Windows Azure Web role;
In the cloud, there will be 2 instances of the role;
I'm using co-located named cache (In-Role Cache) spread between 2 role instances;
Locally, I debug with single instance;
In the cloud, cache client is created successfully and work fluently;
When debug locally, I am unable to create instance of DataCacheFactory, because when the constructor is called, the program flow "stops" and doesn't continue to the following statement. There is no exception!
That's the code where I'm creating Factory and cache client:
var cacheFactoryConfig = new DataCacheFactoryConfiguration
{
ChannelOpenTimeout = TimeSpan.FromMinutes(2),
TransportProperties = {ReceiveTimeout = TimeSpan.FromSeconds(45)}
};
DataCacheFactory cacheFactory;
try
{
cacheFactory = new DataCacheFactory(cacheFactoryConfig);// <--stops here
}
catch (Exception e)
{
Trace.WriteLine(string.Format("--> Message-> {0}; --> Stack Trace->{1}", e.Message, e.StackTrace));
throw;
}
cacheClient = cacheFactory.GetDefaultCache();
Service configuration:
Cache client and server configuration in web.config
I would give any additional information if such is requested in order to resolve the problem shortly.
------EDIT 1------------------
Due to related post Making Windows Azure Caching Work in Compute Emulator I have to add some info:
Operating sistem -> Windows 7 Professional
IDE -> Visual Studio 2013 Ultimate Update 4
Windows Azure Caching package 2.4.0.0
Windows Azure SDK Version 2.4
I don't have Windows Server AppFabric installed, so I'm going for it!

After few days of investigation, I managed to solve the issue and successfully create instance of DataCacheFactory and DataCache and so on. The problem is described and solved in the following 2 posts:
https://social.msdn.microsoft.com/Forums/azure/en-US/8580689a-a1a1-4db7-bba9-f42c1a90e0db/windows-azure-webrole-caching-preview-hangs-makes-the-emulator-stuck-in-deploy-loop?forum=windowsazuredevelopment
http://blog.elastacloud.com/2012/06/09/using-the-windows-azure-cache-preview-with-sdk-1-7/
In my case, I had Microsoft Server AppFabric installed, so I removed it.
Just in case, I removed all available Windows Azure SDKs (2.4 was installed) and
all old nuget packages related to Azure Caching.
I did verify that all assemblies are removed from GAC too.
After "cleaning" I install again latest Azure SDK available which is 2.5. http://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-in-role/
I would like to point out, that windows Event Viewer helped a lot. In Windows Azure logs I found an error that was happening when I start the web role with Azure Emulator. Error was thrown by CacheInstaller.exe -> MissingMethodExceprion with message:
Method not found:
'Microsoft.ApplicationServer.Caching.ClusterConfigElement

Related

Creating a CosmosDB database locally with C# code throws an Internal Server error

I try to create a database in the local cosmosDB emulator but this fails to work. It throws an exception with the following message:
Response status code does not indicate success: InternalServerError
(500); Substatus: 0; ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc;
Reason: (Unknown server error occurred when processing this request.
ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc,
Microsoft.Azure.Documents.Common/2.14.0,
Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum,
Windows/10.0.19042 cosmos-netstandard-sdk/3.24.1);
This error happens in my project as well as in an simple, empty console app only containing these lines of code:
using Microsoft.Azure.Cosmos;
namespace CosmosDBTest;
class Program
{
public static async Task Main()
{
using var client = new CosmosClient("<A local connection string>");
var response = await client.CreateDatabaseIfNotExistsAsync("test", 500);
var database = response.Database;
await database.CreateContainerIfNotExistsAsync("container1", "id");
}
}
The version of the emulator I use is 2.14.6. The version of the NuGet package is 3.26.1
What is causing this exception and how do I solve this? I has worked with older versions of the emulator in combination of an older version of the NuGet package. But before I downgrade the emulator and/or package, I want to find out if there is a better work around.
I haven't tried the demo application which is offered by the emulator. Funny enough as it is on a tab with the name ".NET" (and another tab .NET core next to it) the ".NET" example is written in the very old version .net core 2.1 which I don't have installed even.
Try resetting the Emulator, this looks like a malfunction on the Emulator itself. The HTTP 500 is coming from the Emulator, the SDK is just surfacing the response.
Reference: https://learn.microsoft.com/azure/cosmos-db/troubleshoot-local-emulator
If you installed a new version of the emulator and are experiencing errors, ensure you reset your data. You can reset your data by right-clicking the Azure Cosmos DB Emulator icon on the system tray, and then clicking Reset Data…. If that does not fix the errors, you can uninstall the emulator and any older versions of the emulator if found, remove C:\Program files\Azure Cosmos DB Emulator directory and reinstall the emulator.
Alternatively if resetting the data doesn't work, navigate to %LOCALAPPDATA%\CosmosDBEmulator location and delete the folder.

Windows 10 Visual Studio 2019 IIS Express won't start with error 500

We have an API project in .Net Core 3.1.
It is working in all the computers in the team but when tried to debug it on a new member computer it failed.
It states there is a server error (500) and won't start the program.
It works as a local service, without IIS.
We have tried to format the computer and start fresh, with no use.
I saw posts relating to the project configurations and launch settings, but since it is working on other machines I don't think this is the issue.
We also tried to add the required lines for the aspnetcore modules in iis template files and the dlls as seen in other places where it was recommended, getting the same issue.
Any suggestion will be appreciated!
Error text from your HttpFailure_08-24-17.tml file
NOTE: you really should have copied/pasted as text, instead of a attaching a screen shot:
The description for Event ID 1034 from source IIS Express AspNetCore Module V2 cannot found.
Either the component that raises this event is not installed on your local computer or the installation is corrupted.
You can install or repair the component on the local computer.
...
The following information was included with the event:
Could not load configuration. Exception message: Unable to get required configuration section 'system.webServer/aspNetCore'. Possible reason is web.config authoring error.
The request is not supported.
EDIT:
Program.cs:
public class Program
{
public static void Main(string[] args)
{
try
{
Console.Error.WriteLine("Starting application (from error log without errors)");
var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();
Console.WriteLine("Config set");
var hostBuilder = new WebHostBuilder()
.UseKestrel(opt => opt.AddServerHeader = false)
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
Console.WriteLine("hostBuilder set");
// ConfigureServices is only used to delay execution until UseIISIntegration()
// has actually set the "urls" setting.
Console.WriteLine("urls for hostBuilder " + hostBuilder.GetSetting("urls"));
hostBuilder.ConfigureServices(services =>
{
var urls = hostBuilder.GetSetting("urls");
urls = string.IsNullOrWhiteSpace(urls) ? "127.0.0.1" : urls.Replace("localhost", "127.0.0.1");
hostBuilder.UseSetting("urls", urls);
});
Console.WriteLine("hostBuilder.ConfigureServices set");
var host = hostBuilder.Build();
Console.WriteLine("host set");
host.Run();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
}
The error is warning you about AspNetCore Module V2 being corrupt or missing.
There is a module required to be installed in IIS to be compatible with AspNetCore projects (in particular, working with the default Kestrel server).
You need to follow these instructions and install this module. As far as I can recall, it does not require any additional configuration.
EDIT:
I stumbled upon this article, which refers that they also had issues with IIS Express. Maybe it can be of help to you, and follow their guide to find what is wrong in your configuration?
https://blog.maartenballiauw.be/post/2019/02/26/asp-net-core-iis-express-empty-error-starting-application.html
Seems like we have an Antivirus causing errors in Visual Studio 2019 install, disrupting the netcoreapp.dll and others.
I'm closing this stating that after antivirus was shut down and install went forward,
the blog post #Sotiris Koukios-Panopoulos did the trick.

Azure SDK Storage assembly not found exception when publishing

I try to publish a demo application to Windows Azure using Cloud Service and Azure SDK 2.9. In my service I have a Web Role and a Worker Role. Both use Azure Storage. Everything works fine on local hosting (Emulator) but when I try to publish the app I get the following error on Web Role:
Unhandled Exception: System.Runtime.Serialization.SerializationException,
Details: Exception: Unable to find assembly 'Microsoft.WindowsAzure.Storage, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf385)
In the Worker Role project everything is OK, it's using Storage too.
I tried to convert the Web Role to a standard Web Application and everything works fine but I want to resolve this problem on Cloud Application.
What I've tried:
set local copy in references to true
changed .Net Framework to 4.5.1 and 4.6 (default 4.5)
removed and added reference to Storage again
reinstalled all libraries by nuget
published with Storage 7.0 and 6.2
published by VS and by portal (package)
added dependentAssembly to web.config
On my VM I checked the bin folder, Microsoft.WindowsAzure.Storage exists.
Any ideas what is wrong?
After two days I found a solution for that problem.
In my WebRole.cs I had this:
public override bool OnStart()
{
var csa = CloudStorageAccount.Parse(RoleEnvironment
.GetConfigurationSettingValue("Credentials"));
var cqc = csa.CreateCloudQueueClient();
var inputQueue = cqc.GetQueueReference("inputqueue");
inputQueue.CreateIfNotExists();
var outputQueue = cqc.GetQueueReference("outputqueue");
outputQueue.CreateIfNotExists();
var ctc = csa.CreateCloudTableClient();
var ct = ctc.GetTableReference("last");
ct.CreateIfNotExists();
return base.OnStart();
}
When I moved this initialization to other place e.g. to RouteConfig.cs everything works perfect. I don't know why but every references to Storage from WebRole throws errors after publishing to Azure.
I hope this solution helps.

Creating Table in Azure Storage Emulator produces HTTP 500 Error

I've been attempting to create a table through my machine's Azure storage emulator. I can recreate the problem with a very simple program that uses only WindowsAzure.Storage nuget version 6.2.0 :
using Microsoft.WindowsAzure.Storage;
namespace StorageEmulatorTest
{
internal class Program
{
private static void Main(string[] args)
{
var cloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
cloudTableClient.GetTableReference("JohnnyTest").CreateIfNotExists();
}
}
}
After 25 seconds, this will throw an exception of type Microsoft.WindowsAzure.Storage.StorageException with only this message:
The remote server returned an error: (500) Internal Server Error.
I have attempted:
Ensuring my WindowsAzure.Storage nuget package is the latest version (6.2.0).
Re-installing the Azure SDK for VS2015 2.8.1 (and ensuring that it's the latest version)
Stopping, clearing, initing the Azure Storage Emulator through the Azure Storage Emulator command line tool (seemed to work fine, no errors)
Reading the web response's stream through the exception's ".InnerException.Response.GetResponseStream()". This fails with an exception that states "Stream was not readable".
Restarting my machine (desperation kicked in)
My bag of tricks is running low. Has anybody encountered this issue?
I solved it. I had to completely wipe out my existing local storage emulation instance. Using "AzureStorageEmulator.exe clear" or "AzureStorageEmulator.exe init" was insufficient. Even uninstalling the Azure SDK was insufficient.
I started by stopping the storage emulation:
AzureStorageEmulator.exe stop
AzureStorageEmulator.exe clear
AzureStorageEmulator.exe init /forceCreate
That last command errored and indicated that it could not create the database.
Then I deleted (actually, I renamed them) these remaining files that comprised the database behind the azure storage emulator:
C:\Users\[Me]\AzureStorageEmulatorDb42_log.ldf
C:\Users\[Me]\AzureStorageEmulatorDb42_log.mdf
Finally, I started the emulator back up
AzureStorageEmulator.exe init /forceCreate
AzureStorageEmulator.exe start
Success!
I'm unsure what got me into the situation, but my best guess is that this was caused by a recent upgrade of the Azure SDK.
I think in many cases Johnny's answer will solve the issue.
In my case this also did not work, because AzStorageEmulator did not create the database AzureStorageEmulator510 (database instance (localdb)\MSSQLLocalDB) and also not the tables within.
So I used SSMS to create database AzureStorageEmulator510 from scratch,
then I found that an older version AzureStorageEmulator57 was still on my PC, so I attached it (you can find the databases in C:\Users\YOURACCOUNT) - extracted the database structure to a SQL script and ran it for AzureStorageEmulator510.
After that, I started the emulator and created a new blob container using AzStorageExplorer.
The Error 500 seemed to occur because that database (and structure inside) was missing and could not be recreated by the CLI command AzureStorageEmulator.exe init /forceCreate.
Other things you can check (possible issues):
It can also be AzStorageEmulator can't access its database. One of the reasons (and how it can be fixed) is described here.
After installing a newer version of the instance (localdb)\MSSQLLocalDB, it can be that the related database is not attached. This will result in a strange error like
Cannot open database "AzureStorageEmulator510" requested by the login. The login failed. Login failed for user 'YOURACCOUNT'.
If that is the case, you can fix it by simply connecting to localDb via SSMS, then attach the database: Right-click on databases, select Attach... in the context menu, then in the dialog, add the database file (located in C:\Users\YOURACCOUNT).

Why can't i access the RoleEnvironment in Application_Start when using a RoleEntryPoint?

I have a Azure WebRole which I'm trying to configure logging for using the DiagnosticMonitor.
According to the documentation at windowsazure.com the logging should be implemented in OnStart:
Note: The code in the following steps is typically added to the OnStart method of the role.
https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/
In order to access the OnStart method I have to define a RoleEntryPoint. But once it is defined I can't access the RoleEnvironment in web applications Application_Start.
How can I make the RoleEnvironment available to the application while still being able to use the DiagnosticMonitor?
I store the applications connection-strings in the service configuration.
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// config
var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
LocalResource localResource = RoleEnvironment.GetLocalResource("MyCustomLogs");
DirectoryConfiguration dirConfig = new DirectoryConfiguration();
dirConfig.Container = "wad-mycustomlogs-container";
dirConfig.DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes;
dirConfig.Path = localResource.RootPath;
DiagnosticMonitorConfiguration diagMonitorConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagMonitorConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
diagMonitorConfig.Directories.DataSources.Add(dirConfig);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
return base.OnStart();
}
I've solved it.
After cleaning my solution, rebuilding, restarting IIS, shutting down the azure emulators and restarting Visual Studio it suddenly started working.
I changed no code at all.
(I even did all of those things before posting as well but it only worked when I did it all at the same time)
This is defintely the right example set of code. You need to set all of this in the Role though NOT in your web application.
NOTE: since Azure now has full IIS the context is different between the RoleEntryPoint On_start and the Web application, which is running in it's own worker pool within IIS.
Just a quick sanity checklist:
The code you're writing is in your class that inherits from RoleEntryPoint (typically WebRole.cs NOT in the Global.asax)?
You're running the project in the Azure Emulator (not inadvertently starting a web project directly?)
If you're running the application in the Azure emulator or deployed to Azure itself RoleEnvironment is available from within your IIS application as long as you have the relevant DLLs reference. If you can build with RoleEnvironment.IsAvailable in your code, then the libraries are included. The only thing I can think is that you're running the web site directly, not within the Azure emulator.
Set the Cloud project to be your startup in Visual Studio and you should be golden.

Categories

Resources