문제

I have a custom SPFeatureReceiver, which is supposed to run upon the activation of the feature.

The Feature.template.xml has been modified to this:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Scope="Site" 
         Id="5c15cec8-3ed8-41bc-b124-bd52b6626bbe" 
         Title="MySPSolution" 
         Description="This feature does stuff"
         Version="2.0.0.0"
         Hidden="FALSE"
         ReceiverAssembly="MySPSolution, $SharePoint.Project.AssemblyFullName$"
         ReceiverClass="MySPSolution.BootStrapEventHandler"
         xmlns="http://schemas.microsoft.com/sharepoint/">

</Feature>

The class in question is defined like this:

public class BootStrapEventHandler : SPFeatureReceiver
{

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSecurity.RunWithElevatedPrivileges(() => 
        { 
            using(SPWeb web = properties.Feature.Parent as SPWeb)
            {
                /*Do stuff*/
                web.Update();
            }
        });
    }
    /*Other methods implemented but omitted*/
}

Upon deploying the solution in Visual Studio I receive the following error:

Error   1   Error occurred in deployment step 'Add Solution': Failed to load receiver assembly "MySPSolution, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5c15cec8-3ed8-41bc-b124-bd52b6626bbe" for feature "MySPSolution_Feature1" (ID: 5c15cec8-3ed8-41bc-b124-bd52b6626bbe).: System.IO.FileLoadException: Could not load file or assembly 'MySPSolution\, Version\=2.0.0.0\, Culture\=neutral\, PublicKeyToken\=5c15cec8-3ed8-41bc-b124-bd52b6626bbe' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
File name: 'MySPSolution\, Version\=2.0.0.0\, Culture\=neutral\, PublicKeyToken\=5c15cec8-3ed8-41bc-b124-bd52b6626bbe'
   at System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

What have I done wrong here? I strongly suspect my xml declaration is off, but I can't figure out why.

PS: I have changed the actual namespace to MySPSolution throughout this question.

도움이 되었습니까?

해결책

Robert Lindgrens comment hasn't solved my problem, but it somehow brought my train of thought onto the right track to solve it.

In the end what helped me was doing the following:

  1. Reset feature.template.xml back to default
  2. Right click on the Feature and click Add Event Receiver enter image description here
  3. Copy code from prev. created class to new created event receiver. this class already has SPFeatureReceiver methods implemented. enter image description here
  4. Rebuild - Deploy - Done.

I am not sure, this is the only way to do it, but creating the Event Receiver under the feature instead of the projects root folder solved it for me.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top