unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.88k stars 719 forks source link

No longer supported ms-appx in ResourceDictionary source from v2.0 #4790

Closed Daoting closed 3 years ago

Daoting commented 3 years ago

Current behavior

I haven't upgraded recently and have been using V3.1.6. There was an error running after upgrading to v4.0 today, and this error starts with v2.0.

App.xaml The generated code for App_xxx.g.cs is the same as v3.1.6. The ms-appx:///Dt.Base/Themes/Generic.xaml is in class library Dt.Base. GlobalStaticResources.g.cs in Dt.Base:

        // Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources
        public static void RegisterResourceDictionariesBySource()
        {
            if(!_dictionariesRegistered)
            {
                _dictionariesRegistered = true;
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Base_8668ae864c039084f93be925225e352e_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Desk_458f85e1800a3bc55cf6266b03a4619f_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Dialog_fe6438ceeae26ec062607d998e265911_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => FileList_dc082ac2952b60a36d8030f3a21fa2b3_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => FormView_c9c6509c9c92d49cf4fd18e2993f91d9_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Generic_4a05253b87122aeaab4d7e007a8eed85_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Global_c2decc6413d3e2cfb44cd22a13eca9ad_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => ListView_ad8b8c9037c489fdcec25d6b505a2f2d_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Menu_9eb8f8b4d5f6bc938ccbcac51e90c201_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Sketch_df88f108f6e46bc5500fc5dc06f32120_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => TreeView_fc2a8dfbffbe86d22dcb55c657b12818_ResourceDictionary);
                global::Uno.UI.ResourceResolver.RegisterResourceDictionaryBySource(uri: "ms-appx:///Dt.Base/", context: __ParseContext_, dictionary: () => Win_9be52796d2b6275cbc33bc9223e3f8d9_ResourceDictionary);
            }
        }

ResourceResolver.cs

        public static void RegisterResourceDictionaryBySource(string uri, XamlParseContext context, Func<ResourceDictionary> dictionary)
        {
            _registeredDictionariesByUri[uri] = dictionary;

            if (context != null)
            {
                // We store the dictionaries inside a ResourceDictionary to utilize the lazy-loading machinery
                var assemblyDict = _registeredDictionariesByAssembly.FindOrCreate(context.AssemblyName, () => new ResourceDictionary());
                var initializer = new ResourceDictionary.ResourceInitializer(dictionary);
                _assemblyRef++; // We don't actually use this key, we just need it to be unique
                assemblyDict[_assemblyRef] = initializer;
            }
        }

Is it because the path ms-appx:///Dt.Base/ is incomplete? If the bug is easy to fix, please prioritize it because i can't start the project right now.

The output is:

Loaded assembly: System.Runtime.Serialization.dll [External]
12-23 06:47:34.177 D/Mono    ( 5701): DllImport searching in: '__Internal' ('(null)').
12-23 06:47:34.177 D/Mono    ( 5701): Searching for 'java_interop_jnienv_throw'.
12-23 06:47:34.177 D/Mono    ( 5701): Probing 'java_interop_jnienv_throw'.
12-23 06:47:34.177 D/Mono    ( 5701): Found as 'java_interop_jnienv_throw'.
12-23 06:47:35.941 E/mono    ( 5701): 
12-23 06:47:35.941 E/mono    ( 5701): Unhandled Exception:
12-23 06:47:35.941 E/mono    ( 5701): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Cannot locate resource from 'ms-appx:///Dt.Base/Themes/Generic.xaml'
12-23 06:47:35.941 E/mono    ( 5701):   at Uno.UI.ResourceResolver.RetrieveDictionaryForSource (System.String source, System.String currentAbsolutePath) [0x0003a] in C:\a\1\s\src\Uno.UI\UI\Xaml\ResourceResolver.cs:366 
12-23 06:47:35.941 E/mono    ( 5701):   at Dt.Shell.App.InitializeComponent () [0x0007f] in D:\Dt\Client\Dt.Shell.Droid\obj\Debug\100\g\XamlCodeGenerator\App_a9a445e08e07b50e74be0d8d3c09428f.g.cs:74 
12-23 06:47:35.941 E/mono    ( 5701):   at Dt.Shell.App..ctor () [0x00008] in D:\Dt\Client\Common\App.xaml.cs:29 
12-23 06:47:35.941 E/mono    ( 5701):   at App.Droid.Application+<>c.<.ctor>b__0_0 () [0x00000] in D:\Dt\Client\Dt.Shell.Droid\MainActivity.cs:24 
12-23 06:47:35.941 E/mono    ( 5701):   at Windows.UI.Xaml.NativeApplication..ctor (Windows.UI.Xaml.NativeApplication+AppBuilder appBuilder, System.IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) [0x00008] in C:\a\1\s\src\Uno.UI\UI\Xaml\NativeApplication.cs:36 
12-23 06:47:35.941 E/mono    ( 5701):   at App.Droid.Application..ctor (System.IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) [0x00000] in D:\Dt\Client\Dt.Shell.Droid\MainActivity.cs:24 
12-23 06:47:35.941 E/mono    ( 5701):   at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
12-23 06:47:35.941 E/mono    ( 5701):   at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:936 
12-23 06:47:35.941 E/mono    ( 5701):    --- End of inner exception stack trace ---
12-23 06:47:35.941 E/mono    ( 5701):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-23 06:47:35.941 E/mono    ( 5701):   at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-23 06:47:35.942 E/mono-rt ( 5701): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Cannot locate resource from 'ms-appx:///Dt.Base/Themes/Generic.xaml'
12-23 06:47:35.942 E/mono-rt ( 5701):   at Uno.UI.ResourceResolver.RetrieveDictionaryForSource (System.String source, System.String currentAbsolutePath) [0x0003a] in C:\a\1\s\src\Uno.UI\UI\Xaml\ResourceResolver.cs:366 
12-23 06:47:35.942 E/mono-rt ( 5701):   at Dt.Shell.App.InitializeComponent () [0x0007f] in D:\Dt\Client\Dt.Shell.Droid\obj\Debug\100\g\XamlCodeGenerator\App_a9a445e08e07b50e74be0d8d3c09428f.g.cs:74 
12-23 06:47:35.942 E/mono-rt ( 5701):   at Dt.Shell.App..ctor () [0x00008] in D:\Dt\Client\Common\App.xaml.cs:29 
12-23 06:47:35.942 E/mono-rt ( 5701):   at App.Droid.Application+<>c.<.ctor>b__0_0 () [0x00000] in D:\Dt\Client\Dt.Shell.Droid\MainActivity.cs:24 
12-23 06:47:35.942 E/mono-rt ( 5701):   at Windows.UI.Xaml.NativeApplication..ctor (Windows.UI.Xaml.NativeApplication+AppBuilder appBuilder, System.IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) [0x00008] in C:\a\1\s\src\Uno.UI\UI\Xaml\NativeApplication.cs:36 
12-23 06:47:35.942 E/mono-rt ( 5701):   at App.Droid.Application..ctor (System.IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) [0x00000] in D:\Dt\Client\Dt.Shell.Droid\MainActivity.cs:24 
12-23 06:47:35.942 E/mono-rt ( 5701):   at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
12-23 06:47:35.942 E/mono-rt ( 5701):   at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:936 
12-23 06:47:35.942 E/mono-rt ( 5701):    --- End of inner exception stack trace ---
12-23 06:47:35.942 E/mono-rt ( 5701):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-23 06:47:35.942 E/mono-rt ( 5701):   at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)

Expected behavior

How to reproduce it (as minimally and precisely as possible)

Workaround

Environment

Nuget Package:

Nuget Package Version(s):

Affected platform(s):

IDE:

Relevant plugins:

Anything else we need to know?

Daoting commented 3 years ago

I recommend providing examples of using class libraries. Otherwise a lot of problems won't be found. The netstdref[#3656] still didn't work in ResourceDictionary xaml files (not common xaml files), but I've changed my approach.

davidjohnoliver commented 3 years ago

I'm unable to build the app you link to, I get a lot of errors like the following:

1>        C:\src\repros\dt\Client\Dt.Core\Dt.Core.csproj : error NU1101: Unable to find package Dt.Cells. No packages exist with this id in source(s): [...]
1>    Done building target "ResolvePackageAssets" in project "Dt.Core.csproj" -- FAILED.

Are you able to provide a small standalone repro?

Daoting commented 3 years ago

I created a project to test bugs. ForUno The app is now working. The following two modifications can be bug reproduced after upgrading to 3.4.0: Dtc.props Android