gsemac / Gsemac.Common

A collection of .NET utilities for use across my projects
MIT License
8 stars 3 forks source link

Gsemac.Net.WebClientFactory.Default fails when attempting to get localization string for Method #10

Open CobaltGoldCS opened 1 year ago

CobaltGoldCS commented 1 year ago

Attached below are the relevant snippets of code

image image

serviceProvider.GetRequiredService<IWebClientFactory>(); is the failure point, which seems to call WebClientFactory.Default in the background

EDIT:

I think I've tracked it down to the private WebClient constructor in the WebClientFactory, although I don't see anything in the constructor that would trigger an Exception like this

gsemac commented 1 year ago

Do you have a stack trace I could look at? There shouldn't be any file system access going on here, so it's possible it's coming from elsewhere.

CobaltGoldCS commented 1 year ago
```0x26 in System.Reflection.Assembly.Load  C#
0x55 in System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly  C#
0x4 in System.Resources.ManifestBasedResourceGroveler.InternalGetSatelliteAssembly  C#
0x4D in System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly C#
0x31 in System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet C#
0xA4 in System.Resources.ResourceManager.InternalGetResourceSet C#
0x5A in System.Resources.ResourceManager.GetString  C#
0xF in Gsemac.Net.Properties.DefaultHttpHeaders.get_Method  C#
0x1F in Gsemac.Net.Http.HttpWebRequestOptions..ctor C#
0x0 in Gsemac.Net.Http.HttpWebRequestOptions.get_Default    C#
0x1 in Gsemac.Net.Http.HttpWebRequestFactory..ctor  C#
0x0 in Gsemac.Net.Http.HttpWebRequestFactory.get_Default    C#
0x2E in Spindler.Services.NextChapterService.CheckChaptersInBookList at A:\Dylan\Documents\Programming\C#\Spindler\Spindler\Services\NextChapterService.cs:57,13    C#
0x2F in System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Spindler.Services.NextChapterService.<CheckChaptersInBookList>d__5>    C#
0x1 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IEnumerable<Spindler.Models.Book>.Start<Spindler.Services.NextChapterService.<CheckChaptersInBookList>d__5>    C#
0x35 in Spindler.Services.NextChapterService.CheckChaptersInBookList    C#
0xF6 in Spindler.Services.NextChapterService.CheckChaptersInBookList at A:\Dylan\Documents\Programming\C#\Spindler\Spindler\Services\NextChapterService.cs:49,13    C#
0x11 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IEnumerable<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.NextChapterService.<CheckChaptersInBookList>d__4>.ExecutionContextCallback  C#
0x42 in System.Threading.ExecutionContext.RunInternal   C#
0x46 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IEnumerable<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.NextChapterService.<CheckChaptersInBookList>d__4>.MoveNext  C#
0x2 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IEnumerable<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.NextChapterService.<CheckChaptersInBookList>d__4>.MoveNext   C#
0x3C in System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction    C#
0x68 in System.Threading.Tasks.Task.RunContinuations    C#
0x16 in System.Threading.Tasks.Task.FinishContinuations C#
0x4C in System.Threading.Tasks.Task<System.Collections.Generic.List<Spindler.Models.Book>>.TrySetResult C#
0x1F in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.List<Spindler.Models.Book>>.SetExistingTaskResult C#
0x1C in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.List<Spindler.Models.Book>>.SetResult C#
0x184 in Spindler.Services.DataService.GetBooksByBooklistIdAsync at A:\Dylan\Documents\Programming\C#\Spindler\Spindler\Services\DataService.cs:89,12   C#
0x11 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.List<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.DataService.<GetBooksByBooklistIdAsync>d__10>.ExecutionContextCallback C#
0x42 in System.Threading.ExecutionContext.RunInternal   C#
0x46 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.List<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.DataService.<GetBooksByBooklistIdAsync>d__10>.MoveNext C#
0x2 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.List<Spindler.Models.Book>>.AsyncStateMachineBox<Spindler.Services.DataService.<GetBooksByBooklistIdAsync>d__10>.MoveNext  C#
0x3C in System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction    C#
0x68 in System.Threading.Tasks.Task.RunContinuations    C#
0x16 in System.Threading.Tasks.Task.FinishContinuations C#
0x1F in System.Threading.Tasks.Task.FinishStageThree    C#
0xF4 in System.Threading.Tasks.Task.FinishStageTwo  C#
0x9 in System.Threading.Tasks.Task.Finish   C#
0xCD in System.Threading.Tasks.Task.ExecuteWithThreadLocal  C#
0x32 in System.Threading.Tasks.Task.ExecuteEntryUnsafe  C#
0x2 in System.Threading.Tasks.Task.ExecuteFromThreadPool    C#
0xC in System.Threading.ThreadPoolWorkQueue.DispatchWorkItem    C#
0x142 in System.Threading.ThreadPoolWorkQueue.Dispatch  C#
0x67 in System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart  C#
0x1F in System.Threading.Thread.StartHelper.RunWorker   C#
0x28 in System.Threading.Thread.StartHelper.Run C#
0xF in System.Threading.Thread.StartCallback    C#```

I have a feeling that its an assembly loading issue, which might be the fault of dotnet maui

Here seems to be the more relevant part

    0x26 in System.Reflection.Assembly.Load C#
    0x55 in System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly  C#
    0x4 in System.Resources.ManifestBasedResourceGroveler.InternalGetSatelliteAssembly  C#
    0x4D in System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly C#
    0x31 in System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet C#
    0xA4 in System.Resources.ResourceManager.InternalGetResourceSet C#
    0x5A in System.Resources.ResourceManager.GetString  C#
    0xF in Gsemac.Net.Properties.DefaultHttpHeaders.get_Method  C#
    0x1F in Gsemac.Net.Http.HttpWebRequestOptions..ctor C#
    0x0 in Gsemac.Net.Http.HttpWebRequestOptions.get_Default    C#
    0x1 in Gsemac.Net.Http.HttpWebRequestFactory..ctor  C#
    0x0 in Gsemac.Net.Http.HttpWebRequestFactory.get_Default    C#
    0x2E in Spindler.Services.NextChapterService.CheckChaptersInBookList at A:\Dylan\Documents\Programming\C#\Spindler\Spindler\Services\NextChapterService.cs:57,13    C#
CobaltGoldCS commented 1 year ago

I have looked through the call stack, and the Gsemac.Net.Properties.DefaultHttpHeaders.get_Method seems to be causing the failure. Looking through DefaultHttpHeaders.Designer.cs I see a lot of generated code, which may be the culprit.

I wonder if the compiler cannot resolve ResourceManager, probably the "Method" string My hunch is that it's trying to load "" as an assembly file for some reason

gsemac commented 1 year ago

It seems to be related to MAUI. I was able to find some some discussions related to this issue:

dotnet/maui#13784 dotnet/runtime#103994

It doesn't seem like it's getting any useful attention, though. I'll mess around with it and see if I can reproduce the issue and find some kind of workaround.

EDIT: I created a new MAUI app and attempted to instantiate a WebClient via WebClientFactory, and did not encounter any exceptions. I'm really not sure what's going on. 🤔

CobaltGoldCS commented 1 year ago

Looks like the bug only happens sometimes, which is even more bizarre 🤔.

Edit: It happens about 90% of the time for me, but sometimes it passes by fine.