System.TypeLoadException and explicit interface implementation

From: DanM72 (DanM72_at_discussions.microsoft.com)
Date: 02/07/05


Date: Mon, 7 Feb 2005 13:45:02 -0800

If you have :
1) an assembly that is simply declaring an interface and a value type used
by a method in the interface
2) an console application that is having
- a second interface
- a class that is explicitly implementing the 2 interfaces
- a main function that is instantiating the class (or even using just the
__typeof keyword)

then at run time the following exception occurs (using Visual Studio 2003):
-------------------
An unhandled exception of type 'System.TypeLoadException' occurred in
Unknown Module.
Additional information: Method DoSomething in type TestClass from assembly
TestInterface, Version=1.0.1864.28926, Culture=neutral, PublicKeyToken=null
does not have an implementation.
-------------------
But what is interesting is that if you change the order!!! of implementation
in the class to put the implementation of the value type associated inteface
before the other one everything is running correctly.

Here is an example:
1) In the .dll (a class library called MyInterface.dll)
// MyInterface.h
#pragma once
using namespace System;

public __value struct OtherAssemblyValue
{
  Int32 value;
};
public __gc __interface IOtherAssembly
{
  void Method1(OtherAssemblyValue val);
};

2. In the console application (has an reference to the MyInterface.dll)
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;

public __gc __interface ISomething
{
  void DoSomething();
};
public __gc class TestClass : public ISomething , public IOtherAssembly
{
public:
  void ISomething::DoSomething(){}
  void IOtherAssembly::Method1(OtherAssemblyValue val){}
};
int _tmain()
{
  TestClass* test = new TestClass();
  //or uncomment next line
  //__typeof(TestClass);
        return 0;
}

So if the 2 lines are declared in this order then it is generating an
exception
  void ISomething::DoSomething(){}
  void IOtherAssembly::Method1(OtherAssemblyValue val){}
but if you swap the 2 lines (quite a workaround...)
  void IOtherAssembly::Method1(OtherAssemblyValue val){}
  void ISomething::DoSomething(){}
the application is running correctly

Do you have an ideea about what is wrong here?

Dan



Relevant Pages

  • Problem getting events from C# to VJ++
    ... interface IWeatherEvents: IUnknown ... public delegate void WeatherChangedDelegate(int nTemperature); ... // float Temperature ... private float m_fTemperature = 0; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Question about Java updates installed?
    ... public long add(int a, int b) ... either encapsulate the add method in an interface and then ... void test() throws Exception { ... A multicast delegate was also possible. ...
    (comp.lang.java.advocacy)
  • Re: com interop
    ... with showing a movie, and yet, you want the spell checker from word? ... > i need to know what interface ms-word's spell checker uses. ... > void Pause(); ... > // DisplayUsage(); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delegates VS interfaces - some confusion
    ... one member of the interface, whereas with a delegate you can specify ... delegate void Func; ... algorithm not changing at run time and how that makes it intrinsic to ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: assembly security/permission question
    ... public OpenFileDialog openFileDialog1 = new OpenFileDialog; ... public void ShowFileDialog() ... TestClass tc = new TestClass; ... private void button1_Click(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework)