I'm struggling to figure out how to load an image from an embedded resource using a custom scheme handler and cefsharp. I am currently using it to load html, css and js files with no issue however when attempting to load an image i always get the broken image indicator. (Dev tools also fails to show a response) I found that the default example in cefsharp.example for ResourceHandler does not properly handle anything over 32KB, so i made a small change so that it wouldn't clip files over 32KB, but either way i still get broken images for any image i attempt to serve as an embedded resource.
Below is the ProcessRequest method required by IResourceHandler.
public bool ProcessRequest(IRequest request, ICallback callback)
{
// The 'host' portion is entirely ignored by this scheme handler.
//Replace internal with our assembly namespacing:
var url = request.Url.Replace("internal://", "MyAssembly.Html.").TrimEnd('/');
fileName = url.Replace('/', '.');
byte[] bytes = null;
var assembly = Assembly.GetExecutingAssembly();
using (Stream embeddedFileStream = assembly.GetManifestResourceStream(fileName))
{
if (embeddedFileStream != null)
{
using (StreamReader reader = new StreamReader(embeddedFileStream))
{
bytes = Encoding.UTF8.GetBytes(reader.ReadToEnd());
}
}
}
if (bytes == null)
{
callback.Dispose();
}
else
{
Task.Run(() =>
{
using (callback)
{
stream = new MemoryStream(bytes);
var fileExtension = Path.GetExtension(fileName);
mimeType = ResourceHandler.GetMimeType(fileExtension);
callback.Continue();
}
});
return true;
}
return false;
}
As mentioned, this works for html,js,css files but not any type of image. I'm lost at this point as to whats missing. Any help would be greatly appreciated.