奇怪的是“不能从用法中推断出方法的类型参数." [英] Strange "The type arguments for method cannot be inferred from the usage."

查看:452
本文介绍了奇怪的是“不能从用法中推断出方法的类型参数."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试实现一些代码以在SlimDX中的D3D10和D3D11之间共享纹理的过程中,我ing之以鼻.

I'm scratching my head over trying to implement some code to share textures between D3D10 and D3D11 in SlimDX.

此方法引起了问题:

    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:

无法从用法中推断出方法'SlimDX.Direct3D10.Device.OpenSharedResource(System.IntPtr)'的类型参数.尝试显式指定类型参数.

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

与实现的区别在于,我正在SlimDX表单中实例化"sharedResource"和"textureD3D10"对象.

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

我当然没想到编译错误.我基于此的代码来自: http://www.aaronblog.us/?p=36 ...所有关于在带有DX11的SlimDX中绘制文本.

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.

更新:

来自SlimDX API文档的OpenSharedResource签名:

Signature of OpenSharedResource from SlimDX API docs:

http://slimdx.org/docs/html/M_SlimDX_Direct3D11_Device_OpenSharedResource__1.htm

...和资源: http://slimdx.org/docs/html/T_SlimDX_DXGI_Resource.htm

推荐答案

基于文档,出现错误的原因是因为代码错误. OpenSharedResource采用通用参数,该参数指定要返回的类型,因此应该为

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

在HTML中,<>用于元素;因此,在没有任何人意识到的情况下,代码片段在人们的博客上过滤掉其通用参数的情况并不少见.在这种情况下,您需要自己重新插入.

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.

这篇关于奇怪的是“不能从用法中推断出方法的类型参数."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆