反射したアセンブリ内のコレクションを列挙するために必要なヌル参照チェック?

StackOverflow https://stackoverflow.com/questions/3720340

質問

私はC#/。ネット3.5で非常に奇妙な動作に遭遇しています...

コンテンツ管理システムのパイプラインをアップロードするクラスを作成しています。 CMSは、反射を介してこのフックを実行します。

何らかの未知の理由で、次のコード 失敗します nullrefをスローすることにより(「ファイル」はhttpfilecollectionです)。

foreach (var fileKey in args.Files.AllKeys)
{
     // Do Stuff
}

ステートメントがループを作成する前にnullrefチェックを追加した後 成功した. 。アップロードされたファイルはどちらの場合も同一です。ヌル条件が失敗するため、返品ステートメントは実行されません。

if (args.Files == null ) return;
foreach (var fileKey in args.Files.AllKeys)
{
   // Do Stuff
}

私はこれに完全に困惑しています。何か案は?

フルスタックトレース

    ** Exception: System.Web.HttpUnhandledException **
    Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
    Source: System.Web
    at System.Web.UI.Page.HandleError(Exception e)
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    at System.Web.UI.Page.ProcessRequest()
    at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
    at System.Web.UI.Page.ProcessRequest(HttpContext context)
    at ASP.sitecore_shell_applications_flashupload_advanced_uploadtarget_aspx.ProcessRequest(HttpContext context)
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    ** Nested Exception ** 
    Exception: System.Reflection.TargetInvocationException
    Message: Exception has been thrown by the target of an invocation.
    Source: mscorlib
    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes,        RuntimeTypeHandle typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes,        RuntimeTypeHandle typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
    at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
    at Sitecore.Pipelines.Processor.Invoke(PipelineArgs args)
    at Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline)
    at Sitecore.Pipelines.Pipeline.Resume()
    at Sitecore.Pipelines.Pipeline.DoStart(PipelineArgs args)
    at Sitecore.Pipelines.Pipeline.Start(PipelineArgs args, Boolean atomic)
    at Sitecore.Pipelines.Pipeline.Start(PipelineArgs args)
    at Sitecore.Shell.Applications.FlashUpload.Advanced.UploadTarget.HandleUpload()
    at Sitecore.Shell.Applications.FlashUpload.Advanced.UploadTarget.OnLoad(EventArgs e)
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    ** Nested Exception **
    Exception: System.NullReferenceException
    Message: Object reference not set to an instance of an object.
    Source: Sitecore.CustomExtensions
    at Sitecore.CustomExtensions.StreamingMediaUploader.Process(UploadArgs args) in C:\...\Sitecore.CustomExtensions\StreamingMediaUploader.cs:line 33

正しい解決策はありません

他のヒント

ただの推測ですが、CMSにはおそらく予期しない動作(おそらくバグ)があります。バグかどうか、あなた 契約する CMSでは完全に定義されていません。

アップロードされたファイルが一致する理由は、最終的な呼び出しが例外を提起して、メソッドが複数回呼び出された可能性が高いためです。

制御しないアプリを使用していることを考えると、ソリューションは正しいです。使用する前に与えられたすべてを確認する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top