none
Error occurs casting properties.Feature.Parent in SPFeatureReceiver RRS feed

  • Question

  • Hello!

    I've got a problem with a SPFeatureReceiver.
    I want to install a feature with the scope "Site" in the feature.xml.

             Version="1.0.0.0"
             Scope="Site"
             ImageUrl ="admintitlegraphic.gif"

             
    Then i try to get the context of the teature in the method FeatureActivated. This ist shown in many examples.

            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                SPSite mysite = (SPSite)properties.Feature.Parent;

               
    This cast doesn't work correctly. It gets an error on the member "UserAccountDirectoryPath"    and does not
    cast the following members like "UserToken", "WarningNotificationSent" and so on. The error is of type
    "System.UnauthorizedAccessException".


    Even if i try to get the SPSite with

                SPSite mysite = new SPSite("http://servername/)";
               
    i get the error, but it can be done this way in a simple Console-Application on my system.
    Any ideas?

    Thank you!

    Thea
    Wednesday, April 2, 2008 8:18 AM

Answers

  •  Thea301 wrote:
    This cast doesn't work correctly. It gets an error on the member "UserAccountDirectoryPath"    and does not
    cast the following members like "UserToken", "WarningNotificationSent" and so on. The error is of type
    "System.UnauthorizedAccessException".

    Do you get this error on the line that performs the cast? Or is it another line of code that throws the cast?

     

    I would expect that if the casting fails, the exception would be "invalid cast" or something like that.

    Wednesday, April 2, 2008 12:23 PM

All replies

  •  Thea301 wrote:
    This cast doesn't work correctly. It gets an error on the member "UserAccountDirectoryPath"    and does not
    cast the following members like "UserToken", "WarningNotificationSent" and so on. The error is of type
    "System.UnauthorizedAccessException".

    Do you get this error on the line that performs the cast? Or is it another line of code that throws the cast?

     

    I would expect that if the casting fails, the exception would be "invalid cast" or something like that.

    Wednesday, April 2, 2008 12:23 PM
  • Hi JanT!

    Thanks for your answer!

    In the meantime i find that its a greater problem. Since a few days we use VS 2008 for developing on our SharePoint server
    and we get errors using the SharePoint-Object modell in many ways. I was wrong when i said i can use this code in an Console-Application, the error only occurs
    at another (and changing) place:

    SPSite mysite = new SPSite("http://servername/)";

    I don't get a correct object SPSite.

    It definitely works in the Visual Studio 2005 enviroment. I' think we've made an mistake by updating ourer enviroment or I use wrong settings in VS 2008.
    Wednesday, April 2, 2008 1:24 PM
  •  Thea301 wrote:
    Hi JanT!
    In the meantime i find that its a greater problem. Since a few days we use VS 2008 for developing on our SharePoint server
    and we get errors using the SharePoint-Object modell in many ways. I was wrong when i said i can use this code in an Console-Application, the error only occurs
    at another (and changing) place:

    SPSite mysite = new SPSite("http://servername/)";

    I don't get a correct object SPSite.

    It definitely works in the Visual Studio 2005 enviroment. I' think we've made an mistake by updating ourer enviroment or I use wrong settings in VS 2008.

    Where do you execute that console application? If you use the object model, the application should be executed on a SharePoint Server.

    Thursday, April 3, 2008 7:52 AM

  • Hello JanT!

    I'm working on the SharePoint Server. VS 2008 is installed there as VS 2005 was before. I should add that we installed SharePoint Server SP1 too, when upgrading Visual Studio. Is it possible that it is a security issue? In Debugging mode i can see Access Denied Exceptions e.g in the UserAccountDirectoryPath member of SPSite.

    Thank you!

    Thea
    Thursday, April 3, 2008 9:01 AM
  • Do you have MOSS installed too?

     

    If so did you also install MOSS SP1?

     

    Friday, April 4, 2008 9:03 PM
  • Hi Michael!

    >Do you have MOSS installed too?

    >If so did you also install MOSS SP1?



    Yes to both!


    Since my last post i found differences between the old version of MOSS and SP1.


    As i said, I've got an error in my MOSS SP1 Enviroment with this code in an console applikation:


                    SPSite site = new SPSite("http://mysharepointserver/");
                    Console.WriteLine(site.UserAccountDirectoryPath);


    I reference the Microsoft.Sharepoint.dll Version 12.0.6219.1000


    I get an Access Error for the UserAccountDirectoryPath Member of the SPSite class.


    Then i testet this code on another system without SP1, Microsoft.Sharepoint.dll Version 12.0.4518.1016

    And for my great surprise, there ist no member
    UserAccountDirectoryPath of the SPSite class.

    Can anyone explain that? And what settings do i need to get access to
    UserAccountDirectoryPath in SP1?

    Thanks!

    Thea














    Wednesday, April 9, 2008 9:07 AM