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

Retrieving Stream field throws null reference when GetBlobStream returns null (e.g. when media file is detached) #444

Open
mikemuggli opened this issue Jan 18, 2022 · 0 comments

Comments

@mikemuggli
Copy link

mikemuggli commented Jan 18, 2022

Using Glass Mapper 5.6.160 on Sitecore 9.3.

In a scenario where a field is mapped to a Stream type, for example the Blob field of the media File type (/sitecore/templates/System/Media/Unversioned/File/Media/Blob) if the Blob field is empty/null (e.g. the media asset was detached), Glass Mapper is throwing a null reference exception.

I believe this happens in the GetField method of the SitecoreFieldStreamMapper class. It tries to get the blob stream:

var data = field.GetBlobStream();

In the case of a detached asset, data will be null. But there is no null check before it tries to use data in the conditional:

if (data.CanRead) - https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/DataMappers/SitecoreFieldStreamMapper.cs#:~:text=if%20(-,data.CanRead,-)

I believe the above line is where the null reference exception occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant