dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.37k stars 966 forks source link

cachedTypes in AssemblyNamesTypeResolutionService is unreachable #229

Open Liminiens opened 5 years ago

Liminiens commented 5 years ago

Problem description:

Here the field cachedTypes is currently unreachable because it relies on Assembly.GlobalAssemblyCache which is false in .NET Core and IsNetFrameworkAssembly, which is also always false because it tests if assembly Location path is .NET Framework path, while (on Windows) .NET Core assemblies are on C:\Program Files\dotnet\shared\Microsoft.NETCore.App\... path.

Actual behavior:

Types are not cached

Expected behavior:

.NET Core types are cached (?)

zsd4yr commented 5 years ago

@Liminiens do you have a proposed change to rely on other values which are not always false?

Liminiens commented 5 years ago

@zsd4yr i am not sure if it's a correct way, but maybe checking if assembly Location is on ..\dotnet\shared\.. path will do the job?

zsd4yr commented 5 years ago

@Liminiens it's been awhile here; I am wondering exactly what your scenario is in order to determine a viable solution / replacement? Could you provide a little more information about your needs here?

zsd4yr commented 5 years ago

@ericstj do you happen to know what the replacement for Assembly.GlobalAssemblyCache is?

ericstj commented 5 years ago

/cc @jeffschwMSFT It looks like @hughbe fixed the GAC checking here: https://github.com/dotnet/winforms/commit/5e0710c9b943adf4b0b1ab1aa4d266791f81850b#diff-a2cbb3dd218c63ebe4e00266618b9ef5R828, but this still checks IsNetFrameworkPath: https://github.com/dotnet/winforms/blob/f3ae8f699f703645904e384e9ce16316f2ee23c6/src/System.Windows.Forms/src/System/Resources/ResXDataNode.cs#L791.

Since .NETCore is an xcopy-able framework, you shouldn't really be checking any specific path dotnet\shared.

I think to really answer this question you need to understand the reasoning behind this statement: https://github.com/dotnet/winforms/blob/f3ae8f699f703645904e384e9ce16316f2ee23c6/src/System.Windows.Forms/src/System/Resources/ResXDataNode.cs#L927

I'm not sure what this code is imaging might change over the lifetime of these statics: it's not like it can unload assemblies once they've been loaded so future requests for the same type must result in the same type even if it is not cached (since the assembly is effectively cached by the runtime).

weltkante commented 5 years ago

@ericstj

I'm not sure what this code is imaging might change over the lifetime of these statics: it's not like it can unload assemblies once they've been loaded

Might be related to VS usage of ITypeResolutionService, after a build the WinForms Designer will load the newly built version so maybe its referring to that, to avoid having cached the old version of the assembly.