.NET Framework - COR_E_TYPELOAD error with CoCreateInstance of a COM exposed .Net class

Asked By a on 03-May-12 10:11 AM
I am using SXS COM activation to use CoCreateInstance to create a  COM
exposed .Net class --- I get
CoCreateInstance failed; HRESULT: 0X80131522
Why might this be? --- I cannot think how to debug this.

Thanks in advance for any advice on debugging this issue.




a replied to a on 04-May-12 04:29 AM
Found the problem, recording here for posterity.

So, I got no help from sxstrace or fuslogvw.

The problem was this:

I was writing a simple C# class like this:

UiLauncher.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

[ComVisible(true)]
[Guid("9014512b-748e-4752-8bab-ad340f947df3")]
[ClassInterface(ClassInterfaceType.None)]
public class UiLauncher : IUiLauncher
{
private ExampleUi m_ui =3D null;

private IwpmExampleViewModel m_example_vm =3D null;

[DllImport("User32.dll")]
static extern IntPtr SetParent (IntPtr hWnd, IntPtr hParent);

public long Show(long parent, IwpmExampleViewModel vm)
{
Debug.Assert(0 !=3D parent, "parent is 0");
Debug.Assert(null !=3D vm, "vm is 0");

m_example_vm =3D vm;
m_ui =3D new ExampleUi(vm);
m_ui.Show();

WindowInteropHelper wih =3D new WindowInteropHelper(m_ui);
IntPtr hWnd =3D wih.Handle;
IntPtr ipparent =3D new IntPtr(parent);
SetParent(hWnd, ipparent);
return (long)hWnd;
}
}


Note --- there is no namespace.


I hacked together (by copy / paste and change from some other example)
a manifest file to allow SXS that looked like this:


manifest
=3D=3D=3D=3D=3D=3D



manifestVersion=3D"1.0">
name=3D"wpfuiserver"
version=3D"0.0.0.0"
processorArchitecture=3D"MSIL" />
clsid=3D"{9014512b-748e-4752-8bab-ad340f947df3}"
threadingModel=3D"Both"
name=3D"wpfuiserver.UiLauncher"
runtimeVersion=3D"v4.0.30319">


Basically I got the clrClass attribute name wrong --- I had put in a
bogus namespace where none was needed so instead of
name=3D"wpfuiserver.UiLauncher"

I should have just had

name=3D"UiLauncher"