Share via

Impact of Changing Framework Order in runtime.config.json on Application Stability

Subhabrata Sahoo 0 Reputation points
28 Mar 2025, 09:11

Description:

I am working on a .NET 8 WPF application that undergoes obfuscation using SmartAssembly. During the build, runtime.config.json is generated automatically, but SmartAssembly picks WindowsBase.dll from Microsoft.NETCore.App instead of Microsoft.WindowsDesktop.App, causing obfuscation errors. i.e. During obfuscation with SmartAssembly, WindowsBase.dll was being resolved from Microsoft.NETCore.App instead of Microsoft.WindowsDesktop.App, leading to an invalid symbol error.

To resolve this, I modified the framework order in runtime.config.json to ensure Microsoft.WindowsDesktop.App is listed before Microsoft.NETCore.App. This change resolved the obfuscation issue, but I want to confirm:

  1. Is it safe to modify runtime.config.json manually post-build via a script?
  2. Can this impact runtime behavior on client machines, especially in framework-dependent deployments?
  3. Is there an official way to enforce framework resolution order during build instead of modifying runtime.config.json manually?

User's image

Any official guidance on this would be highly appreciated.

Environment:

  • .NET 8.0

WPF Application

SmartAssembly Obfuscation

Windows 10/11 Deployment

Thanks!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,848 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hongrui Yu-MSFT 5,170 Reputation points Microsoft External Staff
    31 Mar 2025, 07:56

    Hi, @Subhabrata Sahoo. Welcome to Microsoft Q&A. 

    Is it safe to manually modify [appname].Runtime.config.json after building?

    If you modify the configuration in [appname].Runtime.config.json, the runtime will read this file when the application is loaded. If the format or content of the file does not meet the requirements, the runtime may fail to load or throw an exception. In addition, when your application depends on a specific [appname].Runtime.config.json configuration, these settings will affect the runtime deployed to the client computer. If the runtime version of the client computer is incompatible with the configuration file, the application may not start.

    However, if you only adjust the order of framework loading, it generally does not affect the operation of the application, as long as the versions and compatibility of all framework dependencies are correct.

    However, projects need to be updated frequently over time, and manual modifications every time are not conducive to maintenance.

    Set [appname].Runtime.config.json during the build.

    Add a .json file with the contents of your target's [appname].Runtime.config.json. For example: add runtimeconfig.json and add the following code.

    {
        "runtimeOptions": {
          "frameworks": [
            {
              "name": "Microsoft.WindowsDesktop.App",
              "version": "8.0.0"
            },
            {
              "name": "Microsoft.NETCore.App",
              "version": "8.0.0"
            }
          ]
        },
        "configProperties": {
          "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true,
          "CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false
        }
    }
    

    Add <Target> code in <Project> of .csproj to replace the contents of [appname].Runtime.config.json with the contents of .json before build.

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <UseWPF>true</UseWPF>
      </PropertyGroup>
    
    	<Target Name="CopyRuntimeConfig" BeforeTargets="Build">
    		<Copy SourceFiles="runtimeconfig.json" DestinationFiles="$(OutDir)[appname].runtimeconfig.json" />
    	</Target>
    
    </Project>
    

    Replace [appname] with the name of your project.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.