Error Publishing to Azure 2.7 in VS 2015 - c#

I'm trying to do an Azure deployment with two web roles in it. I'm getting the following error after it builds and at the very beginning of the deployment.
Error CloudServices41 : The entrypoint ODataHQ.Query.dll is not a valid assembly. Please provide a relative path to the binary that implements the entrypoint. ODataHQ.Query.Azure C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.7\Microsoft.WindowsAzure.targets 1057
This error is happening on a co-workers machine as well. We just recently upgraded to Azure 2.7 inside of Visual Studio 2015 Enterprise and this is the first deployment we've attempted.
Can't find anything about it on the Internet, any thoughts?

Ok, I figured out the issue. I had added another worker role to my Azure deployment project, then I wanted to remove that worker role and add a web role in its place, but keep all the settings. So I manually renamed the worker role to the name of the web role in the ServiceDefinition.csdef, but I didn't change the tag to be a web role.
<WorkerRole name="MyProjectName" vmsize="Small">
Should have been changed back to
<WebRole name="MyProjectName" vmsize="Small">

Related

Azure Pipelines unable to find .Net framework version 4.0

My solution uses the latest version of .net which is 4.8. However, I see the following error message that complaints about a version 4.0 in Azure Pipelines. Can someone let me know how I could resolve this please ?
The error message indicates I need to install 4.0 but I don't think that's the solution. I also opened up the file Microsoft.Common.CurrentVersion.targets and line 1221 has the following. However, I know it is not advisable to edit this file.
<!-- By default if there is no root path set then the task will assume it is Program Files\Reference Assemblies\Microsoft\Framework-->
<GetReferenceAssemblyPaths
Condition="'$(TargetFrameworkMoniker)' != '' and ('$(_TargetFrameworkDirectories)' == '' or '$(_FullFrameworkReferenceAssemblyPaths)' == '')"
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
RootPath="$(TargetFrameworkRootPath)"
TargetFrameworkFallbackSearchPaths="$(TargetFrameworkFallbackSearchPaths)"
BypassFrameworkInstallChecks="$(BypassFrameworkInstallChecks)"
>
<Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_TargetFrameworkDirectories"/>
<Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="_FullFrameworkReferenceAssemblyPaths"/>
<Output TaskParameter="TargetFrameworkMonikerDisplayName" PropertyName="TargetFrameworkMonikerDisplayName" Condition="'$(TargetFrameworkMonikerDisplayName)' == ''"/>
</GetReferenceAssemblyPaths>
The error message:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1221,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
Note: There are many similar post in SO that suggest to install VS2019. However, I am getting this message while running the application on Azure Pipelines.
Update
From your description, you are using the Microsoft host agent and the pipeline pop out issue 'cannot found NETFramework,Version=v4.0'.
Your environment looks like this:
https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#net-framework
or
https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md#net-framework
You can see that the Microsoft host agent does not have the environment you mentioned.
Although you can install what you need at the beginning of the pipeline startup, I do not recommend this practice. Because when you choose microsoft host agent, every time you start the pipeline, you will be assigned a brand new azure VM machine, which means you need to install the relevant environment every time.
The recommended approach is to use a self-host agent. Please create a self-host agent based on your local machine (or another machine with the relevant environment), the steps are as follows:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
Provided above are the installation steps of windows self host agent, the steps should be very simple, if you encounter any problems please let me know.
And after that, you can run your pipeline based on that self host agent like this:
pool:
name: <your agent pool name>
If you are using classic pipeline, just click and select:
(If you run successfully on local, then the agent based on local machine should also be no problem.)
And if this is still unable to solve your issue, could you please remove the in-private information and share the YAML file or JSON file, and let me know at which step you encountered this issue?

Trouble publishing ASP.NET project with Code First database to Azure - Permission

I cannot migrate my Code First database to Azure - Error hints at permission, but I can't figure out what's missing?
I have created an empty SQL-database in Azure
(I can publish the web site without the EF migration)
Connection string in appsettings.json (+Development+Production) - Startup: ConfigureServices - DbContext gets the right connectionstring
serviceDependencies points to the right connectionstring - Local to LocalSecretsFile and Web Deploy to AzureAppSettings
I have commented out the LocalDB connection though (and changed reference in ConfigureServices)
I haven't deleted old migrations
Azure: App Service - Configuration - Application Settings -> Connection string is set
Azure: SQL Server - Access control (Classic administrator): Service administrator (me) has full access
Azure: SQL Server - Firewalls and virtual networks: Client IP + App Inbound + 6 * App Outbound applied - 'Deny public network access' is not checked - Yes to 'Allow Azure services and resources ...'
When publishing:
(Also tried running Visual Studio as administrator)
I can Validate connection
'File Publish Options': I choose 'Remove additional files at Destination'
'Databases': 'NameofConnStr': Use this connection string at runtime
'Entity Framework Migrations': Apply this migration on publish
'Site Extensions Options': Tried both with and without this
(I do not use the Key Vault)
Result:
Publish Executing command: dotnet ef migrations script --no-build --idempotent --configuration Release --output "..."
Generating Entity Framework SQL scripts completed successfully
Adding sitemanifest (sitemanifest)
Adding Child sitemanifest
Error: Web deployment task failed. (Make sure the database connection string for the server is correct and that you have appropriate permission to access the database. (Web Deploy Provider is "dbFullSql").
Error details:Could not complete an operation with the specified provider ("dbFullSql") when connecting using the Web Management Service. This can occur if the server administrator has not authorized the user for this operation
Learn more for "ERROR_USER_NOT_AUTHORIZED_FOR_DBFULLSQL": Web Deploy error codes - Diagnosis: A non-administrative user attempted to perform an operation with a Web Deploy provider for which the user is not currently authorized
(Build succeeded, Publish failed)
What's missing?
Should I add a new migration (and delete the old ones)?
Is there some problem with commenting out the connection to LocalDb?
Is there some setting in Azure I missed?
Well I finally succeeded in migrating my database.
I upgraded Visual Studio 2019 from 16.11.13 to 16.11.14. That's probably not the reason why it worked, but I just note it because I'm not sure what made the difference.
If someone has the same problem I'll try to summarize what worked although I think I have tried the combinations below before:
Ran Visual Studio as admin
I deleted the previous migrations (made in LocalDB) and added a new
The connectionstring only had Data Source/Initial Catalog/User Id/Password - i.e. not MultipleActiveResultSets/Encrypt/TrustServerCertificate/Connection Timeout
I ignored KeyVault (and LocalDB) service dependencies
New Publishing Profile
Published the Web app first (without migration)
Chose Apply migration and published again
All seems straight forward so it's a bit of a mystery ?!

Access Denied when running Windows Service

I have created a Windows Service using ASP.Net Core 3.x and C#. I started with the new Windows Service template when I built the project. When I run it from my development environment or from a console window it runs fine. When I install it as a Windows Service and attempt to start the service I get an
"Error 5: Access is denied." error.
I tried numerous things which I will outline below to eliminate the error but nothing seemed to work so I downloaded the sample app provided by Microsoft, at sample
Same result...when I run the sample app from within Visual Studio it runs fine, when running as a service I get the Access Denied error.
I am running all of this on my local machine, which I am an admin on.
I originally tried to run it using the default Local System account; got the Access Denied error.
I changed the Log On As to my domain account, the same one I use to log into my local machine which is an admin on this machine; got the same Access Denied error.
My account has the privilege set to run as a service.
The Event Viewer just shows the one message which says "Access Denied", no other messages are created.
I believe the Access Denied error is occurring before the C# code is even executed. What makes me believe this is that I added one line to the very top of the Program.Main.... File.WriteAllText("C:\\temp\\ws.log", $"Test of Worker Service # {DateTime.Now}. Content Root Path: {AppContext.BaseDirectory}");. My account has full access to the temp folder. This file gets created when I run the app from Visual Studio but it does not get created when I run the app as a service.
I have read numerous web sites, include this one and this one. No luck, everything I tried from these sites still produce the Access Denied error.
I have run out of ideas and am hoping someone here can provide me the answer. Thanks!
I found the solution and believe me I feel really stupid!!!
When I installed it as a service I only put the path in "binPath".
sc create WindowsService1 binPath="C:\temp".
Once I actually added the executable to the binPath parameter everything worked.
Changed it to sc create WindowsService1 binPath="C:\temp\WindowsService.exe" and it worked.
I know it is an Id10t error but Microsoft should really provide better messaging for the "sc" command. A message like "Cannot find file specified in the binPath parameter" would have been really helpful. Would have saved me about 6 hours of work.
Thanks everyone for reviewing and replying to this question.

Error in Angular app running on .NET Core in Service Fabric

I have created a new service fabric application, added a stateless .NET Core service (.NET Core 2.1) and selected the angular template. It builds fine and all looks OK however when I run it I get this error:
Startup.cs contains a line spa.UseAngularCliServer(npmScript: "start"); which is only used in development, if I remove this line then I no longer get this error but it doesn't pick up any of my changes to code.
I have tried updating my npm, node, angular cli versions, updating the project to angular 7 (it is 5 by default) with no luck.
If I run ng serve directly in the ClientApp folder it runs OK so the issue seems to be to do with it being hosted in .NET Core or SF.
It seems it could be something to do with the SF service not having permissions to create/edit files/folders under system32?
As suspected it was to do with SF not having permission to modify that folder. Service fabric runs under the user NETWORK SERVICE.
I found 2 ways to fix it:
1. Manually grant permission to NETWORK SERVICE
I navigated to C:\Windows\System32\config\systemprofile\AppData\Roaming and edited the permissions in that folder to give the user NETWORK SERVICE permissions to read/write
2. Edit ApplicationManifest.xml to give SF admin permissions
By adding
<Principals>
<Users>
<User Name="LocalAdmin" AccountType="NetworkService">
<MemberOf>
<SystemGroup Name="Administrators" />
</MemberOf>
</User>
</Users>
</Principals>
<Policies>
<DefaultRunAsPolicy UserRef="LocalAdmin" />
</Policies>
Either of these seems to make it work. The best part is all it eventually did is create an empty npm folder there.

IIS 7.5 Authorization Rules not working as expected

I have a basic Visual Studio project, 2 folders in a site, one folder called 'pub' which should be publicly available, and one called 'auth' which requires you to sign in to view the contents. I have 2 location rules in the web.config that manage that.
I am also using a basic auth module (http://www.asp.net/web-api/overview/security/basic-authentication) which is added to modules in IIS and registered
In VS when I debug using IISExpress, everything works as expected, 'pub' let's me in no problem, and auth prompts me for credentials using 'basic' auth. But when I publish (through VS, delete all files prior to update) the site to IIS 7.5 every folder requires authentication, which is wrong.
Now if it is the BasicAuthModule that is causing the issue, then how do I get prompted for credentials using basic auth in IISExpress, but if it isn't the module then what is different between the IISExpress debug install and my servers?
There isn't really a lot of code to show, but here is my web.config with the code that we are using:
-system.webServer-
-modules-
-add name="BasicAuthHttpModule" type="WebHostBasicAuth.BasicAuthHttpModule" -
-/modules-
-/system.webServer-
-system.web-
-httpRuntime targetFramework="4.5" -
-authentication mode="Windows" -
-/system.web-
-location path="~/services/public"-
-system.web-
-authorization-
-allow users="*"-
-/authorization-
-/system.web-
-/location-
-location path="~/services/auth"-
-system.web-
-authorization-
-deny users="?"-
-/authorization-
-/system.web-
-/location-
Obvious answer, redesigned the site to have virtual directories for the auth and pub and changed the auth methods for each one.
I just though there should be a better way.

Categories

Resources