Build error in overloaded function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I am having a build error in one of the overloaded functions in my class.
The function takes either a string as a parameter or a type referenced in
another dll as a parameter. My class references the dll where the type of the
parameter is defined. I am able to create to create my class in a form
without any build errors and without any references to the DLL where the
other parameter type is defined. The form only uses the function with the
string parameter and not the other one. But when i try to call the overloaded
function with a string parameter, i get an build error saying a reference to
the DLL containing the other parameter type should be added to the form.

I dont understand why the build error happens only when the function in my
class is called and not when it is created. Also i quite dont get why i
should add a reference in the form to the external parameter type when the
form is never gonna use it.

If the question seems confusing i will be happy to give out more details.
Has anybody faced this kind of error before. I would appreciate it if
somebody can let me know if and how the above problem can be fixed.

Thank You,
-Vish
 
Vish,

That's the thing though, it is going to use that type. Once you decide
to call the overload that uses the type from the other assembly, the
compiler needs the type information to make the call (not to mention the
fact that you are probably going to create an instance of that type if you
are going to pass it to an overload that expects it).

So in the end, you have to set a reference to that assembly if you want
to call that overload.

Hope this helps.
 
Hi Nick,

I am going to be calling the overloaded function from the form but never
using the parameter referenced in the external assembly. The form is always
going to use the string parameter. The function will be called with the other
parameter type in other projects and never in the form so why should a
reference to the external assembly be needed in the form. Also why does the
build error happen when i call the function and not when i create class with
the function.

-Vish



Nicholas Paldino said:
Vish,

That's the thing though, it is going to use that type. Once you decide
to call the overload that uses the type from the other assembly, the
compiler needs the type information to make the call (not to mention the
fact that you are probably going to create an instance of that type if you
are going to pass it to an overload that expects it).

So in the end, you have to set a reference to that assembly if you want
to call that overload.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vish said:
Hi all,

I am having a build error in one of the overloaded functions in my class.
The function takes either a string as a parameter or a type referenced in
another dll as a parameter. My class references the dll where the type of
the
parameter is defined. I am able to create to create my class in a form
without any build errors and without any references to the DLL where the
other parameter type is defined. The form only uses the function with the
string parameter and not the other one. But when i try to call the
overloaded
function with a string parameter, i get an build error saying a reference
to
the DLL containing the other parameter type should be added to the form.

I dont understand why the build error happens only when the function in my
class is called and not when it is created. Also i quite dont get why i
should add a reference in the form to the external parameter type when the
form is never gonna use it.

If the question seems confusing i will be happy to give out more details.
Has anybody faced this kind of error before. I would appreciate it if
somebody can let me know if and how the above problem can be fixed.

Thank You,
-Vish
 
Vish said:
Hi Nick,

I am going to be calling the overloaded function from the form but never
using the parameter referenced in the external assembly. The form is always
<snip>

The compiler needs the external assembly because, even though we both
know it can't be in this case, the other parameter which it doesn't know
the type of yet (because the assembly isn't referenced), *could* be
compatible with the String parameter.

In short, you need to provide a reference to the other assembly, or hide
that method from the assembly you want to use (make it internal or
something).
 
Back
Top