小编Mau*_*rGi的帖子

无法将类型为"Newtonsoft.Json.Linq.JObject"的对象强制转换为"System.Runtime.Serialization.ISafeSerializationData"

我试图反序列化一个web api调用时遇到以下异常 - 消息是模糊的,所以我无法理解发生了什么 - 这个演员在其他情况下工作不确定这里有什么问题:

例外:

  InnerException: System.Reflection.TargetInvocationException
   _HResult=-2146232828
   _message=Exception has been thrown by the target of an invocation.
   HResult=-2146232828
   IsTransient=false
   Message=Exception has been thrown by the target of an invocation.
   Source=mscorlib
   StackTrace:
        at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
        at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
        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 Newtonsoft.Json.Serialization.JsonContract.<>c__DisplayClass1.<CreateSerializationCallback>b__0(Object o, StreamingContext context)
        at Newtonsoft.Json.Serialization.JsonContract.InvokeOnDeserialized(Object o, StreamingContext context)
        at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.OnDeserialized(JsonReader reader, JsonContract …
Run Code Online (Sandbox Code Playgroud)

c# json json.net asp.net-web-api

9
推荐指数
2
解决办法
6738
查看次数

Dapper和Enums作为字符串

我正在尝试使用Dapper和将数据库Dapper-Extensions序列化为.enumsstring

现在,它们被序列化为整数(在VARCHAR字段内).

有没有办法做到这一点?我可以添加的任何自定义类型映射?

如果我不能通过它,我可能需要回到EF.

.net c# dapper dapper-extensions

6
推荐指数
4
解决办法
7032
查看次数

C#Generics - 推断静态工厂成员的类型

我想调用使用泛型的类的静态成员,而不指定类型并让编译器推断它们.

例如,这是我想要使用的泛型类,具有静态工厂成员:

public class GenericClass<T>
{
    public T Member;

    // Constructor
    public GenericClass(T value)
    { 
        Member = value; 
    }

    // static factory method
    public static GenericClass<T> StaticFactory(T resultData) 
    { 
        return new GenericClass<T>(resultData); 
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试以下不编译:

    public class Class1
    {
        public GenericClass<string> returnResult1()
        {
            return GenericClass.StaticFactory("Won't Compile, but it's clear that T is a string");
        }

        public GenericClass returnResult2()
        {
            return GenericClass.StaticFactory("Won't Compile, but it's clear that T is a string");
        }
    }
Run Code Online (Sandbox Code Playgroud)

错误1使用泛型类型'SampleStatic.GenericClass'需要1个类型参数

为什么我不能像静态成员一样喜欢以下内容?

    public void ICanInferTheType<T1>(T1 item);

    public void …
Run Code Online (Sandbox Code Playgroud)

c# generics

2
推荐指数
1
解决办法
522
查看次数

使用参数在脚本中导入函数

我有一个带参数的脚本:

param (
    [Parameter(Mandatory=$true)][string]$VaultName,
    [Parameter(Mandatory=$true)][string]$SecretName,
    [Parameter(Mandatory=$true)][bool]$AddToMono = $false
 )
...
Run Code Online (Sandbox Code Playgroud)

在这个脚本中,我想要包含我在另一个ps1文件中编写的函数:common.ps1

我经常导入这个

. .\common.ps1
Run Code Online (Sandbox Code Playgroud)

但如果我在脚本中这样做,我得到:

The term '.\common.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
Run Code Online (Sandbox Code Playgroud)

如何在此脚本中导入common.ps1?

谢谢!

powershell

2
推荐指数
1
解决办法
894
查看次数