question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.ArgumentException: ColorBlend object that was set is not valid for svg with linear gradient

See original GitHub issue

Description

I am getting the following exception when calling SvgDocument.Draw on a specific svg:

System.ArgumentException: ColorBlend object that was set is not valid.Position's last element must be equal to 1.0. ColorBlend objects must be constructed with the same number of positions and color values. Positions must be between 0.0 and 1.0, 1.0 indicating the last element in the array.
   at System.Drawing.Drawing2D.LinearGradientBrush.set_InterpolationColors(ColorBlend value)
   at Svg.SvgLinearGradientServer.GetBrush(SvgVisualElement renderingElement, ISvgRenderer renderer, Single opacity, Boolean forStroke)
   at Svg.SvgDeferredPaintServer.GetBrush(SvgVisualElement styleOwner, ISvgRenderer renderer, Single opacity, Boolean forStroke)
   at Svg.SvgVisualElement.RenderFill(ISvgRenderer renderer)
   at Svg.SvgVisualElement.RenderFillAndStroke(ISvgRenderer renderer)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Action`1 renderMethod)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Boolean renderFilter)
   at Svg.SvgVisualElement.Render(ISvgRenderer renderer)
   at Svg.SvgElement.RenderChildren(ISvgRenderer renderer)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Action`1 renderMethod)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Boolean renderFilter)
   at Svg.SvgVisualElement.Render(ISvgRenderer renderer)
   at Svg.SvgElement.RenderChildren(ISvgRenderer renderer)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Action`1 renderMethod)
   at Svg.SvgVisualElement.RenderInternal(ISvgRenderer renderer, Boolean renderFilter)
   at Svg.SvgVisualElement.Render(ISvgRenderer renderer)
   at Svg.SvgElement.RenderChildren(ISvgRenderer renderer)
   at Svg.SvgElement.Render(ISvgRenderer renderer)
   at Svg.SvgFragment.Render(ISvgRenderer renderer)
   at Svg.SvgDocument.Draw(ISvgRenderer renderer, ISvgBoundable boundable)
   at Svg.SvgDocument.Draw(Int32 rasterWidth, Int32 rasterHeight)

Example data

Here is the svg in question:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 439.37 328.82">
	<defs>
		<linearGradient id="linear-gradient" x1="65.2" y1="167.51" x2="412.98" y2="167.51" gradientUnits="userSpaceOnUse">
			<stop offset="0" stop-color="#fff" stop-opacity="0"/>
			<stop offset="1" stop-color="#059ad6"/>
		</linearGradient>
		<linearGradient id="linear-gradient-2" x1="177.97" y1="196.85" x2="325.45" y2="196.85" gradientUnits="userSpaceOnUse">
			<stop offset="0.54" stop-color="#fff" stop-opacity="0"/>
			<stop offset="0.58" stop-color="#fef7e2" stop-opacity="0.14"/>
			<stop offset="0.64" stop-color="#fce9b3" stop-opacity="0.36"/>
			<stop offset="0.7" stop-color="#fbde8a" stop-opacity="0.56"/>
			<stop offset="0.77" stop-color="#fad468" stop-opacity="0.72"/>
			<stop offset="0.83" stop-color="#f9cd4f" stop-opacity="0.84"/>
			<stop offset="0.89" stop-color="#f8c73c" stop-opacity="0.93"/>
			<stop offset="0.95" stop-color="#f8c431" stop-opacity="0.98"/>
			<stop offset="1" stop-color="#f8c32d"/>
		</linearGradient>
		<linearGradient id="linear-gradient-3" x1="22.22" y1="237.44" x2="122.2" y2="237.44" xlink:href="#linear-gradient"/>
		<linearGradient id="linear-gradient-4" x1="44.7" y1="247.9" x2="107.79" y2="247.9" xlink:href="#linear-gradient-2"/>
	</defs>
	<title>Reaction mode</title>
	<g style="isolation:isolate">
		<g id="Layer_1" data-name="Layer 1">
			<path d="M271.48,311.34v-22.2H206.7v22.2a11.91,11.91,0,0,1-.27,1.71,14.64,14.64,0,0,1-1.36,3.77,10.19,10.19,0,0,1-3.28,3.76,10.46,10.46,0,0,1-6,1.71h86.7a10.46,10.46,0,0,1-6.05-1.71,10.19,10.19,0,0,1-3.28-3.76,14.64,14.64,0,0,1-1.36-3.77A11.91,11.91,0,0,1,271.48,311.34Z" style="fill:#9dadb7"/>
			<path d="M295.79,322.3H182.39a5,5,0,0,0-2,.43,5.36,5.36,0,0,0-1.68,1.19,5.59,5.59,0,0,0-1.13,1.76,5.77,5.77,0,0,0-.42,2.16h124a5.77,5.77,0,0,0-.42-2.16,5.59,5.59,0,0,0-1.13-1.76,5.36,5.36,0,0,0-1.68-1.19A5,5,0,0,0,295.79,322.3Z" style="fill:#eff2f3"/>
			<polygon points="206.72 289.14 222.9 289.14 239.09 289.14 255.28 289.14 271.46 289.14 271.46 293.77 271.46 298.39 271.46 303.02 271.46 307.64 255.28 307.64 239.09 307.64 222.9 307.64 206.72 307.64 206.72 303.02 206.72 298.39 206.72 293.77 206.72 289.14" style="fill:#9dadb7;mix-blend-mode:multiply"/>
			<path d="M419,289.14H59.2a5,5,0,0,1-2-.4,5.27,5.27,0,0,1-1.63-1.12,5.28,5.28,0,0,1-1.49-3.69V63.12a5.28,5.28,0,0,1,1.49-3.69,5.07,5.07,0,0,1,1.63-1.11,4.87,4.87,0,0,1,2-.41H419a4.87,4.87,0,0,1,2,.41,5.07,5.07,0,0,1,1.63,1.11,5.28,5.28,0,0,1,1.49,3.69V283.93a5.19,5.19,0,0,1-3.12,4.81A5,5,0,0,1,419,289.14Z" style="fill:#023852"/>
			<polygon points="65.2 266.02 152.15 266.02 239.09 266.02 326.04 266.02 412.98 266.02 412.98 216.77 412.98 167.51 412.98 118.26 412.98 69.01 326.04 69.01 239.09 69.01 152.15 69.01 65.2 69.01 65.2 118.26 65.2 167.51 65.2 216.77 65.2 266.02" style="fill:#0099da"/>
			<polyline points="65.2 81.95 65.2 78.72 65.2 75.48 65.2 72.24 65.2 69.01 152.15 69.01 239.09 69.01 326.04 69.01 412.98 69.01 412.98 72.24 412.98 75.48 412.98 78.72 412.98 81.95 326.04 81.95 239.09 81.95 152.15 81.95" style="fill:#023852"/>
			<path d="M245.1,277.58a6.07,6.07,0,0,0-.47-2.34,5.91,5.91,0,0,0-1.29-1.91,6.13,6.13,0,0,0-1.91-1.29,6.06,6.06,0,0,0-4.68,0,6.13,6.13,0,0,0-1.91,1.29,5.91,5.91,0,0,0-1.29,1.91,6.06,6.06,0,0,0,0,4.68,6.06,6.06,0,0,0,3.2,3.2,6.06,6.06,0,0,0,4.68,0,6.06,6.06,0,0,0,3.2-3.2A6.07,6.07,0,0,0,245.1,277.58Z" style="fill:#023852"/>
			<path d="M65.2,69l13,12.45,13,12.45,13,12.46,13,12.44q19.19,18.42,38.4,36.82l38.41,36.81,38.43,36.79L270.75,266H413V69H65.2Z" style="fill:url(#linear-gradient)"/>
			<polygon points="89.7 104.75 89.7 103.23 89.7 101.71 83.97 101.71 78.25 101.71 78.25 175.69 78.25 249.68 83.97 249.68 89.7 249.68 89.7 248.16 89.7 246.64 85.49 246.64 81.28 246.64 81.28 175.69 81.28 104.75 85.49 104.75 89.7 104.75" style="fill:#f3f5f6"/>
			<polygon points="388.65 246.64 388.65 248.16 388.65 249.68 394.38 249.68 400.1 249.68 400.1 175.69 400.1 101.71 394.38 101.71 388.65 101.71 388.65 103.23 388.65 104.75 392.86 104.75 397.07 104.75 397.07 175.69 397.07 246.64 392.86 246.64 388.65 246.64" style="fill:#f3f5f6"/>
			<polygon points="251.69 165.25 243.26 165.25 234.83 165.25 234.83 156.82 234.83 148.39 233.31 148.39 231.8 148.39 231.8 156.82 231.8 165.25 223.37 165.25 214.93 165.25 214.93 166.77 214.93 168.29 223.37 168.29 231.8 168.29 231.8 176.72 231.8 185.15 233.31 185.15 234.83 185.15 234.83 176.72 234.83 168.29 243.26 168.29 251.69 168.29 251.69 166.77 251.69 165.25" style="fill:#f3f5f6"/>
			<path d="M120.38,116h3.78a8.38,8.38,0,0,1,3.88.69,2.84,2.84,0,0,1,1.47,2.73,3,3,0,0,1-.73,2.07,3.61,3.61,0,0,1-2,1v0a2,2,0,0,1,1,.59,4.28,4.28,0,0,1,.64,1.14l1,2.39,1,2.38h-2.9l-.73-1.85-.73-1.85a3.16,3.16,0,0,0-.79-1.37,2.51,2.51,0,0,0-1.6-.35H123V129h-2.64V116ZM123,121.6h.77a4.67,4.67,0,0,0,2.28-.42,1.51,1.51,0,0,0,.72-1.41,1.39,1.39,0,0,0-.79-1.39,5.19,5.19,0,0,0-2.21-.33H123v3.55Z" style="fill:#f3f5f6"/>
			<path d="M132,116h7.72v2.17h-5.12v3.14h4.71v2.11h-4.71v3.44h5.17V129H132V116Z" style="fill:#f3f5f6"/>
			<path d="M152,128.74a7.52,7.52,0,0,1-1.41.32,10.93,10.93,0,0,1-1.64.11,7.44,7.44,0,0,1-5.12-1.75,7,7,0,0,1,0-9.75,7.08,7.08,0,0,1,4.93-1.81,11.85,11.85,0,0,1,1.6.1,7.82,7.82,0,0,1,1.56.37l-.09,1.13-.09,1.13a6.29,6.29,0,0,0-2.77-.6,4.3,4.3,0,0,0-3.13,1.15,4.47,4.47,0,0,0-1.19,3.3,4.59,4.59,0,0,0,1.26,3.36A4.34,4.34,0,0,0,149,127a8.37,8.37,0,0,0,1.41-.11,7.54,7.54,0,0,0,1.47-.4l0,1.13Z" style="fill:#f3f5f6"/>
			<path d="M112.71,122.52a6.62,6.62,0,1,0-1.94,4.66A6.58,6.58,0,0,0,112.71,122.52Z" style="fill:#f3f5f6"/>
			<path d="M146.92,230.31l81.31-126.43a8.73,8.73,0,0,1,14.69,0l81.31,126.43a8.73,8.73,0,0,1-7.34,13.46H154.27A8.74,8.74,0,0,1,146.92,230.31Z" style="fill:#ffe700"/>
			<path d="M231.42,142.77h5.18c3.86,0,7,2.2,6.86,4.88l-1.81,45.95c-.11,2.57-3.14,4.62-6.86,4.62h-1.56c-3.72,0-6.76-2.05-6.86-4.62l-1.81-45.95C224.46,145,227.56,142.77,231.42,142.77Z" style="fill:#023852"/>
			<circle cx="233.97" cy="215.12" r="9.7" style="fill:#023852"/>
			<g style="mix-blend-mode:multiply">
				<path d="M324.05,230.48l-51.91-80.72-56.77,56.77L178,243.94H316.7A8.74,8.74,0,0,0,324.05,230.48Z" style="mix-blend-mode:multiply;fill:url(#linear-gradient-2)"/>
			</g>
			<path d="M129.79,175.08a8.33,8.33,0,0,0-8.32-8.33H22.76a8.35,8.35,0,0,0-8.33,8.33V316a8.37,8.37,0,0,0,8.33,8.33h98.71a8.35,8.35,0,0,0,8.32-8.33V175.08Z" style="fill:#023852"/>
			<polygon points="122.14 305.71 72.11 305.71 22.08 305.71 22.08 239.92 22.08 174.13 72.11 174.13 122.14 174.13 122.14 239.92 122.14 305.71" style="fill:#0099da"/>
			<path d="M122.05,174.33H22.28l0,13.38,0,13.38c8.71,8.83,29.35,29.61,50,50.22s41.28,41.06,50,49.25l-.08-63.12Z" style="fill:url(#linear-gradient-3)"/>
			<path d="M31.42,262.21,66.2,208.13a3.74,3.74,0,0,1,6.29,0l34.78,54.08a3.74,3.74,0,0,1-3.14,5.76H34.56A3.74,3.74,0,0,1,31.42,262.21Z" style="fill:#ffe700"/>
			<path d="M67.57,224.76h2.21c1.66,0,3,1,2.94,2.09l-.78,19.66c0,1.1-1.34,2-2.93,2h-.67c-1.59,0-2.89-.88-2.93-2l-.78-19.66C64.59,225.71,65.92,224.76,67.57,224.76Z" style="fill:#023852"/>
			<circle cx="68.66" cy="255.72" r="4.15" style="fill:#023852"/>
			<g style="mix-blend-mode:multiply">
				<path d="M107.19,262.29,85,227.76,60.7,252l-16,16h59.35A3.73,3.73,0,0,0,107.19,262.29Z" style="mix-blend-mode:multiply;fill:url(#linear-gradient-4)"/>
			</g>
			<path d="M36.57,193.46h2A7.5,7.5,0,0,0,31.34,186v2a5.43,5.43,0,0,1,5.23,5.41Z" style="fill:#f3f5f6"/>
			<path d="M33.08,193.46h2a4,4,0,0,0-3.78-4v2.05a1.94,1.94,0,0,1,1.74,1.91Z" style="fill:#f3f5f6"/>
			<path d="M40.52,193.46h2a11.46,11.46,0,0,0-11.23-11.41v2a9.39,9.39,0,0,1,9.18,9.36Z" style="fill:#f3f5f6"/>
			<path d="M376.17,125.38h2a7.48,7.48,0,0,0-7.27-7.46v2a5.43,5.43,0,0,1,5.23,5.41Z" style="fill:#f3f5f6"/>
			<path d="M372.68,125.38h2a4,4,0,0,0-3.78-4v2a2,2,0,0,1,1.23.62A1.91,1.91,0,0,1,372.68,125.38Z" style="fill:#f3f5f6"/>
			<path d="M380.12,125.38h2A11.44,11.44,0,0,0,370.94,114v2a9.39,9.39,0,0,1,9.18,9.37Z" style="fill:#f3f5f6"/>
		</g>
	</g>
</svg>

Used Versions

SVG version 3.4.1 (also tested in 3.3.0 and 3.4.0) Windows 10 .NET 6

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrbean-bremencommented, Apr 11, 2022

A new bugfix release has just been released.

1reaction
H1Gdevcommented, Apr 7, 2022

Cause of Exception is fixed in PR #969 and #970. However mix-blend-mode is not supported and will be ignored by Draw.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An error has occurred.","exceptionMessage": "ColorBlend ...
Hi. I got: The following exception: {"message":"An error has occurred.","exceptionMessage": "ColorBlend object that was set is not valid.
Read more >
SVG gradient not working
I've a svg and I need to fill it with a gradient, the css is added by a script, if U work with...
Read more >
Gradients in SVG - SVG: Scalable Vector Graphics | MDN
There are two types of SVG gradients: linear and radial. They are defined separately from where they are used, which promotes reusability.
Read more >
SVG.NET Release Notes
SVG.NET Release Notes. The release versions are NuGet releases. ... fixed invalid value is set in Attributes of SvgTextBase (see #954); fixed precision ......
Read more >
<linearGradient> - SVG: Scalable Vector Graphics | MDN
The <linearGradient> element lets authors define linear gradients to apply to other SVG elements. Example.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found