当前位置: 动力学知识库 > 问答 > 编程问答 >

MMC development in c#

问题描述:

Hi i am developing MMC snap in C#,

in this i want to read XML file so where to put my xml file.

the code is not giving any build error but when i am adding the snapin in MMC its giveing error what to do.

[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);

}

}

}

i am getting

Exception has been thrown by the target of an invocation.

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)

网友答案:

There are many exceptions which could be thrown in your constructor (the stack trace indicates that this is the source of the error). It could be a malformed XML exception is thrown on XDocument.Load, it could also be null reference exception if any of the named nodes/attributes you're accessing don't exist. It could be a file not found exception, or even a SecurityException - it could even be something more obscure such as MMC requiring that your assembly is signed.. without knowing what type of exception you're getting it's very difficult for anyone to help you!

As I said in my comment, when you receive errors at runtime that you can't easily explain - this is when having verbose logging in your application becomes really valuable! NLog and log4net are the two most popular logging frameworks for .NET applications

分享给朋友:
您可能感兴趣的文章:
随机阅读: