我正在尝试使用 程序集解析功能在面向 SQL Server 2019 的 SSIS 项目中使用 JSON.net,因为我无法在 GAC 中安装该程序集,因为它位于托管服务器上。
我在 Visual Studio 中有一个小项目(它包含一个脚本任务)来证明我可以使用程序集解析。我在 Citrix 环境中的 Visual Studio 中创建了原始项目,该项目位于我无法将程序集安装到 GAC 的服务器上。当我在 Visual Studio 中运行它时,它确实有效。我将项目复制到本地计算机并编辑脚本,仅更改引用以指向本地计算机上路径中的程序集。它因以下内容而失败,并且它永远不会打开调试器或到达我设置的断点 - 即使有问题的行位于 try-catch 中。该消息显示在通用消息框中,并且永远不会打开脚本。
at System.RuntimeMethodHandle.InvokeMethod(对象目标,对象[]参数,签名sig,布尔构造函数) 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(对象 obj,对象 [] 参数,对象 [] 参数) 在System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,Binder活页夹,Object []参数,CultureInfo文化) 在System.RuntimeType.InvokeMember(字符串名称,BindingFlags绑定Flags,活页夹活页夹,对象目标,对象[]提供的参数,ParameterModifier []修饰符,CultureInfo文化,字符串[]命名参数) 在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
我已经确定了导致问题的线路。这是带有“JsonConvert”的行。如果我将其注释掉,它将在调试器中打开。以下是我的脚本任务的全部内容。
我试图理解为什么它在一台机器上工作,两台机器都运行 VS 2019,针对 SQL Server 2019 上的 SSIS。VS 版本有细微差别:一台是 16.11.22(本地),Citrix 版本是 16.11。 26.SQL Server Data Tools版本相同。
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
string myJson = "{\"folderName\" : \"TestFolder\"}";
try
{
FolderData myObj = JsonConvert.DeserializeObject<FolderData>(myJson);
}
catch (Exception ex)
{
}
Dts.TaskResult = (int)ScriptResults.Success;
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Newtonsoft"))
{
string path = @"c:\users\user123\Downloads\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.Json.dll"));
}
return null;
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
public class FolderData
{
public string FolderName { get; set; }
}
因此,解决方案是通过右键单击我的项目,选择属性-->配置属性-->调试,并将 Run64BitRuntime 设置为 False,将我的项目设置为不使用 64 位运行时。
我已经通过来回更改两次成功验证了。设置为true,失败。设置为 false,它将运行并打开调试器。