Google Speech - After Hosting getting Unauthenticated Error - c#

I have created a web api method to Speech to text using Google Speech library. It is working fine when I execute using the visual studio. After hosting the application on IIS, I am getting below error when the api method is called
Method:Status(StatusCode=Unauthenticated, Detail="Getting metadata from plugin failed with error: Exception occurred in metadata credentials plugin.")
Error at line with code:
var speechResponse = speech.Recognize(SpeechConfig,
RecognitionAudio.FromFile(fileToProcess));*
And on another system, I have configured the GOOGLE_APPLICATION_CREDENTIALS env avariable with service account json, but I am getting below error
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.

Do you also have compact framework sdk installed for visual studio? if try adding
< NoStdLib > False< / NoStdLib >
in your *.csproj file. This would force VS to use the std mscorlib.dll instead of compact one.
Check if the date and time on your system are correct (should be with 60 seconds of actual time)

Related

IronPDF Renderer.RenderHtmlAsPdf failing when deployed to IIS

We are using ironPDF to genetate PDF file from HTML string. It is a MVC web application written in C# (.net framework 4.8) , deployed to IIS
I did the following.
Added IronPdf nuget package to the project (Version: 2022.11.10347)
Use the following code to generate PDF from string
using IronPdf; (on top of the code to add ref)
PDF generation code as below;
public ActionResult ExportPDF()
{
var Renderer = new IronPdf.ChromePdfRenderer();
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
return File(pdfDoc.Stream.ToArray(), "application/pdf", "TransactionStatement.pdf");
}
here htmlstring is the html that need to be rendered to PDF
This code works fine and generates PDF when I run in my local dev machine.
But when I deploy this code to our integration environment , it is failing. It is not generating any PDF.
It just hangs for couple of minutes then our website is getting timed out and application pool is getting stopped.
the failure is happening is in the following line
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
Out integration environment is in IIS (Windows server 2008 R2) . and application pool identity is NetworkService.
When I looked into the event log I can see the following warnings
Application popup: IronCefSubprocess.exe - System Error : The program can't start because api-ms-win-core-com-l1-1-0.dll is missing. from your computer. Try reinstalling the program to fix this problem.
A process serving application pool '<poolname>' suffered a fatal communication error with the Windows Process Activation Service. The process id was '5940'. The data field contains the error number.
I have all required Visual C++ redistributables installed in my server as described in the ironPDF website
Any idea how to fix this issue.
For API-MS-WIN-CORE-COM-L1-1-0.DLL. You could refer to this to reinstall API-MS-WIN-CORE-COM-L1-1-0.DLL.
About application pool error. As the community member said, need configuration information is needed to locate the cause.
In my opinion, you could try turn Enable 32-bit applications to true. If still don't work, you can refer to this using debugging tools to locate the cause.

Can't connect Firebase Cloud Firestore from C# .NET Core app

I'm trying to set up a very simple test application for connecting to my Firebase Cloud Firestore instance.
It's a C# .NET Core console application using .NET Core 3.0 on Windows 7
I'm just trying to connecting to my Firestore instance using my project name.
My GOOGLE_APPLICATION_CREDENTIALS environment variable is set to C:\test\creds.json which I created from using the "Create Key" feature on the GCP Console page for my default service account.
When I run the code below, I get the following error:
using Google.Cloud.Firestore;
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
FirestoreDb db = FirestoreDb.Create("my-proj-id");
}
}
}
Exception:
The Application Default Credentials are not available. They are
available if running in Google Compute Engine. Otherwise, the
environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials. See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.'
When I run ProcessMonitor to detect file system activity, my application never even tries to touch the creds.json file, which makes me believe the C# Cloud Firestore API isn't even finding my creds file. I've set the GOOGLE_APPLICATION_CREDENTIALS env variable at both the user and system level.
Is there a problem with how I've configured things?
Well this was maddening. I tried to log the GOOGLE_APPLICATION_CREDENTIALS environment variable value in my app and it was null. I restarted Visual Studio and it started to work. My theories are that either VS passed the current environment to the debugee when it launches the debugger process or that it may use one of those Visual Studio debugger host proxy processes for debugging and it was restarted after I restarted the IDE
Sometimes the environment that Visual Studio is running can be different to the scope of the PATH ENV variables in Windows. I think it is related to the Admin permission. It would be interesting to execute the task and the GOOGLE_APPLICATION_CREDENTIALS assignment opening Visual Studio as Administrator.
Seems that this behavior is expected. C# .net MVC, set path to Google Application Credentials JSON file

Why can't the AWS SDK find my credentials?

I have a server that utilizes AWS SES to send notification emails, but I keep recieving the following message:
An unhandled exception of type 'Amazon.Runtime.AmazonServiceException'
occurred in AWSSDK.dll
Additional information: Unable to find credentials
I have a credentials file fully accessible by the server's user and I use the following to tell the AWS SDK where the file is located and the profile name:
AWSConfigs.AWSProfileName = "example-user";
AWSConfigs.AWSProfilesLocation = Environment.CurrentDirectory + "/example-dir/credentials";
..however crashes at the following line with the error message:
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(REGION);
I checked out this answer on Amazon.Runtime.AmazonServiceException: Unable to find credentials which suggests that profiles should be in the application's configuration file, like so:
<appSettings>
<add key="AWSProfilesLocation" value="C:\awsfile\credentials" />
<add key="AWSRegion" value="us-east-1" />
</appSettings>
...this results in the exact same error.
What am I doing wrong? The AWSConfigs.* code has been working for around six months now without issue, this started happening when my project took a hiatus and I restored it from its Git repository. I cannot remember which version of Visual Studio I used before but I'm currently using 2015 (update 3).
I did however get this to work by adding the credentials as system environment variables, but this isn't a permanent solution for security reasons.
If I download earlier commits, build them and run them, I get the exact same error. I'm thinking this is either something to do with the version of Visual Studio I'm using, but can't think of any reasons why this could be.
The AWS SDK and .NET versions have always been the same so it shouldn't be incompatibility (2.3.55.2 for the AWS SDK and .NET 4.6.1).
If you are running applications on an Amazon EC2 instance and those applications require AWS credentials, the best-practice advice is:
Never put credentials in your code
Assign an IAM Role to the instance and the SDK will automatically use those credentials
Even when you're running an application on a non-EC2 instance, avoid putting credentials in code. Instead, put them in environment variables or configuration files.
See: Configuring AWS Credentials for .Net applications

Interop service error occured when using InternetExplorerClass

i am trying to deploy an asp.net web service application to IIS 7.5. The application used .Net framework 3.5. dev machine is win 7 64bit. i have used following code snippet to create HTML and then convert it to pdf using Amyuni Document Converter 450.
private InternetExplorer internetExplorer = new InternetExplorerClass();
when i deploy the application in local development server it perfectly run but whn i deploy it using the local iis server it gives following error. any reasons for that.. i have used impersonate='true'
System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80080005.
You have to change property in DComConfig for ie.
Follow the next steps:
Start->Run->dcomcnfg->Component services>Computers>My Computer
Right click on My Computer and select Properties. On the Security COM tab set the Default Autethentication level and Default Impersonation level.

Can not open database error from IIS

Hi I just tryed to run my application fopr the first time on IIS.
Everything worked find while developing on visual studio but when I added the app to IIS I got this error:
Cannot open user default database. Login failed.
Login failed for user 'IIS APPPOOL\forum'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database.
What should I do the site works when I run it from visual studio?
EDIT
I did a litle more digging and I managed to find out that I needed to setmy application pool identity to NetworkService I did that but now I got another error :
Unable to open the physical file "D:\Projects IDE\Visual Studio\MyWork\Websites\Forum\App_Data\ASPNETDB.MDF". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file D:\Projects IDE\Visual Studio\MyWork\Websites\Forum\App_Data\ASPNETDB.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Please check two places
1 Access to folder for the NetworkService identity(default for IIS app pool) or for this one(IIS APPPOOL\forum)
2 Connection string credetial. And if there "Integrated security". Provide Specific user and passwrod there.
I received this non explicit error because I had the Application Pool set to .NET 2.0 as opposed to .NET 4.0 on a service that was responsible for authentication. Typically when the framework is incorrect a different type of error about a non-recognized framework .dll is displayed, but not in this case. If this happens, check the following:
The value after IIS APPPOOL is the name of the application pool this current process is run under. In your case there was an AppPool named forum.
Check that the app pool is using the corrected pipeline and .NET Framework required for the application being run.

Categories