Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run dotnet core application on Mac using dotnet command, but works under vscode #8529

Closed
janvorli opened this issue Jul 24, 2017 · 34 comments
Milestone

Comments

@janvorli
Copy link
Member

@danwalmsley commented on Tue Jul 11 2017

Basically I have an application written for netcoreapp2.0

It runs perfectly via vscode debugger with setting

"console": "internalConsole" (I mention this as it may be a clue to what is happening)

If I tell vscode to use external console or...

If I run it through the terminal on mac and do dotnet ./myapp.dll

I starts to load and crashes with

could not load file or assembly System.Text.RegularExpressions, Version=4.0.0.0

How can it be the case it works under vscode terminal but not bash? How can I get more verbose output that could help you guys diagnose the issue?


@gkhanna79 commented on Wed Jul 12 2017

@steveharter should be able to help out here.


@danwalmsley commented on Fri Jul 14 2017

Thanks! I have the feeling, vscode is using an internal console and its environments / paths, etc is correct, when I use bash something is missing ands its not able to resolve assemblies.


@steveharter commented on Fri Jul 14 2017

@danwalmsley try export COREHOST_TRACE=1 and run again to get verbose output. This will tell you where it is looking for the runtime and related assemblies.

It is possible that the version of System.Text.RegularExpressions that is found is older.


@danwalmsley commented on Fri Jul 14 2017

@steveharter i will try on Monday when I'm in front of the affected system and post back. Thanks


@danwalmsley commented on Mon Jul 17 2017

OK so here is the result:

firstly contents of directory:

AvalonStudio					AvalonStudio.Languages.CSharp.pdb		AvalonStudio.pdb
AvalonStudio.Controls.Standard.dll		AvalonStudio.Projects.CPlusPlus.dll		AvalonStudio.runtimeconfig.dev.json
AvalonStudio.Controls.Standard.pdb		AvalonStudio.Projects.CPlusPlus.pdb		AvalonStudio.runtimeconfig.json
AvalonStudio.Debugging.GDB.JLink.dll		AvalonStudio.Projects.OmniSharp.dll		AvaloniaEdit.dll
AvalonStudio.Debugging.GDB.JLink.pdb		AvalonStudio.Projects.OmniSharp.pdb		AvaloniaEdit.pdb
AvalonStudio.Debugging.GDB.Local.dll		AvalonStudio.Projects.Standard.dll		CorApi.NetCore2.dll
AvalonStudio.Debugging.GDB.Local.pdb		AvalonStudio.Projects.Standard.pdb		CorApi.NetCore2.pdb
AvalonStudio.Debugging.GDB.OpenOCD.dll		AvalonStudio.Repository.dll			CorApi.Portable.dll
AvalonStudio.Debugging.GDB.OpenOCD.pdb		AvalonStudio.Repository.pdb			CorApi.Portable.pdb
AvalonStudio.Debugging.GDB.Remote.dll		AvalonStudio.Toolchains.Clang.dll		CorApi2.NetCore2.dll
AvalonStudio.Debugging.GDB.Remote.pdb		AvalonStudio.Toolchains.Clang.pdb		CorApi2.NetCore2.pdb
AvalonStudio.Debugging.GDB.dll			AvalonStudio.Toolchains.GCC.dll			Mono.Debugging.Win32.dll
AvalonStudio.Debugging.GDB.pdb			AvalonStudio.Toolchains.GCC.pdb			Mono.Debugging.Win32.pdb
AvalonStudio.Debugging.dll			AvalonStudio.Toolchains.LocalGCC.dll		Mono.Debugging.dll
AvalonStudio.Debugging.pdb			AvalonStudio.Toolchains.LocalGCC.pdb		Mono.Debugging.pdb
AvalonStudio.Extensibility.dll			AvalonStudio.Toolchains.STM32.dll		PortableCom.dll
AvalonStudio.Extensibility.pdb			AvalonStudio.Toolchains.STM32.pdb		PortableCom.pdb
AvalonStudio.LanguageSupport.TypeScript.dll	AvalonStudio.Toolchains.Standard.dll		Templates
AvalonStudio.LanguageSupport.TypeScript.pdb	AvalonStudio.Toolchains.Standard.pdb		libhostfxr.dylib
AvalonStudio.Languages.CPlusPlus.dll		AvalonStudio.deps.json				libhostpolicy.dylib
AvalonStudio.Languages.CPlusPlus.pdb		AvalonStudio.dll				native
AvalonStudio.Languages.CSharp.dll		AvalonStudio.dll.config				publish

@danwalmsley commented on Mon Jul 17 2017

The error message when I run the application normally. It can't find AvaloniaEdit.dll, which is included (see prev post with dir listing)

$ dotnet ./AvalonStudio.dll

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> OmniXaml.LoadException: Error loading XAML: System.IO.FileLoadException: Could not load file or assembly 'AvaloniaEdit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An internal error occurred.
 (Exception from HRESULT: 0x8007054F)
File name: 'AvaloniaEdit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at OmniXaml.Typing.TypeRepository.GetByPrefix(String prefix, String typeName)
   at Avalonia.Markup.Xaml.Converters.SelectorTypeConverter.<>c__DisplayClass2_0.<ConvertFrom>b__0(String t, String ns)
   at Avalonia.Markup.Xaml.Parsers.SelectorParser.Parse(String s)
   at OmniXaml.Typing.CommonValueConversion.ConverterStep.TryConvert(Object value, XamlType targetType, IValueContext valueContext, Object& result)
   at OmniXaml.Typing.CommonValueConversion.TryConvert(Object value, XamlType targetType, IValueContext valueContext, Object& result)
   at OmniXaml.ObjectAssembler.StateCommuter.AssignChildToParentProperty()
   at OmniXaml.ObjectAssembler.StateCommuter.AssociateCurrentInstanceToParent()
   at OmniXaml.ObjectAssembler.Commands.ValueCommand.Execute()
   at OmniXaml.ObjectAssembler.ObjectAssembler.Process(Instruction instruction)
   at OmniXaml.TemplateHostingObjectAssembler.Process(Instruction instruction)
   at OmniXaml.XmlParser.Parse(IEnumerable`1 xamlNodes)
   at OmniXaml.XmlLoader.Load(Stream stream, IParser parser)

 ---> System.IO.FileLoadException: Could not load file or assembly 'AvaloniaEdit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An internal error occurred.
 (Exception from HRESULT: 0x8007054F)
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at OmniXaml.Typing.TypeRepository.GetByPrefix(String prefix, String typeName)
   at Avalonia.Markup.Xaml.Converters.SelectorTypeConverter.<>c__DisplayClass2_0.<ConvertFrom>b__0(String t, String ns)
   at Avalonia.Markup.Xaml.Parsers.SelectorParser.Parse(String s)
   at OmniXaml.Typing.CommonValueConversion.ConverterStep.TryConvert(Object value, XamlType targetType, IValueContext valueContext, Object& result)
   at OmniXaml.Typing.CommonValueConversion.TryConvert(Object value, XamlType targetType, IValueContext valueContext, Object& result)
   at OmniXaml.ObjectAssembler.StateCommuter.AssignChildToParentProperty()
   at OmniXaml.ObjectAssembler.StateCommuter.AssociateCurrentInstanceToParent()
   at OmniXaml.ObjectAssembler.Commands.ValueCommand.Execute()
   at OmniXaml.ObjectAssembler.ObjectAssembler.Process(Instruction instruction)
   at OmniXaml.TemplateHostingObjectAssembler.Process(Instruction instruction)
   at OmniXaml.XmlParser.Parse(IEnumerable`1 xamlNodes)
   at OmniXaml.XmlLoader.Load(Stream stream, IParser parser)
   --- End of inner exception stack trace ---
   at OmniXaml.XmlLoader.Load(Stream stream, IParser parser)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Stream stream, Object rootInstance, Uri uri)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Uri uri, Uri baseUri, Object rootInstance)
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded()
   at Avalonia.Markup.Xaml.Styling.StyleInclude.FindResource(String name)
   at Avalonia.Styling.Styles.FindResource(String name)
   at Avalonia.Styling.StyleExtensions.FindStyleResource(IStyleHost control, String name)
   at Avalonia.Markup.Xaml.Data.StyleResourceBinding.Initiate(IAvaloniaObject target, AvaloniaProperty targetProperty, Object anchor, Boolean enableDataValidation)
   at Avalonia.Styling.Setter.Apply(IStyle style, IStyleable control, IObservable`1 activator)
   at Avalonia.Styling.Style.Attach(IStyleable control, IStyleHost container)
   at Avalonia.Styling.Styles.Attach(IStyleable control, IStyleHost container)
   at Avalonia.Styling.Styles.Attach(IStyleable control, IStyleHost container)
   at Avalonia.Styling.Styles.Attach(IStyleable control, IStyleHost container)
   at Avalonia.Styling.Styler.ApplyStyles(IStyleable control, IStyleHost styleHost)
   at Avalonia.Controls.TopLevel..ctor(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver)
   at Avalonia.Controls.WindowBase..ctor(IWindowBaseImpl impl, IAvaloniaDependencyResolver dependencyResolver)
   at Avalonia.Controls.Window..ctor(IWindowImpl impl)
   at AvalonStudio.Controls.SplashScreen..ctor()
   at AvalonStudio.BootScreen..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance[T]()
   at Avalonia.Controls.AppBuilderBase`1.Start[TMainWindow](Func`1 dataContextProvider)
   at AvalonStudio.App.Main(String[] args)
Abort trap: 6

@danwalmsley commented on Mon Jul 17 2017

log.txt

log is very long so put it in the attached text file.


@steveharter commented on Mon Jul 17 2017

Do you know why the error message changed from failing to load System.Text.RegularExpressions to AvaloniaEdit? Does it still work under different vscode settings?

The triggering exception appears to be OmniXaml.LoadException, wrapping a System.IO.FileLoadException for AvaloniaEdit.dll. From the log, that assembly appears to be found by CoreClr at /Users/richard/avalon/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/osx.10.12-x64/AvaloniaEdit.dll.

However I would guess that OmniXaml is doing a custom load of the AvaloniaEdit.dll and is not using the same directory as CoreClr to find that assembly. Perhaps it needs to intercept the assembly resolving events?

Other misc from the log:
App base location:
/Users/richard/avalon/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/osx.10.12-x64
App location:
Users/richard/avalon/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/osx.10.12-x64/AvalonStudio.dll
Launch host:
/usr/local/share/dotnet/dotnet
JIT_PATH:
/Users/richard/.nuget/packages/runtime.osx-x64.microsoft.netcore.app/2.0.0-preview2-25407-01/runtimes/osx-x64/native/libclrjit.dylib
Probing directory:
/Users/richard/.nuget/packages/ with several subdirectories (not complete):
lib/netstandard1.1
Avalonia.Direct2D1/0.5.1-build3417-alpha
avalonia.direct2d1/0.5.1-build3417-alpha/lib/net45
Avalonia.Gtk3/0.5.1-build3417-alpha
avalonia.win32/0.5.1-build3417-alpha/lib/netstandard1.1
Avalonia.Skia.Desktop/0.5.1-build3417-alpha
avalonia.skia.desktop/0.5.1-build3417-alpha/lib/netstandard1.3
Avalonia.Xaml.Behaviors/0.5.0
avalonia.xaml.behaviors/0.5.0/lib/netstandard1.1
avalonia/0.5.1-build3417-alpha/lib/netcoreapp1.0/


@danwalmsley commented on Thu Jul 20 2017

@steveharter sorry for delay, my colleague with mac is away, so I will come back to you once we have access to mac, to give you more information. Thanks Dan


@danwalmsley commented on Mon Jul 24 2017

@steveharter Ok I don't know why the error message changed, i rebuilt from scratch and the error went back to original one. I have attached a new log file, and linked a youtube video so you can see what is happening.

youtube shows me using the console in vscode to invoke the app, and it working.
then me using terminal, and it not working.

avalonstudio.txt

https://www.youtube.com/watch?v=v8C_aJm6WTg&feature=youtu.be

thanks for your patience as I have been slow to respond.


@steveharter commented on Mon Jul 24 2017

From the log, it looks like a previous version of dotnet was installed as it is finding the dotnet executable version 1.0.1 instead of 2.0 preview version. Although I'm not aware of any problems with this (as it should be in "muxer" mode and just forward to the 2.0 preview location) can you please try to replace the dotnet executable with the 2.0 version? At least we can rule that out and then go from there. Thanks.

@livarcocc
Copy link
Contributor

@danwalmsley can you share your csproj. Also, please share the contents of dotnet --info when it is executed in both the console in VS code and the bash terminal.

Also, keep in mind that the CLI does not support XMAL.

@danwalmsley
Copy link

dotnetbug

@danwalmsley
Copy link

@livarcocc sure no problem, project is on GitHub located here:
https://github.com/VitalElement/AvalonStudio

git clone https://github.com/VitalElement/AvalonStudio.git
git submodule update --init
cd AvalonStudio/AvalonStudio/AvalonStudio
dotnet restore
dotnet build

cd bin/Debug/netcoreapp2.0
dotnet ./AvalonStudio.dll

@danwalmsley
Copy link

@steveharter I ran the uninstall dot net script it output the following:
dotnetbug

so there are all the dotnet versions that were installed.

@danwalmsley
Copy link

@livarcocc

Also, keep in mind that the CLI does not support XMAL.

we built our own XAML framework ;) see here: https://github.com/AvaloniaUI/Avalonia

@danwalmsley
Copy link

@livarcocc @steveharter
ok so with the other versions uninstalled and just .net core 2 preview.

I still get the issue: here is the log file with only .net core 2 installed.

avalonstudio.txt

@steveharter
Copy link
Member

@danwalmsley I followed the instructions above, and got this:

Steves-MacBook-Pro:netcoreapp2.0 steveharter$ dotnet ./AvalonStudio.dll
Unhandled Exception: Avalonia.Gtk3.Interop.NativeException: dlsym(RTLD_DEFAULT, gtk_window_set_decorated): symbol not found
   at Avalonia.Gtk3.Interop.UnixLoader.GetProcAddress(IntPtr dll, String proc, Boolean optional)
   at Avalonia.Gtk3.Interop.Resolver.Resolve(String basePath)
   at Avalonia.Gtk3.Gtk3Platform.Initialize()
   at Avalonia.Controls.AppBuilderBase`1.Setup()
   at Avalonia.Controls.AppBuilderBase`1.SetupWithoutStarting()
   at AvalonStudio.App.Main(String[] args) in /Users/steveharter/git/AvalonStudio/AvalonStudio/AvalonStudio/App.paml.cs:line 44
Abort trap: 6

Are there additional dependencies? Gtk?

@danwalmsley
Copy link

ah yes, you need to install gtk3, instructions are:

  1. install brew from http://brew.sh then
brew update
brew install gtk+3

@danwalmsley
Copy link

@steveharter

@danwalmsley
Copy link

Any updates on this?

@danwalmsley
Copy link

@livarcocc @steveharter @janvorli hoping to find a solution to this still, did you guys find out what may be the problem?

@steveharter
Copy link
Member

steveharter commented Sep 15, 2017

I was able to repro the issue. It works with integrated VSCode console, fails with raw console or external console.

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. A device attached to the system is not functioning.
 (Exception from HRESULT: 0x8007001F)
   at System.Xml.XmlTextReaderImpl.DetectEncoding()
   at System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
   at System.Xml.XmlTextReaderImpl.FinishInitStream()
   at System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32 byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr, XmlParserContext context, Boolean closeInput)
   at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
   at Portable.Xaml.XamlXmlReader.CreateReader(Stream stream, XamlXmlReaderSettings settings)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream stream, Object rootInstance, Uri uri)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type type, Object rootInstance)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object obj)
   at AvalonStudio.App.Initialize()
   at Avalonia.Controls.AppBuilderBase`1.Setup()
   at Avalonia.Controls.AppBuilderBase`1.SetupWithoutStarting()

   at AvalonStudio.App.Main(String[] args)

@steveharter
Copy link
Member

@janvorli what do you suggest in terms of additional debugging from CLR side? Is there a way to enable diagnostics to see additional information on assembly loading failure (location, version)? Thanks

@janvorli
Copy link
Member Author

@steveharter the "A device attached to the system is not functioning" could lead us to figure out the culprit. Could you please run it under dtruss? Like sudo dtruss dotnet ./AvalonStudio.dll That should show syscalls it was making and that means also file open requests. The error makes me think that we might be accessing some weird code path.

@janvorli
Copy link
Member Author

You can also try to set the COREHOST_TRACE env var to 1 and see what it dumps.

@livarcocc
Copy link
Contributor

@DustinCampbell since it works in vscode, he may be able to tell us if there is anything different there.

@DustinCampbell
Copy link
Member

@danwalmsley: Could you set "omnisharp.loggingLevel": "trace" option in VS Code provide and the OmniSharp Log?

@DustinCampbell
Copy link
Member

Adding @gregg-miskelly since this is really about running under the VS Code debugger (where it works). @danwalmsley: You can disregard my request above.

@steveharter
Copy link
Member

Here's the dtrace output dtraceoutput.txt. Nothing special about the System.Text.Encoding.Extensions assembly there that I saw.

The method that is failing System.Xml.XmlTextReaderImpl.DetectEncoding() does nothing special except reference some encoding classes including UnicodeEncoding and UTF8Encoding which are located in System.Text.Encoding.Extensions reference assembly (which is failing to load), with its implementation in core. Is it possible that the contract for these classes is not consistent \ correct (I didn't verify yet). Other possibilities?

@gregg-miskelly
Copy link

If you want to get a dtrace while running under the debugger -- there is no way to directly spawn the process both under dtrace and under the debugger at the same time. If dtrace supports attach you could try pausing the process at startup (ex: hitting a breakpoint), going to a separate command window and attaching with dtrace, and then continuing. All the debugger will be doing is running the equivalent of cd <working-directory-from-launch.json> + [ export <env-var-from-launch.json>=<value> ] + dotnet <program-value-from-launch.json> with stdin/out/error redirected to a pipe. So I have zero idea why this would work under a debugger, but not externally unless you are launching a different path or have a different working directory.

@steveharter
Copy link
Member

@gregg-miskelly I took the dtrace outside the debugger which is the failure case. Since there was nothing out of place in the dtrace log for the failing assembly, I don't plan on running dtrace under the debugger. Thanks.

@janvorli
Copy link
Member Author

@steveharter have you also tried my second suggestion - set the COREHOST_TRACE env var to 1 and see what the dotnet command dumps when you try to run the failing app?

@steveharter
Copy link
Member

@janvorli yes I ran with COREHOST_TRACE=1 with nothing obvious. Note also danwalmsley linked his output earlier in this issue.

Also I compared the tail end of the trace output with the output from running within the integrated terminal (success case) and didn't see any differences except for the exception. Here's the tail end:

...
Processing TPA for deps entry [runtime.osx-x64.Microsoft.NETCore.App, 2.0.0-preview2-25407-01, runtimes/osx-x64/lib/netcoreapp2.0/System.Text.Encoding.Extensions.dll]
  Considering entry [runtime.osx-x64.Microsoft.NETCore.App/2.0.0-preview2-25407-01/runtimes/osx-x64/lib/netcoreapp2.0/System.Text.Encoding.Extensions.dll] and probe dir [/usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01]
    Local path query exists /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/System.Text.Encoding.Extensions.dll
    Probed deps json and matched '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/System.Text.Encoding.Extensions.dll'
Adding tpa entry: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/System.Text.Encoding.Extensions.dll
...
NATIVE_DLL_SEARCH_DIRECTORIES = /Users/steveharter/.nuget/packages/avalonstudio.languages.cplusplus.libclang/4.0.0.2/runtimes/osx/native:/Users/steveharter/.nuget/packages/skiasharp/1.57.1/runtimes/osx/native:/usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01:
Property PLATFORM_RESOURCE_ROOTS = 
Property AppDomainCompatSwitch = UseLatestBehaviorWhenTFMNotSpecified
Property APP_CONTEXT_BASE_DIRECTORY = /Users/steveharter/git/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/
Property APP_CONTEXT_DEPS_FILES = /Users/steveharter/git/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/AvalonStudio.deps.json;/usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/Microsoft.NETCore.App.deps.json
Property FX_DEPS_FILE = /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/Microsoft.NETCore.App.deps.json
Property PROBING_DIRECTORIES = /usr/local/share/dotnet/store/x64/netcoreapp2.0:/Users/steveharter/.nuget/packages:
Property JIT_PATH = /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0-preview2-25407-01/libclrjit.dylib
Launch host: /usr/local/share/dotnet/dotnet, app: /Users/steveharter/git/AvalonStudio/AvalonStudio/AvalonStudio/bin/Debug/netcoreapp2.0/AvalonStudio.dll, argc: 0, args: 
Directory core breadcrumbs [] was not specified or found
Fallback directory core breadcrumbs at [opt/corebreadcrumbs] was not found
--- Begin breadcrumb write
Breadcrumb store was not obtained... skipping write.

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. A device attached to the system is not functioning.
 (Exception from HRESULT: 0x8007001F)
   at System.Xml.XmlTextReaderImpl.DetectEncoding()
   at System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
   at System.Xml.XmlTextReaderImpl.FinishInitStream()
   at System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32 byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr, XmlParserContext context, Boolean closeInput)
   at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
   at Portable.Xaml.XamlXmlReader.CreateReader(Stream stream, XamlXmlReaderSettings settings)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream stream, Object rootInstance, Uri uri)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type type, Object rootInstance)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object obj)
   at AvalonStudio.App.Initialize()
   at Avalonia.Controls.AppBuilderBase`1.Setup()
   at Avalonia.Controls.AppBuilderBase`1.SetupWithoutStarting()
   at AvalonStudio.App.Main(String[] args)

@steveharter
Copy link
Member

Going forward, I'll attempt a simple repro on the box trying to trigger\reference the failing assembly. If that doesn't lead to anything, I will likely do a local build of coreclr and debug that.

@janvorli
Copy link
Member Author

I have just realized that the error message has nothing to do with a device not being functioning. It is the generic ERROR_GEN_FAILURE that is reported when something fails and there is no suitable error code for that. There are just a few places where we generate such a code. We can ignore majority of those that are generated during PAL initialization and so there seem to be only two places left.
First place is in src\pal\src\exception\machexception.cpp in InjectActivationInternal when thread_suspend call fails. The second is in the same file / function when thread_resume fails. The first one is most likely not the issue, since otherwise PAL would print an error message into console. The second one is very unlikely.
The third and last one is in src/pal/src/file/file.cpp in FILEGetLastErrorFromErrno. This transforms Unix file I/O error to Windows error and it would generate the ERROR_GEN_FAILURE in case it was passed errno that we didn't recognize. So this sounds to me like the most likely place where our error stems from. This function is called from many places in PAL, so if we discover it is the culprit, we would need to look at the call stack at the point of failure to see where it really came from.

I would recommend building coreclr from the same commit as the one that's being used now was built from (run strings libcoreclr.so | grep "@(#)" to get the commit number) with the FILEGetLastErrorFromErrno patched to call printf instead of ERROR in the "default" case by the end of the function. Then replace the libcoreclr.so with this new one and run your test. If the problem is really there, the errno would get printed. That alone might give us a clue, but we can later run it under a debugger to be able to view the call stack at the point of failure.

@steveharter
Copy link
Member

steveharter commented Sep 18, 2017

@danwalmsley: Could you set "omnisharp.loggingLevel": "trace" option in VS Code provide and the OmniSharp Log?

@DustinCampbell, I assume the log is stored as a file? Where at? (didn't see it in stdout or stderr)

@steveharter
Copy link
Member

Success!

@janvorli with the custom coreclr, the error was indeed at the third location you thought it would be (FILEGetLastErrorFromErrno) and was returning:

unexpected errno 24 (Too many open files); returning ERROR_GEN_FAILURE

I then ran from within my test console:

ulimit -S -n 512

to bump the max number of open files from 256 to 512, which resulted in the success case of the AvalonStudio window in opening.

@steveharter
Copy link
Member

Next steps? Add a release note? Make a call to setrlimit to increase the limit programmatically?

@steveharter steveharter removed their assignment Sep 18, 2017
@janvorli
Copy link
Member Author

@steveharter Great!
One of the next steps should be to fix the error translation so that it returns ERROR_TOO_MANY_OPEN_FILES for the errno 24 instead of ERROR_GEN_FAILURE.
I would also try to investigate to make sure we don't have a bug that would cause not closing some specific files correctly and leaving unnecessarily many files open.
As for setrlimit for file descriptors, we are actually calling that and attempting to set the RLIMIT_NOFILE to the max allowed value. So there is probably something wrong there too.
I'll look into both of these things.

@janvorli
Copy link
Member Author

I've looked into the rlimit stuff. Although we call setrlimit and pass in the rlim_max that we get from getrlimit, the setrlimit with that value fails. In the PAL initialization, we consider this just a soft error and only report something to the PAL debug channel in debug builds of coreclr. So in our case here, nothing happens and the limit is not set.
The reason for that failure is actually described in the OSX specific manpage for setrlimit:

setrlimit() now returns with errno set to EINVAL in places that historically succeeded. It no longer accepts "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE. Use "rlim_cur = min(OPEN_MAX, rlim_max)".

@janvorli
Copy link
Member Author

@anwalmsley could you please check if e.g. it ulimit -S -n 10000 fixes the issue for you? That would confirm that it is really the same issue as @steveharter has reproduced.

@danwalmsley
Copy link

@janvorli hey, sorry I didn't notice this thread, I will try and run the test this week.

Thanks for all your efforts in diagnosing and fixing :)

@livarcocc
Copy link
Contributor

@danwalmsley any updates on this repro?

@livarcocc
Copy link
Contributor

I am going to close this issue since this seems like a too many files open problem and the fix is not in the CLI but in the CoreCLR, if I read this thread right.

If that's not the case, please comment or re-activate.

@danwalmsley thanks for reporting and @janvorli and @steveharter thanks for investigating.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the Discussion milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants