MMC中的MMC开发

时间:2011-09-06 07:10:05

标签: c# mmc

您好我正在使用C#开发MMC snap,

在这里我想读取XML文件,以便放置我的xml文件。

代码没有给出任何构建错误,但是当我在MMC中添加snapin时,它给出了错误该怎么做。

[SnapInSettings("{2078B103-76FF-46E1-95BB-8B2CE3A72E60}", 
     DisplayName = "Configuration", 
     Description = "abc Pvt Ltd.")
    ]
    public class Mymmc : SnapIn
    {
        XDocument xDoc;
        public Sararmmc()
        {
            ScopeNode childscopenode;
            xDoc = XDocument.Load("MMCSnapinXML.xml");
            IEnumerable<XElement> xelements = xDoc.Root.Descendants();
            this.RootNode = new ScopeNode();
            this.RootNode.DisplayName = xDoc.Root.Attribute("name").Value;
            foreach (XElement elm in xelements)
            {
                childscopenode = new ScopeNode();
                childscopenode.DisplayName = elm.Attribute("name").Value;
                this.RootNode.Children.Add(childscopenode);
            }

        }

    }
我得到了 调用的目标抛出了异常。

Server stack trace: 
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at Microsoft.ManagementConsole.Internal.SnapInClient.CreateSnapIn(String assemblyName, String typeName)
   at Microsoft.ManagementConsole.Internal.ClassLibraryServices.Microsoft.ManagementConsole.Internal.IClassLibraryServices.CreateSnapIn(String assemblyName, String typeName)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   at Microsoft.ManagementConsole.Executive.SnapInInitializationOperation.OnStart()
   at Microsoft.ManagementConsole.Executive.Operation.Start()
   at Microsoft.ManagementConsole.Executive.RunningOperationsTable.EnqueueOperation(Operation operation)
   at Microsoft.ManagementConsole.Executive.StandAloneComponentData..ctor(SnapInRegistrationInfo info, Int32 bookkeepingId)
   at Microsoft.ManagementConsole.Advanced.FrameworkSnapInFactory.Microsoft.ManagementConsole.Advanced.ISnapInFactory.CreateSnapIn(Int32 bookkeepingId, String snapInKey, Object& snapIn)

1 个答案:

答案 0 :(得分:1)

可以在构造函数中抛出许多异常(堆栈跟踪表明这是错误的来源)。它可能是在XDocument.Load上抛出格式错误的XML异常,如果您访问的任何命名节点/属性不存在,它也可能是空引用异常。它可能是一个文件未找到异常,甚至是一个SecurityException - 它甚至可能是更加模糊的东西,比如MMC要求你的程序集被签名..不知道你得到什么类型的异常它对任何人都很难帮助你!

正如我在评论中所说,当您在运行时收到错误时,您无法轻易解释 - 这就是在您的应用程序中进行详细记录变得非常有价值的时候! NLog和log4net是.NET应用程序最常用的两种日志框架