Errors in .NET 6 Hello World console application - c#

After following the steps from Microsoft for setting up a new Console Application in .NET 6.0, I immediately get syntax errors from Intellisense. However, when I do dotnet run, the program runs as expected. weird
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Here's a screenshot of the folder, sample code and terminal
Program: Predefined type 'System.Object' is not defined or imported [HelloWorld]
Void: Predefined type 'System.Void' is not defined or imported [HelloWorld]
string: Predefined type 'System.String' is not defined or imported [HelloWorld]
Console: The name 'Console' does not exist in the current context [HelloWorld]
.NET SDKs installed
5.0.201 [C:\Program Files\dotnet\sdk]
6.0.102 [C:\Program Files\dotnet\sdk]
HelloWorld.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Relevant VS Code Extensions:
C# v1.24.0

For me, worked when i deleted the ".vs" hidden folder. this folder was in the same location of ".sln" file

Deleting .vs worked for me.
Problem seemed to start after an MS Windows (10 pro) update.
Problem also accompanied by a VS 2022 (17.2.6) recoverable exception when trying to display a project properties (see below).
For all its worth, when rebuilding all projects in the solution (12 of them) compile with no errors and the code runs just fine - yet the editor shows tons of errors (but not in all files or projects - weird).
Call stack for the exception:
=====================
7/20/2022 11:31:27 AM
Recoverable
Microsoft.VisualStudio.ProjectSystem.Query.QueryExecutionException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.EntryPointFinder.FindEntryPoints(INamespaceSymbol symbol)
at Microsoft.VisualStudio.ProjectSystem.Properties.StartupObjectsEnumGenerator.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.ProjectSystem.PropertyPages.PageDynamicEnumProperty.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Query.SupportedValueDataProducer.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Query.QueryDataFromProviderStateProducerBase1.<SendRequestAsync>d__0.MoveNext() --- End of inner exception stack trace --- at Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription1.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription1.<>c__DisplayClass8_0.<<Start>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<InitializeAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertiesEditor.<>c__DisplayClass0_0.<<-ctor>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.AsyncLoadContent.<>c__DisplayClass0_0.<b__0>d.MoveNext()

Related

Visual Studio 2022 Visual View Designer Timout

Win11 Pro Visual Studio 2022 v17.3.4 C# .NET6.0
Trying to create a visual component library for use with C#. I successfully create a class library following several videos that I have watched online.
When I try to open View Designer, I get the dialog shown below and it will eventually time out with the Call Stack shown below.
The solution is setup for Class Library, .NET 6.0, Any CPU (I've also tried x64), Target OS Windows, Target OS version 10.0.226221.
From another online post, I used Manage NuGet Packages to install Microsoft.VisualStudio.Designer.Interfaces and Microsoft.VisualStudio.Interop to my solution.
I have downloaded the latest VS and installed as instructed by a MS post on this issue.
I have tried all the solutions from the following post but this is solving the issue for a Windows Forms .NET solution,
Visual Studio 2022 WinForms designer hang on "Loading Designer..."
The problem still exists.
Any help would be greatly appreciated.
John
at Microsoft.DotNet.DesignTools.Client.Host.ServerProcess.d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.Host.ServerProcess.d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.Host.ServerHostFactory.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.DesignToolsClientLoader.d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.DesignToolsClientLoader.<>c__DisplayClass25_1.<<-ctor>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.DesignToolsClientLoader.d__27.MoveNext()

ASP .Net Core 2 Self Contained Deployment giving 502.5 Error in IIS under different App Pool Identity Account

I have an ASP .Net Core 2 Web Api application targeting netcoreapp2.1 and deploying as self-contained (produces an exe) to IIS.
On this server the app will work with the existing App Pool configured to run under a specific AD account.
When we change it to use a different account which appears to have the same permissions to the folders as the first account, the app won't start and gives a 502.5 error.
Here's the really weird part. If we run another site pointed to the same application folder but under the first AD account it works and THEN run the site with the seconds AD account, it will now work perfectly fine.
Another bit of info, the physical location of the application files is on a network share. When we move the physical files to the IIS server (to run it locally) it will work but due to our enterprise setup, this isn't an option in production. So it seems it might be related to some sort of permission/policy for starting the exe from a network share using UNC file path.
UPDATE
The files are shared from a NAS not a Windows Server share. Also, I have determined that for the user this fails for the application reports that it runs in the Internet zone whereas the other user it runs in the Intranet zone.
How are these zones determined?
Below is the stdout logs when it fails.
Unhandled Exception: System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass22_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindEndpointAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.<BindAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.<BindAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<StartAsync>d__22`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.<StartAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.<RunAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.<RunAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at MyApp.Program.Main(String[] args)
To resolve this issue, you need to publish the website/project as a self-contained application. In order to publish it as a self-contained application, please add this to the csproj folder.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RuntimeIdentifiers>win7-x64;win7-x86;ubuntu.16.04-x64;</RuntimeIdentifiers>
<SuppressDockerTargets>True</SuppressDockerTargets>
</PropertyGroup>
Hope this help!
For our issue, it turns out that the account under which the site is running must have read permissions at every directory level of the NAS file share path. Once this was done, the server started correctly.

The project system has encountered an error When trying to load project

In Visual Studio 2017 v15.7.1 I am getting the following error window when trying to load one of my projects:
And when I go to the path specified, inside the test file I find a very long stack-trace which I could not copy all of it because it exceeds allowed characters count.
===================== 5/31/2018 3:40:57 PM LimitedFunctionality System.AggregateException: Project system data flow
'ProjectBuildSnapshotService Outer 320459' closed because of an
exception: System.AggregateException: One or more errors occurred.
---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. --->
System.AggregateException: One or more errors occurred. --->
System.NullReferenceException: Object reference not set to an instance
of an object. at
Microsoft.VisualStudio.ProjectServices.DesignTimeBuilder.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Build.DesignTimeBuilderService.BuilderLifetimeHelper.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Build.DesignTimeBuilderService.d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
Microsoft.VisualStudio.ProjectSystem.Build.DesignTimeBuilderService.d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at
Microsoft.VisualStudio.ProjectSystem.Build.DesignTimeBuildManagerService.d__55.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at
Microsoft.VisualStudio.ProjectSystem.Build.DesignTimeBuildManagerService.d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Designers.ProjectBuildSnapshotService.d__74.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at
Microsoft.VisualStudio.ProjectSystem.Designers.ProjectBuildSnapshotService.<>c__DisplayClass72_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.Threading.JoinableTask.d__78.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.Threading.JoinableTask1.<JoinAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Designers.ProjectBuildSnapshotService.<UpdateSnapshotCoreAsync>d__72.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at
Microsoft.VisualStudio.ProjectSystem.Designers.CustomizableBlockSubscriberBase3.d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Designers.CustomizableBlockSubscriberBase3.<>c__DisplayClass32_0.<<Initialize>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.Threading.JoinableTask.<JoinAsync>d__78.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.Designers.CustomizableBlockSubscriberBase3.<b__32_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Microsoft.VisualStudio.ProjectSystem.DataflowExtensions.<>c__DisplayClass24_0`2.<b__0>d.MoveNext()
I found that you need to do two steps to resolve this issue:
Delete the .vs folder at the solution level.
Delete the bin and obj folders in all projects within the solution.
I encountered the issue in Visual Studio 2017 v15.7.4 and the affected project/solution was created in v15.7.4, so it can occur without upgrading to a new version of Visual Studio.
Try deleting bin and obj folders in all projects of that solution.
Probably those folders were having old files generated by some older version of visual studio, which are not compatible with new version of visual studio.
I want to share a shell script that recursively removes bin and obj directories from the current directory
Navigate to the root directory of your solution via git bash or wsl
Run
find . -type d \( -name bin -o -name obj \) -exec rm -r "{}" \;
Enjoy!

How do i solve 'Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException'

I have just created new ASP.NET Core Web Application using predefined templates e.g `File > New > Project > Asp.Net Core Web Application'.
I select .NET Core 2.0 with Angular template.
I am using VS 2017.
The node version installed on my machine is 4.2.2
NPM version is 2.14.7
When i run i get exception
{Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException:
Unexpected token { SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (c:\users\MyApp\node_modules\#ngtools\webpack\src\index.js:30:10)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10) at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.d__131.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.AspNetCore.NodeServices.NodeServicesImpl.d__101.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__101.MoveNext()}
The reason i see for this problem is basically you are using older versions of Node and NPM. Like you said "The node version installed on my machine is 4.2.2 NPM version is 2.14.7"
You need to update them
Node: 6.11.2
NPM: 3.10.10.
Then problem shall be fixed.

Can an ASP.NET 5 app communicate to MS SQL Server if it runs on Ubuntu?

I created a new ASP.NET 5 web application using the new application wizard in Visual Studio 2015, code on bitbucket here. After a bit of trouble with dnvm runtime setup, I got the sources to run on Ubuntu 14.04 LTS, well enough that the main static html page loads, while dnx web serves up my application. However if I click on the Register link, and try to put an email and password in I get "Error. An error occurred processing your request" on the web UI side, and on the dnx web side, I get this:
error : [Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware]
An unhandled exception has occurred: Could not load file or assembly
'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
...
File name: 'System.Data.SqlClient'
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at Microsoft.Data.Entity.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
at AspNetWebApplication.Controllers.AccountController.EnsureDatabaseCreated(ApplicationDbContext context)
at AspNetWebApplication.Controllers.AccountController.<Register>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.<CastToObject>d__8`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__50.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.Template.TemplateRoute.<RouteAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__5.MoveNext()
It appears that lazy initialization is occurring, and that the System.Data.SqlClient class load fails.
The assembly exists in the "dnx cache" at ~/.dnx/packages/System.Data.SqlClient/4.0.0-beta-23409.
I am assuming that the actual problem must be that the System.Data.SqlClient is not loading because it's actually not compatible with DNX and the Ubuntu coreclr x64 runtime environment. Alternatively perhaps I have to do something else to configure my app (a web.config or environment variable or something?). But in that case I would have expected the class to load, and fail to connect. I was kind of expecting it would try to find an MS SQL LocalDb instance just like it would try to find one on windows, but it doesn't, it just doesn't load, as if the .Net assembly itself was missing.
Update: It is interesting to look at packages like System.Text.Encoding. When NuGet fetches them, it has SEVEN, count-em SEVEN different actual DLLs in its package cache, by platform/os, each copy is in a different subfolder and those folders have these names:
DNXCore50 MonoTouch10 netcore50 xamarinmac20
MonoAndroid10 net46 xamarinios10
I believe that the System.Data.SqlClient, having not shipped any netcoreXX or DNXCoreXX variant folders in its nuget package, makes that package effectively non-portable though without any warning to users. So the class load failure is simply that NuGet has a package with that name, but it doesn't contain a variant folder that can be found and loaded by the coreclr x64 on ubuntu.
Update 19 November
As of ASP.NET 5 RC1 it should now be possible to use coreclr's System.Data.SqlClient on linux provided you have Multiple Active Result Sets turned off. See the release notes on Cross-platform SQL Client here.
It is possible to have ASP.NET 5 running linux communicate to MS MSQL, but perhaps not using the coreclr runtime.
System.Data.SqlClient was only flagged as Done on 14 October in corefx, and beta8 was released October 15. I'm unsure if it ended up being included in beta8 but the error you have posted is the same as that of beta7 which makes me believe the library is still not included. Your investigations also seem to point at this.
If this is the case your only option to run it on linux is using the mono runtime (same as beta7). To do this, remove the "dnxcore50": { } line from your project.json and tell dnvm to target mono rather than coreclr. This then also requires mono (4.1 or later I think) to be installed on your linux box.
If you don't want to install mono on the box, a mono-based aspnet 5 docker image is also an option.

Categories