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

Resource Editor not working properly. #343

Open
danyhm opened this issue Jul 9, 2024 · 5 comments
Open

Resource Editor not working properly. #343

danyhm opened this issue Jul 9, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@danyhm
Copy link

danyhm commented Jul 9, 2024

dnSpyEx version

6.5.1

Describe the Bug

Hello,

I'm using the Resource Editor feature and even if I change 1 character in a string resource, while trying to read the resource of the file I get this error at runtime:

Corrupt .resources file. Unable to read resources from this file because of invalid header information. Try regenerating the .resources file.

Stack trace:

"   at System.IO.__Error.EndOfFile()\r\n   at System.IO.BinaryReader.FillBuffer(Int32 numBytes)\r\n   at System.IO.BinaryReader.ReadInt32()\r\n   at System.Resources.ResourceReader._ReadResources()\r\n   at System.Resources.ResourceReader.ReadResources()"

image

How To Reproduce

Edit any resource file and use it in other assemblies.

Expected Behavior

The program should generate the correct header for resource files when saving the modified file.

Actual Behavior

Somehow the header file for resources is not generated correctly

Additional Context

No response

@danyhm danyhm added the bug Something isn't working label Jul 9, 2024
@danyhm
Copy link
Author

danyhm commented Jul 9, 2024

here is the initial stacktrace.

{System.BadImageFormatException: Corrupt .resources file. Unable to read resources from this file because of invalid header information. Try regenerating the .resources file. ---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
   at System.IO.__Error.EndOfFile()
   at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
   at System.IO.BinaryReader.ReadInt32()
   at System.Resources.ResourceReader._ReadResources()
   at System.Resources.ResourceReader.ReadResources()
   at System.Resources.ResourceReader.ReadResources()
   at System.Resources.ResourceReader..ctor(Stream stream)

It does not matter if I add a resource to the file or remove a resource to the file , this exception is always thrown.
the resources are a lot BTW if that has to do something with it.

also trying to extract the resources with ResGen Fails

Read in 101 resources from "AH.resources"
Read in 16423 resources from "LH.resources"
Read in 99 resources from "TH.resources"
ResGen : error RG0000: Error while writing the output file "./AH.resw"
ResGen : error RG0000: Specific exception: "InvalidOperationException"  Message: "Item named '72' of type 'System.IO.UnmanagedMemoryStream' cannot be added to the resource file because it is not serializable."
2 error(s).

@ElektroKill
Copy link
Member

Hello,

Sorry for the late response! Could you provide a minimum reproduce case with the files you used and the changes you made? If you do not wish to give this publically, you can send it to me via email [email protected]

Thanks in advance

@danyhm
Copy link
Author

danyhm commented Jul 31, 2024

Hi,
I sent you the email.

If you edit any of the resource strings the final program won't be able to read the resources and will fail with the errors mentioned above.

@greenozon
Copy link

there was some update recenly in ILSPy about resources support - icsharpcode/ILSpy@f9ae51b

is it related to this topic?

@ElektroKill
Copy link
Member

Hi, even when trying resgen with your original file it fails to execute:

Read in 101 resources from "Genetec.Platform.Resources.AppearanceHook.resources"
Read in 16423 resources from "Genetec.Platform.Resources.LanguageHook.resources"
Read in 99 resources from "Genetec.Platform.Resources.TrademarkHook.resources"
ResGen : error RG0000: Error while writing the output file "sds\Genetec.Platform.Resources.AppearanceHook.resw"
ResGen : error RG0000: Specific exception: "InvalidOperationException"  Message: "Item named '72' of type 'System.IO.UnmanagedMemoryStream' cannot be added to the resource file because it is not serializable."
3 error(s).

A file where i used the Edit Resource option and changed the string produces the exact same error.

This error is not related to the edit and is caused by ResGen not properly supporting data stream resources. ResGen properly parses all resources from the file as seen by the Read in X resources from messages before and after my edit using dnSpy.

This is visible when debugging ResGen itself in dnSpy where we can see all resource files are properly read.
image

I cannot reproduce your issue with ResourceReader crashing using the latest build of dnSpyEx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants