C
C#13mo 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
JakenVeina13mo 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
zed13mo 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
jcotton4213mo ago
there's probably some cursed #allow-unsafe-blocks way
zed
zed13mo 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
More Posts
❔ Getting Identity from [Authorize]Hey there, since i'm using [Authorize] i thought i should be able to get UserID from var userId = H❔ Tasked with making a scheduling algorithm at summer internshipI'm an industrial engineering student that knows a bit of coding, but it seems like I've been given ❔ ✅ Search for specific value that is contained inside some variable while debugging VSWhen debugging a large project, I know that one of my many variables will contain a string valled "VIIS Worker (30%) and SQL Server (60%) High CPU usage.Currently hosting a website on iis (.net core 3.1). I have no clue as to why usage for both the iis ❔ Trying to make an app using rustI come from a background of asp net core, where I worked with the framework for over a year and has ❔ Visual Studio Code doesn't highlight a syntax error in C# (with Unity)I have the Unity Debugger and C# plugins, and still nothing comes up. I know it is an error becasue ❔ AutoSize always shrinks my control to 1 px even with contentI have a User Control that has 3 panels in it. One docked to the top, one to fill and one to the bot❔ WPF application resources not found in windowI'm doing a small project but for reason I can't use my WPF application resources in my windows. I Forwarding T to other generic methodI don't know if these are the right terms for this, my bad. But basically I'm making a class that w❔ Output error when user missing .NET runtimeI have an AvaloniaUI project targetting .NET Framework 4.6.2 AND .NET6. It builds two EXEs: one for