Fragment Shader not applyable at runtime?

I have the following scenrario:
A Script generates ShaderCode and it is assigned to a virtual Material.
The ShaderCode contains a fragment Shader and is working, if I put the Code into a .shader file and assign it to a created Material file.

If I try to assign the pure Code as a string to a new Material (Material m = new Material(Code)),
the compiler produces:

Shader error in ‘mcfShaders/Diffuse’: Parse error: syntax error at line 15

So something is wrong with the CGPROGRAM. Maybe the Mapping in vertexInput or fragmentInput?
This errormessage is not really helping…

Shader "mcfShaders/Diffuse" {
  Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
  }
  SubShader {
    Tags { "RenderType"="Transparent" "Queue"="Transparent" "LightMode"="ForwardBase" }

    LOD 200
    ZWrite On
    Lighting On
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Back

    Pass {
      CGPROGRAM
      #pragma exclude_renderers ps3 xbox360 flash
      #pragma fragmentoption ARB_precision_hint_fastest
      #pragma vertex vert addshadow fullforwardshadows
      #pragma fragment frag

      uniform float4 _Color;

      struct vertInput {
        float4 vertex : POSITION;
        float4 color : COLOR;
      };

      struct fragInput {
        float4 pos : SV_POSITION;
        float4 diff : COLOR0;
      };

      fragInput vert(vertInput i) {
        fragInput r;
        r.pos = mul(UNITY_MATRIX_MVP, i.vertex);
        r.diff = _Color;
        return r;
      }

      half4 frag( fragInput i ) : COLOR {
        return half4(i.diff);
      }
      ENDCG
    }
  }
  Fallback "Diffuse"
}

Hope someone with knowledge finds this :slight_smile:

http://docs.unity3d.com/ScriptReference/Material-ctor.html

From that page:

NOTE: Creating materials this way
supports only simple shaders (fixed
function ones). If you need a surface
shader, or vertex/pixel shaders,
you’ll need to create shader asset in
the editor and use that.