Directional lightmap in custom shader

I have this error:

Fragment program 'frag': Unrecognized sampler 'samplerunity_lightmap'
- does not match any texture and is not a recognized inline name
(should contain filter and wrap modes)

when I write

UNITY_SAMPLE_TEX2D_SAMPLER( unity_LightmapInd, unity_Lightmap, i.uv1 );

I’m just trying to get directional lightmap in custom shader, but i have this strange error.
If I write unity_Lightmap instead of unity_LightmapInd i don’t have error.

In recent versions of Unity this error seems to occur anytime you access a texture using a sampler that isn’t named "sampler##texturename".

To access unity_LightmapInd, which doesn’t inherently have a sampler defined, I found I needed to declare the corresponding named sampler:

SamplerState samplerunity_LightmapInd;

You don’t even need to initialize it or anything.

Then you can read from the texture like any other.

UNITY_SAMPLE_TEX2D(unity_LightmapInd, i.uv1)

This occurs when you use unity_LightmapInd without unity_Lightmap.
unity_LightmapInd is supposed to use the sampler of unity_Lightmap, named samplerunity_Lightmap.
If you do not use unity_Lightmap in your shader, then the optimizer will strip it and its sampler from shader.