Publish on Azure Website unexpected behavior - azure

I have a web project, which works fine on local PC. But when I publish it on Azure Website, I get an error:
Could not load type 'Infrastructure.Asset.AssetContext' from assembly
'Infrastructure'. 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.TypeLoadException: Could not load type
'Infrastructure.Asset.AssetContext' from assembly 'Infrastructure'.
where AssetContext is DbContext from another project inside solution. As I understand, this assembly is not published correctly on Azure. So, I removed all files on Azure Website via Kudu and republish again. The same. I try to connect to remote Db from my local - it works. I tried to rebuild solution, reopen Visual Studio etc. Nothing happened
Why it can be happened, what is wrong and how to fix?

There is a similar SO thread What could be causing a System.TypeLoadException in a Visual Studio Unit Test?, I think which answers are valuable for your current issue.
Please follow the figure below to get the information of what platform you used is on Azure Website, then to select the current mode in Visual Studio to build and publish.

Related

error while attempting to deploy Dockered .net core application to Azure Container Registry

Folks, this may have been asked before, i took some time trying to search for a possible root cause/solution to this but have not found anything similar enough.
Goal: I am looking to publish a Dockerized .Net Core Web App default template to an Azure Container Registry.
I have created a default application teplate for .Net Core Web App using Visual Studio 2022 targeting .Net 7.0. this is what it looked like:
i have tested running it locally on my machine which seems to be working just fine.
i then went ahead and created a publish profile targeting Azure Container Registry.
when i attempt to run the publish workflow - it seems to run into an error complaining that:
error from sender: context canceled
C:\FolderPath\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.17.0\build\Container.targets(219,5): Error MSB4018: The "ContainerBuildAndLaunch" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
It also complains about Assembly binding logging being turned OFF. i went on to fix this issue however it had no effect on the original error about the missing file related to Microsoft.Win32.Registry.
I have tried to add Microsoft.Win32.Registry nuget package to the project explicitly. That did not solve the problem either.
I have tried to reproduce these steps on another computer workstation running different Visual Studio (Professional edition as opposed to Enterprised) and on the other computer - i am able to deploy dockerized template to Azure Container Registry just fine.
At which point i have decided i would do a full re-install of the computer system where i had a problem (it was due anyway for a while and i was putting it off). So i did a fresh Win 11 install, fresh VS install and fresh Docker Desktop install among all other things. i intentionally tried to stick to default config whenever possible.
after full reinstall - i keep hitting the same error.
i would appreciate any hint as to what might be causing the error. thank you!
Try copying the lib\net461\Microsoft.Win32.Registry.dll file from the Microsoft.Win32.Registry NuGet to C:\FolderPath\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.17.0\tools\.
I haven't been able to reproduce the issue. But if copying the file unblocks you, I can update the NuGet to include it going forward.

Azure: Updated ASP.Net Core SDK to 1.0 to 2.1.203 and getting error about System.Data.SqlClient

I updated and migrated my local project to start using ASP CORE 2.1.0 from 1.0. I followed the ASP CORE migration guideline from Microsoft here:
https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/?view=aspnetcore-2.1
Then 2.0 to 2.1 here:
https://learn.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1
And everything works just fine on my local machine.
After pushing the code, it builds and runs just fine. So no error occurred when running the website. But when I hit the website on my browser, Azure is throwing 500 internal error messages. I checked the logs, and this is what I find:
2018-08-01 07:05:25.682 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel:
Connection id "0HLFNDIE4UDCG", Request id "0HLFNDIE4UDCG:00000003": An
unhandled exception was thrown by the application.
System.InvalidOperationException: Cannot find compilation library location for package 'System.Data.SqlClient'
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List`1 assemblies)
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
...
I tried adding System.Data.SqlClient to my local code using Nuget, and pushed to Azure, and still I get the same problem.
Can someone please explain what's happening here? And why Azure needs this package when it's not part of my project?
This is a reference path issue.
Check for System.Data.SqlClient in the references and verify the location form which the package is referred. It looks like the path is there in your local machine and not available after deployment.
I figured out what I could do.
I went into the azure console, and typed this in:
nuget install System.Data.SqlClient
And it added the package into the system. The error now stopped.

Published Service Stack service returning a 404 error

I've been recently trying out service stack for a future project and have been enjoying the framework. In Visual Studio, I have no issues getting the service to work however it returns a 404 error when trying to reach the resource after being published on IIS. It queries Mongo for the service, so maybe theirs some run time issue there. Anyone have issues after publication where the service didn't work?
I figured out what the issue was. It was a assembly version issue. I had to build all of my projects and then publish.

Not able to setup Umbraco in Visual Studio 2012

I am trying to setup Umbraco in Visual Studio 2012 with Nuget package. After package installation when I try to run it getting following exception.
Type is not resolved for member 'Umbraco.Core.Security.UmbracoBackOfficeIdentity,Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
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.Runtime.Serialization.SerializationException: Type is not resolved for member 'Umbraco.Core.Security.UmbracoBackOfficeIdentity,Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
I don't recommend using nuget for Umbraco. Using a CMS like that, you won't want to update through nuget once you're in production. Best keep it manually. Here is a step by step to get setup in VS with Umbraco.
Open Visual Studio, create a new "ASP.NET Empty Web Application", with a folder for the solution. Here is how I set it up:
C:\_Websites\[MyProject] --> All this in source control
C:\_Websites\[MyProject]\Website --> .sln file is here
C:\_Websites\[MyProject]\Website\[MyProject] --> .csproj and /bin are here
Download the version of Umbraco you want from here: http://our.umbraco.org/download
Unzip that folder and place it in that [MyProject] folder
Once this is in place, setup your hosts file 127.0.0.1 myproject.local
Setup a new website in IIS, set the binding, make sure the app. pool is using framework 4
Back in Visual Studio, click Show All Files in the Solution explorer and refresh. Include everything in your project.
Build solution and run the website using myproject.local, should be good to go!
I like this setup because Umbraco is developer oriented and this way I control everything. I have to add the references I need manually and this makes me more familiar with the platform as I work with it.
I know I'm not helping you with you problem directly, but this is the setup I use and I never have issues with this. Hope this helps!
I had the same issue when using VS Development Server - try running the program as administrator after selecting "Local IIS Web Server" in the Web section your project properties as explained here.

Root element is missing when trying to Publish

It has been a while since I've published my app to Azure. During that time frame, I've upgraded my system from 32-bit to 64-bit meaning a fresh install of Windows and Visual Studio. And Visual Studio Update 3 came out and was applied. When I went to publish an update today, I received the following:
The following exception was thrown trying to publish: Root element is missing.
My web.config file looks fine so I don't think it's this issue.
The app works fine in debug mode so I don't think it's any of the .lsml files as is mentioned here.
And I tried this procedure to hand edit the .ls3proj file but it didn't seem to help.
I previously had an issue trying to publish when I upgraded from the standalone LightSwitch 2011 to Visual Studio 2012. I was able to overcome that issue using the method described in this thread.
Attempting to use this same method resulted in my new project has a full screen error saying "There are critical errors in the application definition metadata..." and 210 individual errors (max errors reached).
The first error, "Cannot create unknown type '{http://schemas.microsoft.com/LightSwitch/2010/xaml/model}GlobalAttributeGroup'." Doesn't make sense because that line in the .lsml is identical from the old project to the new project.
The second error, "Could not find any application definition in the project." Which I do not understand at all.
I am able to publish a simple "Hello, world" style app to my Azure account.
What could be causing this? How can I get more information about exactly which element is causing the issue? The log produced by running devenv /log was not helpful.
Matt Thalman was able to solve my problem over in the Microsoft Forums. The ServiceConfiguration.cscfg and ServiceDefinition.csdef were missing from the project when checked out of version control. Copying those over from a new project restored my ability to publish.

Resources