<packages>
<package id="cef.redist.x64" version="3.3239.1723" targetFramework="net452" />
<package id="cef.redist.x86" version="3.3239.1723" targetFramework="net452" />
<package id="CefSharp.Common" version="63.0.2" targetFramework="net452" />
<package id="CefSharp.OffScreen" version="63.0.2" targetFramework="net452" />
</packages>
What architecture x86 or x64?
Both x64 and x86
On what operating system?
Win10
Are you using WinForms, WPF or OffScreen?
OffScreen
What steps will reproduce the problem?
_In general:_
Changing the size of a browser and taking then a screenshot from this after the website was loaded again
_Example:_
Check out this fork
What is the expected output? What do you see instead?
_Expected:_
The size of the bitmap gets updated when I set the size of the browser.
_Current:_
The size of the bitmap differs from the size of the browser and therefore causes an AccessViolationException
Please provide any additional information below.
Exception thrown: 'System.AccessViolationException' in System.Drawing.dll
CefSharp.OffScreen.dll!CefSharp.OffScreen.ChromiumWebBrowser.ScreenshotOrNull(CefSharp.OffScreen.PopupBlending blend) Line 510
CefSharp.OffScreen.dll!CefSharp.OffScreen.ChromiumWebBrowser.ScreenshotAsync.AnonymousMethod__1(object sender, CefSharp.OnPaintEventArgs e) Line 544
CefSharp.OffScreen.dll!CefSharp.OffScreen.ChromiumWebBrowser.CefSharp.Internals.IRenderWebBrowser.OnPaint(CefSharp.Internals.BitmapInfo bitmapInfo) Line 775 CefSharp.Core.dll!CefSharp::Internals::RenderClientAdapter::OnPaint(scoped_refptr<CefBrowser>* browser, cef_paint_element_type_t type, std::vector<CefRect,std::allocator<CefRect> >& dirtyRects, void* buffer, int width, int height) Line 18
CEF Sample Application from http://opensource.spotify.com/cefbuilds/index.html?As part of #2237 the way rendering for the OffScreen and WPF projects is done has been rewritten, I've run a slightly modified version of your code (OnPaint event is now Paint, there is now a virtual OnPaint method which is more consistent with the other projects). I changed the counter to 100 and it ran through without exception.
The main difference is that the buffer is stored as a byte[] now, rather than a Bitmap, and a Bitmap is only created upon request, this should improve performance and actually greatly simplifies the code.
Closing this as I'm not unable to reproduce with master, you can try one of the CI builds listed at https://github.com/cefsharp/CefSharp#releases-1 to try it out ASAP.
Will likely be some more changes as part of https://github.com/cefsharp/CefSharp/issues/2237 so subscribe to that issue to be notified of updates.
Sorry to ask, but I'm having the same problem (see closed duplicate above). I'm not sure what you did to fix the problem? Do we have to wait for version 65?
OK I tested with "65.0.0-pre01" and I confirm the exception is gone, without requiring any change to my code.
Most helpful comment
As part of #2237 the way rendering for the
OffScreenandWPFprojects is done has been rewritten, I've run a slightly modified version of your code (OnPaintevent is nowPaint, there is now a virtualOnPaintmethod which is more consistent with the other projects). I changed the counter to100and it ran through without exception.The main difference is that the buffer is stored as a
byte[]now, rather than aBitmap, and aBitmapis only created upon request, this should improve performance and actually greatly simplifies the code.