KSP-CKAN / CKAN

The Comprehensive Kerbal Archive Network
https://forum.kerbalspaceprogram.com/index.php?/topic/197082-*
Other
1.99k stars 348 forks source link

Common Language Runtime detected an invalid program during XML serialization #3919

Closed PMoffitt05 closed 1 year ago

PMoffitt05 commented 1 year ago

Is there an existing issue for this?

Operating System

Windows 11 22H2

CKAN Version

1.33.2

Game Version

KSP2 0.1.4.1

Did you make any manual changes to your game folder (i.e., not via CKAN)?

Not that I am aware of.

Describe the bug

Deleting the CKAN folder or any of the files does not correct the issue.

Checking security settings, all users should have rights to the CKAN folder and contents.

Using ckan via CMD Terminal (command line version), I can list instances and clear them all.  Then add in my current game instance and set it as default.  But, the GUI or consoleui present the same issues afterwards. (Not an issue of not having a default game instance set.)

Renaming the CKAN folder and starting CKAN results in the same results.

Looking at the CKAN folder there is a registry.lock file when CKAN is running.   Using consoleui, I can get an error that a registry lock file already exists when trying to selet the instance of the game I am playing and to check for other running versions of CKAN.  However, this is the only running version.  Seems to be an issue with CKAN checking for the registry lock file and finding it but not knowing it is its own lock file or not releasing (deleting) the lock when it should.

Steps to reproduce

Lunch CKAN by dubble clicking it.

Relevant log output

CKAN 1.33.2 on Windows 11 22H2 error on startup:  Unhandled exception. 

System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at System.Xml.Serialization.XmlReflectionImporter..ctor(XmlAttributeOverrides attributeOverrides, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
   at CKAN.GUI.GUIConfiguration.SaveConfiguration(GUIConfiguration configuration)
   at CKAN.GUI.GUIConfiguration.LoadOrCreateConfiguration(String path, IGame game)
   at CKAN.GUI.Main.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

installed-KSP2.ckan:

{
    "spec_version": "v1.18",
    "identifier": "installed-KSP2",
    "name": "installed-KSP2",
    "abstract": "A list of modules installed on the KSP2 KSP instance",
    "author": [
        "Pat"
    ],
    "version": "2023.10.14.06.18.19",
    "ksp_version_min": "0.1.4",
    "ksp_version_max": "0.1.4",
    "license": [
        "unknown"
    ],
    "depends": [],
    "release_date": "2023-10-14T11:18:19.2441375-07:00",
    "kind": "metapackage"
}

registry.json:

{
"registry_version": 3,
"sorted_repositories": {
"default": {
"name": "default",
"uri": "https://github.com/KSP-CKAN/KSP2-CKAN-meta/archive/main.tar.gz",
"last_server_etag": null,
"priority": 0
}
},
"available_modules": {},
"installed_dlls": {},
"installed_modules": {},
"installed_files": {},
"download_counts": {}
}
HebaruSan commented 1 year ago

It's actually throwing that while trying to save <Game Root>/CKAN/GUIConfig.xml. Does that file exist, and if so, can you please share its contents?

(The consoleui thing sounds like a secondary effect of GUI crashing in the first place while holding the lock.)

HebaruSan commented 1 year ago

Browsing a web search for this error, the most plausible cause sounds like trying to use an assembly for an architecture that isn't supported on the system (think a 64-bit DLL on a 32-bit system). Since this is happening in a System.* assembly, it'll be a DLL outside of CKAN, so the best bet is that there's something screwy with your .NET Framework install. Try uninstalling and reinstalling .NET Framework.

PMoffitt05 commented 1 year ago

I will check .Net. Probably caused by some MS update after 7/2023. I haven't tried to run CKAN in a while.

PMoffitt05 commented 1 year ago

More of the error (why didn't I have all this before?). Does it mater that I have Visual Studio installed coding in C# with .net?

Things I have tried since the first message:

  1. Install latest .Net Framework from MS. 4.8.0919510
  2. SFC /scannow (repaired some Bluetooth drivers)
  3. DISM /online /checkhealth (may be missing some of that command line) and /scanhealth - nothing found.
  4. Ran .net framework repair tool (not convinced it did much)
  5. Restarted

Still getting the following:

************** Exception Text **************
System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at System.Xml.Serialization.XmlReflectionImporter..ctor(XmlAttributeOverrides attributeOverrides, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
   at CKAN.GUI.GUIConfiguration.SaveConfiguration(GUIConfiguration configuration)
   at CKAN.GUI.GUIConfiguration.LoadOrCreateConfiguration(String path, IGame game)
   at CKAN.GUI.Main.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
PMoffitt05 commented 1 year ago

Updated Visual Studio. Still the same issue. Consoleui works as long as I don't try to change game instance. I managed to update my installed mods using consoleui. Granted, I had removed the KSP1 instances and set the KSP2 instance as default using command lines.

I still think MS updated something in Win 11 and broke CKAN and how it deals with that registry.lock file.

Tempting to download the code, compile it and run it in the debugger....

PMoffitt05 commented 1 year ago

It's actually throwing that while trying to save <Game Root>/CKAN/GUIConfig.xml. Does that file exist, and if so, can you please share its contents?

(The consoleui thing sounds like a secondary effect of GUI crashing in the first place while holding the lock.)

If I rename the CKAN folder, no that file does not exist after attempting to run CKAN in GUI mode.

Old CKAN Folder (which I am currently using again): image

Contents of GUIConfig.xml (from old CKAN folder):

<?xml version="1.0" encoding="utf-8"?>
<Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <CommandLineArguments>KSP2_x64.exe -single-instance</CommandLineArguments>
  <AutoCloseWaitDialog>false</AutoCloseWaitDialog>
  <URLHandlerNoNag>false</URLHandlerNoNag>
  <CheckForUpdatesOnLaunch>true</CheckForUpdatesOnLaunch>
  <CheckForUpdatesOnLaunchNoNag>true</CheckForUpdatesOnLaunchNoNag>
  <EnableTrayIcon>false</EnableTrayIcon>
  <MinimizeToTray>false</MinimizeToTray>
  <HideEpochs>true</HideEpochs>
  <HideV>false</HideV>
  <RefreshOnStartup>true</RefreshOnStartup>
  <RefreshOnStartupNoNag>true</RefreshOnStartupNoNag>
  <RefreshPaused>false</RefreshPaused>
  <AutoSortByUpdate>true</AutoSortByUpdate>
  <ActiveFilter>6</ActiveFilter>
  <DefaultSearches>
    <Search />
  </DefaultSearches>
  <SortColumns>
    <string>ReleaseDate</string>
  </SortColumns>
  <MultiSortDescending>
    <boolean>true</boolean>
  </MultiSortDescending>
  <HiddenColumnNames />
  <IsWindowMaximised>true</IsWindowMaximised>
  <WindowSize>
    <Width>1358</Width>
    <Height>743</Height>
  </WindowSize>
  <PanelPosition>1024</PanelPosition>
  <WindowLoc>
    <X>159</X>
    <Y>35</Y>
  </WindowLoc>
</Configuration>
PMoffitt05 commented 1 year ago

Finally found a way to actual get Win 11 to reinstall .net Framework 4.8.1. However, that didn't fix anything. Still getting an error thrown from mscorlib.dll, ver 4.8.9181.0 dated 7/19/2023.

1. Delete the following folders from c:\windows\Microsoft.Net: Framework\v4.0.30319 and Framework64\v4.0.30319
2. Start a cmd prompt as an administrator
3. Run SFC /SCANNOW
4. Once it finishes, restart the computer and it will reinstall the missing files

I also uninstalled KSP2 and reinstalled it (via Steam). That didn't change anything other than I had to go install my favorite mods using the consoleui (seems to work without issue). Turned out, none of my mods were working before reinstalling KSP2. (Yep, KSP2 is still prerelease, expect to have to fix it often.)

HebaruSan commented 1 year ago

Apparently there's a repair tool, might be worth a try:

https://www.microsoft.com/en-us/download/details.aspx?id=30135

HebaruSan commented 1 year ago

Here's the code (specifically line 202) that calls the System.Xml code that throws the exception, in case that helps you figure out what's wrong on your PC:

https://github.com/KSP-CKAN/CKAN/blob/46c4dec0b948b962634e04599d8ab1206291ab40/GUI/Model/GUIConfiguration.cs#L200-L210

PMoffitt05 commented 1 year ago

Yeah, don't do the things I have done. .Net is broken and just got Event Viewer to run again. Visual Studio 2022 will not run. Yep, I broke my machine....

HebaruSan commented 1 year ago

Oh no! I hope you're able to recover it 🤞. Please let us know if you manage to figure out the problem with System.Xml once you do...

PMoffitt05 commented 1 year ago

Well, got Event Viewer working again. Fixed Visual Studio by restoring the backup I had of my .net framework folders. got the source from git for CKAN and thinking I will recompile for .Net 4.8.1 Framework (I actually do not have .Net 4.5 and 4.8 comes with Win 11).

Still can't compile anything Visual Studio is borked....

PMoffitt05 commented 1 year ago

Ok, this is simiple to fix..

  1. Right click on Ckan.exe
  2. Select properties.
  3. Click the Compatibility tab
  4. Turn on the checkbox for Run this program in compatibility mode for
  5. Select Windows 8
  6. Click OK

Now it appears to run without issue. Much beating my head against the wall over something simple to fix.

HebaruSan commented 1 year ago

Glad you found a workaround! Please let us know if you ever discover what was actually wrong that made it necessary. As far as I know, no one else has ever needed to use that option before.

PMoffitt05 commented 1 year ago

I was wrong, only seemed like it was going to work. Crashed soon after I selected my instance of KSP2 and now doesn't work. It still fails trying to write the GUIConfiguration even if I run it as administrator.

BTW, it is easy to change that app to not use the new terminal which should fix the issue about Terminal being left open (but your workaround of minimize works too).

HebaruSan commented 1 year ago

Hey @PMoffitt05, sorry you've been having issues with this, but I don't think it's something we can solve for you. There's something weird on your system that's making a System assembly throw internally when CKAN calls it in the most ordinary, boilerplate way. If you manage to identify something that CKAN is actually doing wrong here, we'll be happy to fix it, but for now I'm closing this.