System.TypeLoadException and explicit interface implementation
From: DanM72 (DanM72_at_discussions.microsoft.com)
Date: 02/07/05
- Next message: Tarek Madkour [MSFT]: "Re: Error; Why is VS C++ deleting my events from the form?"
- Previous message: _Christopher\(M2M\): "Error; Why is VS C++ deleting my events from the form?"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Tarek Madkour [MSFT]: "Re: Error; Why is VS C++ deleting my events from the form?"
- Previous message: _Christopher\(M2M\): "Error; Why is VS C++ deleting my events from the form?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|