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] SCM2020 launch failed with error: Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' #9311

Open
Junjun-zhao opened this issue Jun 27, 2024 · 5 comments
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.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.

Reproduction Steps

App Repro steps:
1.Set EnableUnsafeBinaryFormatterSerialization switch to True and set runtime version to .NET 9.0.100-preview.6.24325.8 in SCM2020 - Server.runtimeconfig.json.

"framework": {
      "name": "Microsoft.AspNetCore.App",
      "version": "9.0.0-preview.6.24324.2"
    },
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }

2.Restore database refer to devdiv bug.
3.Launching SCM2020\Server\SCM2020-Server.exe
4.Launching SCM2020\Client\SCM2020-Client.exe.
5.Click “Close” button.
6.Click “Cadastro” button, then select “Grupo” item.
7.Input “Appcompat” in textbox, then click “Salvar Grupo” button.
8.Click “Ok” bottom.
9.Click “Cadastro” button, then select “Setor” item.

Expected behavior

Launch successfully.

Actual behavior

App is crashed
image

Exception:

Description: The process was terminated due to an unhandled exception. 
Exception Info: 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' 

   at MS.Internal.AppModel.DataStreams.get_Formatter 

   at MS.Internal.AppModel.DataStreams.SaveSubStreams(UIElement element) 

   at MS.Internal.AppModel.DataStreams.SaveState(Object node) 

   at MS.Internal.AppModel.DataStreams.WalkLogicalTree(Object node, NodeOperation operation) 

   at MS.Internal.AppModel.DataStreams.WalkLogicalTree(Object node, NodeOperation operation) 

   at MS.Internal.AppModel.DataStreams.WalkLogicalTree(Object node, NodeOperation operation) 

   at MS.Internal.AppModel.DataStreams.WalkLogicalTree(Object node, NodeOperation operation) 

   at MS.Internal.AppModel.DataStreams.WalkLogicalTree(Object node, NodeOperation operation) 

   at System.Windows.Navigation.NavigationService.MakeJournalEntry(JournalReason journalReason) 

   at System.Windows.Navigation.NavigationService.UpdateJournal(NavigationMode navigationMode, JournalReason journalReason, JournalEntry destinationJournalEntry) 

   at System.Windows.Navigation.NavigationService.OnBeforeSwitchContent(Object newBP, NavigateInfo navInfo, Uri newUri) 

   at System.Windows.Navigation.NavigationService.MS.Internal.AppModel.IContentContainer.OnContentReady(ContentType contentType, Object bp, Uri bpu, Object navState) 

   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.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 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 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 SCM2020___Client.App.Main() 

Regression?

Yes

Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24314.10: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24321.3: Fail
3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24325.8: 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.1": {
      "SCM2020 - Client/1.0.0": {
        "dependencies": {
          ......
          "System.Runtime.Serialization.Formatters": "9.0.0-preview.6.24327.7"
        },
        "runtime": {
          "SCM2020 - Client.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: SCM2020(WPF, .NET Core 3.1)
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-preview.6.24325.8
App or Source Checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2110609

Other information

@dotnet-actwx-bot @dotnet/compat

@miloush miloush marked this as a duplicate and then as not a duplicate of #9309 Jun 27, 2024
@miloush
Copy link
Contributor

miloush commented Jun 27, 2024

Sorry GitHub is trying to be smart. This one should go to WPF actually because it's the JournalEntry using the binary formatter.

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

This is expected behavior that BinaryFormatter has been removed from .NET 9 Preview 6 due to its security risk. It is recommended that user should start looking at alternative serialization formats. If the security risk is acceptable and would like to use a workaround temporally with nuget package, please refer to the details in above workaround area. Closing this issue.

@miloush
Copy link
Contributor

miloush commented Jul 15, 2024

It is not expected that internal WPF structures would use a formatter that has been removed. This should be fixed.

@Junjun-zhao
Copy link
Member Author

@miloush Thanks for the information, reopen this issue to be fixed in WPF structure.

@Junjun-zhao Junjun-zhao reopened this Jul 16, 2024
@Alexgoon
Copy link

Alexgoon commented Jul 17, 2024

JFYI: at DevExpress, we encountered this issue when we tried migrating to .NET 9. It might affect many of our customers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

4 participants