Alex Gordon
Alex Gordon

Reputation: 60892

the namespace .. already contains a definition for

Why am I getting this exception, even though I only have 1 OnUnzipHttpTriggered defined?

enter image description here

I did a global search:

enter image description here

And it showed that indeed I had only 1 one of these classes defined:

enter image description here

What I have tried:

  1. rebuilt
  2. restarted visual studio
  3. checked code in and got latest

Why am I getting this exception?

Here's my VS info:

enter image description here

Upvotes: 1

Views: 7686

Answers (4)

Tolu
Tolu

Reputation: 1147

Deleting and re-creating the file seemed to fix this for me. Renaming it and reversing the rename also seems to work. Looks like a bug.

Upvotes: 1

Priyanjali agarwal
Priyanjali agarwal

Reputation: 61

Reload the visual studio code window by Ctrl+shift+P and then search for Reload window. This worked for me.

Upvotes: 6

rickvdbosch
rickvdbosch

Reputation: 15619

Have a look at the first result in your search. It states pretty clearly that DestinationFileNamer.cs has the namespace AlidadeUtilities.OnUnzipHttpTriggered.Extensions. That's where the problem is, because both the class and (part of) the namespace of that file are AlidadeUtilities.OnUnzipHttpTriggered.

A class cannot have the same name as a namespace in the same namespace as where the class is.

By the way, just a tip: anything starting with On sounds a LOT like an event handler. Please reconsider the name.

EDIT:

The full name of the class you're creating is this:
AlidadeUtilities.OnUnzipHttpTriggered

The namespace of the class DestinationFileNamer is this: AlidadeUtilities.OnUnzipHttpTriggered.Extensions

Your problem is the fact that those two bold parts are the same.

Solution:
The solution would be to either rename the class OnUnzipHttpTriggered or rename the namespace AlidadeUtilities.OnUnzipHttpTriggered**.Extensions.

Upvotes: 3

Vijay Jagdale
Vijay Jagdale

Reputation: 2669

Some other ways to find the problem:

  1. Generate a class diagram and examine it
  2. comment out this class and examine code for any other references
  3. Use a find tool to find this symbol in your codebase. I use AstroGrep.

You also may have a compiled dll (added reference) with an extension method of the same name. In that case you will have to call your class something else.

Upvotes: 1

Related Questions