deepgram/deepgram-dotnet-sdk

Problem on Unity / Android (UnauthorizedAccessException on file system stemming from PhysicalFilesWatcher)

ecsplendid opened this issue · 1 comments

What is the current behavior?

When I run on Android (with Unity, so lots of weird stuff happening like byte code stripping and transpiling)

I get this

IOException: Permission denied

Rethrow as UnauthorizedAccessException: Access to the path '/' is denied.
System.IO.Enumeration.FileSystemEnumerator`1[TResult].CreateDirectoryHandle (System.String path, System.Boolean ignoreNotFound) (at <00000000000000000000000000000000>:0)
System.IO.Enumeration.FileSystemEnumerator`1[TResult]..ctor (System.String directory, System.IO.EnumerationOptions options) (at <00000000000000000000000000000000>:0)
System.IO.Enumeration.FileSystemEnumerable`1+DelegateEnumerator[TResult]..ctor (System.IO.Enumeration.FileSystemEnumerable`1[TResult] enumerable) (at <00000000000000000000000000000000>:0)
System.IO.Enumeration.FileSystemEnumerable`1[TResult]..ctor (System.String directory, System.IO.Enumeration.FileSystemEnumerable`1+FindTransform[TResult] transform, System.IO.EnumerationOptions options) (at <00000000000000000000000000000000>:0)
System.IO.Enumeration.FileSystemEnumerableFactory.UserDirectories (System.String directory, System.String expression, System.IO.EnumerationOptions options) (at <00000000000000000000000000000000>:0)
System.IO.Directory.InternalEnumeratePaths (System.String path, System.String searchPattern, System.IO.SearchTarget searchTarget, System.IO.EnumerationOptions options) (at <00000000000000000000000000000000>:0)
System.IO.Directory.GetDirectories (System.String path, System.String searchPattern, System.IO.EnumerationOptions enumerationOptions) (at <00000000000000000000000000000000>:0)
System.IO.DefaultWatcher.DoFiles (System.IO.DefaultWatcherData data, System.String directory, System.Boolean dispatch) (at <00000000000000000000000000000000>:0)
System.IO.DefaultWatcher.UpdateDataAndDispatch (System.IO.DefaultWatcherData data, System.Boolean dispatch) (at <00000000000000000000000000000000>:0)
System.IO.DefaultWatcher.StartDispatching (System.Object handle) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher () (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken (System.String filter) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[TState]..ctor (System.Func`1[TResult] changeTokenProducer, System.Action`1[T] changeTokenConsumer, TState state) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.Primitives.ChangeToken.OnChange (System.Func`1[TResult] changeTokenProducer, System.Action changeTokenConsumer) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor (Microsoft.Extensions.Configuration.FileConfigurationSource source) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build (Microsoft.Extensions.Configuration.IConfigurationBuilder builder) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.Configuration.ConfigurationBuilder.Build () (at <00000000000000000000000000000000>:0)
Deepgram.Configuration..ctor () (at <00000000000000000000000000000000>:0)
Deepgram.Configuration..cctor () (at <00000000000000000000000000000000>:0)
Deepgram.DeepgramClient.InitializeCredentials (Deepgram.Credentials credentials) (at <00000000000000000000000000000000>:0)
Deepgram.DeepgramClient..ctor (Deepgram.Credentials credentials) (at <00000000000000000000000000000000>:0)
AudioProcessor.Start () (at <00000000000000000000000000000000>:0)
Rethrow as TypeInitializationException: The type initializer for 'Deepgram.Configuration' threw an exception.
Deepgram.DeepgramClient.InitializeCredentials (Deepgram.Credentials credentials) (at <00000000000000000000000000000000>:0)
Deepgram.DeepgramClient..ctor (Deepgram.Credentials credentials) (at <00000000000000000000000000000000>:0)
AudioProcessor.Start () (at <00000000000000000000000000000000>:0)

I had already wondered why DeepGram has so many random dependencies, I had to add all of these nuget packages;

<!-- All of the above is just needed for deepgram API  -->
  <package id="Deepgram" version="1.8.0" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="6.0.0" />
<package id="Microsoft.Extensions.Primitives" version="6.0.0" />
<package id="System.Runtime.CompilerServices.Unsafe" version="7.0.0-preview.2.22152.2" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.Logging" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="7.0.0-rc.1.22426.10" />
<package id="System.Text.Json" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.Configuration" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.Configuration.Json" version="7.0.0-rc.1.22426.10" />
<package id="System.Threading.Channels" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.Options" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0-rc.1.22426.10" />
<package id="System.Text.Encodings.Web" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.DependencyInjection" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.FileProviders.Physical" version="7.0.0-rc.1.22426.10" />
<package id="System.Diagnostics.DiagnosticSource" version="7.0.0-rc.1.22426.10" />
<package id="Microsoft.Extensions.FileSystemGlobbing" version="7.0.0-rc.1.22426.10" />

Some of them made me wonder, why do you need to do all this file system stuff anyway?

Unity is difficult to work with and we have already had to re-write from scratch most SDKs for other APIs we use. I am hoping we don't have to do that again for Deepgram!

Looking at the stack trace it looks like InitializeCredentials is trying to monitor the file system. I certainly do not want it to be doing this anyway, can we disable it?

Please tell us about your environment

  • Unity
  • Android

I checked the source code

image

If I pass an apiUrl then the config file / file watcher doesn't happen i.e.

_deepgramConnection = new DeepgramClient(new Credentials("xxx", "api.deepgram.com"));

I just pass the default value "api.deepgram.com" -- so this is a good solution for me