Search code examples
c#textslimdx

Strange "The type arguments for method cannot be inferred from the usage."


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:

    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! 

    }

I get the following error from the compiler:

The type arguments for method 'SlimDX.Direct3D10.Device.OpenSharedResource(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:

        // 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);

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


Solution

  • Based on the documentation, the reason you get an error is because the code is wrong. OpenSharedResource takes a generic argument that specifies which type to return, so it should be

    SlimDX.Direct3D10.Texture2D textureD3D10 = device10_1.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);
    

    In HTML, < and > are used for elements; because of this, it's not uncommon for code snippets to get their generic arguments filtered out on people's blogs without anyone realising. In that case, you need to reinsert them yourself.