Null Reference Exception on passing texture to HLSL

Hello everyone, when I try to pass a texture to my shader, it gives me a null reference error.

Shader:

    #if OPENGL
    	#define SV_POSITION POSITION
    	#define VS_SHADERMODEL vs_3_0
    	#define PS_SHADERMODEL ps_3_0
    #else
    	#define VS_SHADERMODEL vs_4_0_level_9_1
    	#define PS_SHADERMODEL ps_4_0_level_9_1
    #endif

    float3 LightDirection;
    float3 LightColor = 1.0;
    float3 AmbientColor = 0.35; 

    Texture2D ScreenTexture;
    sampler TextureSampler = sampler_state
    {
    	texture = <ScreenTexture>;
    };

    Texture2D NormalTexture;
    sampler NormalSampler = sampler_state
    {
    	texture = <NormalTexture>;
    };

    float4 main(float4 pos : SV_POSITION, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
    {
    	//Look up the texture value
    	float4 tex = ScreenTexture.Sample(TextureSampler, texCoord);

    	//Look up the normalmap value
    	float4 normal = 2 * NormalTexture.Sample(NormalSampler, texCoord) - 1;

    	// Compute lighting.
    	float lightAmount = saturate( dot(normal.xyz, LightDirection));
    	color.rgb *= AmbientColor + (lightAmount * LightColor);

    	return color*tex;
    }

    technique Normalmap
    {
    	pass Pass1
    	{
    		PixelShader = compile PS_SHADERMODEL main();
    	}
    }

draw function:

        protected override void Draw(GameTime gameTime)
        {
            Vector2 dir = new Vector2(0, 0);
            dir.Normalize();

            Vector3 lightDirection = new Vector3(dir.X, dir.Y, 0.05f);
            lightDirection.Normalize();

            GraphicsDevice.Clear(Color.CornflowerBlue);
            GraphicsDevice.BlendState = BlendState.Opaque;

            effect.Parameters["LightDirection"].SetValue(lightDirection);
            effect.Parameters["NormalTexture"].SetValue(normalMap);
            effect.Parameters["ScreenTexture"].SetValue(texture);
            effect.Parameters["LightColor"].SetValue(new Vector3(1f, 1f, 1f));
            effect.Parameters["AmbientColor"].SetValue(new Vector3(.25f, 0.25f, 0.25f) * 0.0001f);

            effect.CurrentTechnique.Passes[0].Apply();

            spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, effect);
            spriteBatch.Draw(texture, Vector2.Zero, Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }

What’s the value of texture here? Where is it being loaded?

Where does that happen? What’s the stack trace?

I’m loading the texture in the game1 file,
texture = content.Load<Texture2D>(“normalMap”);

Have you verified the texture was successfully loaded and not null?

Having this same issue with the exact same shader file. Verified that the texture is loaded and not null. I seen this with other shaders too where it errors out saying parameters are null when I try to set them, even when these parameters ARE used in the shader. I know that unused parameters are shaved off but these are not unused.

Weird thing is I can add some innocuous line of code to one of the shader functions, and suddenly it works. Remove the line, and it doesn’t work. The shaders compile correctly in MGCB without errors and load into the game just fine, all the textures load, etc.