MG 3.5 Shader Loading Issue when using pipeline

So i recently decided to convert my XNA project to monogame but i am having problems with my content pipeline:
I used my pipeline to assign a specific loaded effect to the models and apply the texture, however I get an error when trying to load the content in-game.

I tried to isolate the case as much as possible but i might just be missing something:
-i switched to the default instancing shader since it is a shader error.
-i changed the fbx file version to an older type.
-i made a new game in wich i only load the model, no special stuff going on:

Model n2x2x3 = this.Content.Load(“N2x2x3”);

(this is the only line of importance)
but i still get the error:

HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

With stacktrace:

at SharpDX.Result.CheckError()
at SharpDX.Direct3D11.Device.CreatePixelShader(IntPtr shaderBytecodeRef, PointerSize bytecodeLength, ClassLinkage classLinkageRef, PixelShader pixelShaderOut)
at SharpDX.Direct3D11.PixelShader…ctor(Device device, Byte shaderBytecode, ClassLinkage linkage)
at Microsoft.Xna.Framework.Graphics.Shader.CreatePixelShader()
at Microsoft.Xna.Framework.Graphics.Shader.PlatformConstruct(Boolean isVertexShader, Byte shaderBytecode)
at Microsoft.Xna.Framework.Graphics.Shader…ctor(GraphicsDevice device, BinaryReader reader)
at Microsoft.Xna.Framework.Graphics.Effect.ReadEffect(BinaryReader reader)
at Microsoft.Xna.Framework.Graphics.Effect…ctor(GraphicsDevice graphicsDevice, Byte effectCode, Int32 index, Int32 count)
at Microsoft.Xna.Framework.Content.EffectReader.Read(ContentReader input, Effect existingInstance)
at Microsoft.Xna.Framework.Content.ContentTypeReader1.Read(ContentReader input, Object existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.InnerReadObject[T](T existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.ReadObject[T]() at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action1 recordDisposableObject)
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
at Microsoft.Xna.Framework.Content.ContentReader.ReadExternalReferenceT
at Microsoft.Xna.Framework.Content.EffectMaterialReader.Read(ContentReader input, EffectMaterial existingInstance)
at Microsoft.Xna.Framework.Content.ContentTypeReader1.Read(ContentReader input, Object existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.InnerReadObject[T](T existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.ReadSharedResources() at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action1 recordDisposableObject)
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
at Game1.Game1.LoadContent() in D:\Mercurial\World Of Bricks\testprojects\Creator\Monogame\Game1\Game1.cs:line 44
at Microsoft.Xna.Framework.Game.Initialize()
at Game1.Game1.Initialize() in D:\Mercurial\World Of Bricks\testprojects\Creator\Monogame\Game1\Game1.cs:line 31
at Microsoft.Xna.Framework.Game.DoInitialize()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()
at Game1.Program.Main() in D:\Mercurial\World Of Bricks\testprojects\Creator\Monogame\Game1\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

The default instancing shader:

// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file ‘LICENSE.txt’, which is part of this source code package.
float4x4 View;
float4x4 Projection;
struct VSInput
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
struct VSOutput
{
float2 TexCoord : TEXCOORD0;
float4 Position : SV_Position;
};
struct PSInput
{
float2 TexCoord : TEXCOORD0;
};
VSOutput VS(VSInput input, float4x4 worldTransposed : BLENDWEIGHT)
{
VSOutput output = (VSOutput)0;
float4x4 world = transpose(worldTransposed);
float4 positionWorld = mul(input.Position, world);
float4 positionView = mul(positionWorld, View);
output.Position = mul(positionView, Projection);
output.TexCoord = input.TexCoord;
return output;
}
float4 PS(PSInput input) : COLOR0
{
return float4(input.TexCoord.xy, 0, 1);
}
#if SM4
#define PS_PROFILE ps_4_0
#define VS_PROFILE vs_4_0
#else
#define PS_PROFILE ps_3_0
#define VS_PROFILE vs_3_0
#endif
technique
{
pass
{
VertexShader = compile VS_PROFILE VS();
PixelShader = compile PS_PROFILE PS();
}
}

My content pipeline:

[ContentProcessor(DisplayName = “Instanced Model”)]
public class InstancedModelProcessor : ModelProcessor
{
ContentIdentity rootIdentity;
public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
rootIdentity = input.Identity;
return base.Process(input, context);
}
protected override MaterialContent ConvertMaterial(MaterialContent material,ContentProcessorContext context)
{
// Create a new material.
EffectMaterialContent newMaterial = new EffectMaterialContent();
// Tell it to use our custom shader.
newMaterial.Effect = new ExternalReference(“Instancing.fx”,rootIdentity);
// Copy the texture setting across from the original material.
BasicMaterialContent basicMaterial = material as BasicMaterialContent;
if ((basicMaterial != null) && (basicMaterial.Texture != null))
{
newMaterial.Textures.Add(“Texture”, basicMaterial.Texture);
}
// Chain to the base ModelProcessor, so it can build our new material.
return base.ConvertMaterial(newMaterial, context);
}
}

(Sorry for the bad formatting, i couldn’t finde the “code” tag)

Just to be clear EVERYTHING i did (pipeline, my custom shader, fbx importing ect) works on xna.

I am really getting desparate here i have been searching for this for over a week and i really need this to work since i planned on releasing my game this week. (If it had not been that i found an unmanaged memory leak in xna, i didn’t have to switch to monogame in such short notice)

I think I got that error message too when I was assigning an effect parameter that the effect compiler had optimized away. The Monogame compiler is more aggressive in removing unused parameters than XNA was.

I see where you are going but even then the model should still load.
There are no errors in the compilation or pipeline, only when loading the model in game. I am not even assigning parameters yet at that stage its just the Content.load() that fails.

I never used effects in the model pipeline myself, not even in XNA. I guess plan B is to assign the effects at runtime, during drawing.

I will try plan B then :slight_smile:
Do you know the best (or a good) way to compile the shader at compile time and import it at runtime?
Most documentation i find compiles at runtime.

Not sure…

I am just debugging my own skinned animation code and I can see that the effect is assigned to the mesh parts in the custom model processor, but all parameters are set just before Draw.
So perhaps you can just move the code that assigns the parameters to runtime, and still create the effect at compile time, since the error message seems to complain about the parameters.

I just tried and i can’t load the effects at run time.
Maybe there is something wrong with the shader?
i used:

Shader = content.Load(“Instancing”);

and it gives the exact same error.
I don’t know what i am missing, the example shader should work right?

You won’t believe this:
I found in a previous post: How do I load FX files?
A rather weird solution, lower the shader model to 4_0_level_9_3 and it works!
I think this might actually be a bug in monogame/sharpdx.
Monogame should support everything directx11 supports so that should include 5_0.
Does anyone know where i should report this?