Stuck on "The type arguments for method cannot be inferred from the usage" error.

Started by
1 comment, last by CdrTomalak 11 years, 7 months ago
I'm scratching my head over trying to implement some code to share textures between D3D10 and D3D11 in SlimDX.
This method is causing the problem:

[source lang="csharp"]
public void InitialiseTextureSharing()

{
// A DirectX10 Texture2D sharing the DirectX11 Texture2D
sharedResource = new SlimDX.DXGI.Resource(textureD3D11);
textureD3D10 = device10_1.OpenSharedResource(sharedResource.SharedHandle); // This fails to compile!

}
[/source]

I get the following error from the compiler:

The type arguments for method 'SlimDX.Direct3D10.Device.OpenSharedResource<T>(System.IntPtr)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

The wierd thing (to me) is, this code is being ported straight from someone elses which is supposed to work. The original code is:
[source lang="csharp"]
// A DirectX10 Texture2D sharing the DirectX11 Texture2D
SlimDX.DXGI.Resource sharedResource = new SlimDX.DXGI.Resource(textureD3D11);
SlimDX.Direct3D10.Texture2D textureD3D10 = device10_1.OpenSharedResource(sharedResource.SharedHandle);
[/source]

The difference with my implementation is I am instantiating the 'sharedResource' and 'textureD3D10' objects in the SlimDX Form.

I certainly didn't expect a compilation error. The code I am basing this on is from: http://www.aaronblog.us/?p=36
... which is all about drawing text in SlimDX with DX11.

I'm totally stumped on this. I've had a look at posts which contain solutions to similar issues, but adapting this to mine is beyond me at present.
Any pointers would be uber-appreciated.

UPDATE:
Signature of OpenSharedResource from SlimDX API docs:
http://slimdx.org/docs/html/M_SlimDX_Direct3D11_Device_OpenSharedResource__1.htm
... and Resource:
http://slimdx.org/docs/html/T_SlimDX_DXGI_Resource.htm
Advertisement
You need to provide the type argument for the method call. This is standard C#; a generic method that doesn't take a parameter with a generic type can't infer the types automatically. Return values aren't enough for inference. So your call should look like:

OpenSharedResource<Texture2D>(sharedResource.SharedHandle);
Mike Popoloski | Journal | SlimDX
Cheers Mike. This did the trick!

This topic is closed to new replies.

Advertisement