C
C#2y ago
zed

✅ Modify embedded resources at runtime

Is there a way to modify an assembly's own embedded resources? I'm not looking into physically changing the file, but (ideally) just virtually change what it produces, when an embedded resource is requested. The context here being that I'm interfacing with a third party component which reads data only from an embedded resource, but I want to feed it data that is generated at runtime - it has no other way (that I know of) to interface with my project, other than through reading of embedded resources. While the "third" party component is technically developed in-house, it's from a closed off development team, and they said they have no resources to devote to changing this behavior. So I'm not sure what else I could do. Unfortunately, this is .NET Framework 4.8, so I don't have some newer features available to me. Any ideas?
4 Replies
JakenVeina
JakenVeina2y ago
you probably want to extract the embedded resource as a stream, and then copy it into a MemoryStream or a temporary file. From there you can modify and use it however you like
zed
zedOP2y ago
Thanks, but that wouldn't work in my case, because the third party component calls assembly.GetManifestResourceNames directly and uses that, so I would need to adjust it so that this function call includes the runtime data That said, I found a stupid workaround, so this is kinda closed for me, at least to a point that I can live with it @.@
jcotton42
jcotton422y ago
there's probably some cursed #allow-unsafe-blocks way
zed
zedOP2y ago
For future reference, in case anyone has this problem, I created a new dummy assembly with no code, and just use it as a target to write runtime embedded resources into - coupled with build order settings and one custom build step to assure the file exists and is copied to the output properly, this works for my needs... Possibly, though if I went that route, I'd prefer IL fiddling Either way, I don't think there's a way to do that within the confines of the framework itself Thanks for helping though :)
Want results from more Discord servers?
Add your server