HelloWorld.dll SharePoint功能激活错误

时间:2010-03-03 20:51:42

标签: sharepoint-2007

我现在可以使用gacutil.exe和sn.exe将我的HelloWorld.dll导入GAC,并将其上传到SharePoint。 我可以在功能列表中看到它。 但是,当我尝试激活它时,我得到:

Feature '79bc44ea-93f5-4886-8784-8f3fbd1dfa48' could not be installed because the loading of      event      receiver assembly "HelloWorld, Version 1.0.0.0, Culture=neutral,        PublicKeyToken=b169cb5c722a4763" failed: System.IO.FileLoadException: Could not load file or assembly 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b169cb5c722a4763' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 
File name: 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b169cb5c722a4763' 
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() 

这是一个新手功能,它有一个事件处理程序,我的feature.xml文件:

<Feature
Id="79bc44ea-93f5-4886-8784-8f3fbd1dfa48"
Title="Hello World Feature"
Description="This is my first custom Featuree"
Scope="Web"
Hidden="False"
ImageUrl="menuprofile.gif"
ReceiverAssembly="HelloWorld, Version 1.0.0.0, Culture=neutral, PublicKeyToken=b169cb5c722a4763"
ReceiverClass="HelloWorld.FeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>

</Feature>

我的elements.xml文件:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
 Id="SiteActionsToolbar"
 GroupId="SiteActions"
 Location="Microsoft.SharePoint.StandardMenu"
 Sequence="100"
 Title="Hello World"
 Description="A custom menu item added using a Feature"
 ImageUrl="_layouts/images/menuprofile.gif">
 <UrlAction Url="http://msdn.microsoft.com"/>
</CustomAction>
 </Elements>

当我运行sn.exe时,dll有效,并且它在GAC中。由于事件处理程序,我确实有一个.cs文件,我假设它在dll中? 如果我编写功能“Id”是否重要,我只是从我正在使用的代码示例中复制了一个数字。 我可以研究其他一般领域吗?

这是接收器类:

using System;
using Microsoft.SharePoint;

namespace HelloWorld
{
public class FeatureReceiver : SPFeatureReceiver
{
    public override void       FeatureInstalled(SPFeatureReceiverProperties properties)
    {
    }
    public override void   FeatureUninstalling(SPFeatureReceiverProperties properties)
    {
    }
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        Console.WriteLine("...in HelloWorld.FeatureActiviated()...");
        SPWeb site = (SPWeb)properties.Feature.Parent;
        site.Properties["OriginalTitle"] = site.Title;
        site.Properties.Update();
        site.Title = "Hello World";
        site.Update();
    }
    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPWeb site = (SPWeb)properties.Feature.Parent;
        site.Title= site.Properties["OriginalTitle"] = site.Title;
        site.Update();
    }
}
}

1 个答案:

答案 0 :(得分:0)

  1. 功能ID必须是唯一的,这是真的。你可以自己动手或使用guidgen.exe(我在C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ bin \ guidgen.exe)
  2. 如果您为Visual Studio下载WSPBuilder并添加到项目新项目“Receiver的功能”,您将可能会做得更好,该项目将自动提供有效的feature.xml和功能接收器代码的有效类。