Domanda

i have a problem regarding InternalsVisibleTo.

I have an Assembly named A with an internal test class I have a Wcf Service (WcfService1) hosted on iis that is referencing this assembly via static linking (add reference on visual studio).

i have the A - AssemblyInfo.cs file with:

[assembly: InternalsVisibleTo("WcfService1")]

I build and add the A.dll to the WcfService1. Obviously, on WcfService1 class, i call the internal method of the A.dll, and the intellisense signal me correctly the name of the method, the variables etc.

It compile smoothly and no problem is shown.

however, when i build and run on his, the server give me a compilation error:

CS0122 'method called' is inaccessible due to its protection level

so i'm confused: in the Visual Studio IDE i got correctly the autocompletion and no build errors. When run, it cannot use the internal methods?!

Other info: i tried with Strong naming and without(public key calculated via command prompt), with the same result (on IDE is ok, when run it crash).

È stato utile?

Soluzione

Found the solution.

I was calling the internal method from the method initialize() of the IIS.

This method is used to do inizialization, and the class with initialize() must be placed in App_Code folder.

I moved the offending call to another class, in my friend assembly, et voilà, problem solved :) hope it will help someone!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top