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

[dotnet-sdk-9.0.100-preview.6.24325.8] Transmogrify get System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.' #9309

Closed
Junjun-zhao opened this issue Jun 27, 2024 · 7 comments
Assignees
Labels
Investigate Requires further investigation by the WPF team.

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Jun 27, 2024

Description

When run the 3rd party application with the latest .NET 9 build "dotnet-sdk-9.0.100-preview.6.24325.8", it failed to launch with error:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.'
Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Reproduction Steps

1.Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.6.24325.8 and Enable BinaryFormatter.

"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.6.24321.8"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "9.0.0-preview.6.24322.3"
      }
    ],
"configProperties": {
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }
  1. Launching Transmogrify.exe.

Expected behavior

Launch successfully.

Actual behavior

Launch failed.

Exception details: (Exception comes from Event Viewer)

System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'Transmogrify.Pages.ProjectOverviewControls.OverviewRibbon' that matches the specified binding constraints threw an exception.' Line number '12' and line position '10'.
 ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetDefinedTypes()
   at System.Reflection.RuntimeModule.GetTypes()
   at Transmogrify.Services.LibraryService.<>c.<GetAvailableEndpointTypes>b__6_1(Assembly a) in C:\Users\v-yibiaozhu\Desktop\New folder (2)\Transmogrify\Transmogrify\Services\LibraryService.cs:line 33
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.IEnumerableWhereIterator`1.MoveNext()
   at Transmogrify.Pages.ProjectOverviewControls.OverviewRibbon.AddEndPointTypesToMenu() in C:\Users\v-yibiaozhu\Desktop\New folder (2)\Transmogrify\Transmogrify\Pages\ProjectOverviewControls\OverviewRibbon.xaml.cs:line 38
   at Transmogrify.Pages.ProjectOverviewControls.OverviewRibbon..ctor() in C:\Users\v-yibiaozhu\Desktop\New folder (2)\Transmogrify\Transmogrify\Pages\ProjectOverviewControls\OverviewRibbon.xaml.cs:line 29
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime.Serialization.Formatters, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverterCore(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter, Boolean isUnsafe)
   at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStreamCore(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter, Boolean isUnsafe)
   at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
   at System.Windows.Navigation.NavigationService.DoNavigate(Uri source, NavigationMode f, Object navState)
   at System.Windows.Navigation.NavigateQueueItem.Dispatch(Object obj)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at Transmogrify.App.Main()

Regression?

Yes
Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24317.13: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24325.8: Fail
3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24321.3: Fail

Known Workarounds

Yes.

Try with the following steps:

  1. Turn on the AppContext Switch like <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  2. Download and Extract System.Runtime.Serialization.Formatters nuget package.
  3. Copy System.Runtime.Serialization.Formatters.dll from nuget package folder to application publish folder.
  4. Update .deps.json file to registry System.Runtime.Serialization.Formatters.dll for application dependencies by adding following content in deps.json file:
{
......
  "targets": {
    ".NETCoreApp,Version=v3.0": {
      "Transmogrify/1.0.0": {
        "dependencies": {
          "System.Runtime.Serialization.Formatters": "9.0.0-preview.6.24327.7"
        },
        "runtime": {
          "Transmogrify.dll": {}
        }
      },
      "System.Runtime.Serialization.Formatters/9.0.0-preview.6.24327.7": {
        "runtime": {
          "lib/net8.0/System.Runtime.Serialization.Formatters.dll": {
            "assemblyVersion": "9.0.0.0",
            "fileVersion": "9.0.24.32707"
          }
        }
      }
 ......
  "libraries": {
   ......
    "System.Runtime.Serialization.Formatters/9.0.0-preview.6.24327.7": {
      "type": "package",
      "serviceable": true,
      "sha512": "sha512-5S1E7KF/RzcZoRQ27BW3f6HX6zihRVz2utacaUWw4ilos2L4435PPn4rn8c+6Ltp4isTukBnw9K+FZCQHwCVPA==",
      "path": "system.runtime.serialization.formatters/9.0.0-preview.6.24327.7",
      "hashPath": "system.runtime.serialization.formatters.9.0.0-preview.6.24327.7.nupkg.sha512"
    }
  }
......

Impact

No response

Configuration

Application Name: Transmogrify (WPF)
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-preview.6.24325.8
App & Source Checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2110581
Github Link: https://github.com/FTWinston/Transmogrify

Dotnet Info:

.NET SDK:
 Version:           9.0.100-preview.6.24325.8
 Commit:            89054b0c37
 Workload version:  9.0.100-manifests.29b7987d
 MSBuild version:   17.11.0-preview-24318-05+4a45d5633

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.6.24325.8\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      9.0.0-preview.6.24321.8
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  9.0.100-preview.6.24325.8 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.6.24324.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24321.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.6.24322.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

Other information

No response

@miloush
Copy link
Contributor

miloush commented Jun 27, 2024

The support for .NET Core 3.0 ended in 2020 and you are trying to run it on .NET 9. Upgrade to a supported version, which would allow you to use the formatters package.

@miloush
Copy link
Contributor

miloush commented Jun 27, 2024

This one is a bit weird because the application is inspecting all types in all assemblies. Can't tell who is at fault here without debugging. Either way, my comment stands, I don't understand why we are trying to run .NET 3 apps on .NET 9 runtime.

@miloush
Copy link
Contributor

miloush commented Jun 27, 2024

The type at which the loading fails is private System.Windows.DataObject.OleConverter.TypeRestrictingSerializationBinder in PresentationCore.dll.

On WPF side this is probably being taken care of by #8532. However, I consider it a bug in the application (Transmogrify) that it tries to load all types in all assemblies without any attempt at failure recovery.

@himgoyalmicro himgoyalmicro added the Investigate Requires further investigation by the WPF team. label Jun 28, 2024
@Junjun-zhao
Copy link
Member Author

Junjun-zhao commented Jul 15, 2024

Update for the workaround: It works well with the public Nuget package for the application. Leave this issue open for dev team to investigate if this is an issue in Application side on WPF side.

@Junjun-zhao
Copy link
Member Author

@harshit7962 Any update for this issue? Is this a bug in Application side or WPF side?

@ericstj
Copy link
Member

ericstj commented Jul 30, 2024

I think this should be fixed with my PR. That will make it so there is no longer a load exception here. @Junjun-zhao could you give a try with the latest RC1 build of WPF that has that fix (just merged).

@ericstj ericstj closed this as completed Jul 30, 2024
@Junjun-zhao
Copy link
Member Author

Hi @ericstj, we verified this issue on the latest build dotnet-sdk-9.0.100-preview.7.24402.8, it has been fixed. Thanks.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

5 participants