我正在使用LINQPad来测试代码(我必须说,这是一个很棒的产品),但是当我尝试将Thread.CurrentPrincipal设置为一个自定义的IPrincipal时,我遇到了一个异常,该自定义的IPrincipal在示例中跟随了一个示例的SerializableAttribute问题
void Main()
{
Thread.CurrentPrincipal = new MyCustomPrincipal();
}
// Define other methods and classes here
[Serializable]
public class MyCustomPrincipal : IPrincipal
{
public bool IsInRole(string role)
{
return true;
}
public IIdentity Identity
{
get
{
return new WindowsIdentity("RECUPERA\\m.casamento");
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在LINQPad(C#Program as Language)中运行此代码时,我得到以下异常
Type is not resolved for member 'UserQuery+MyCustomPrincipal,query_nhxfev, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null'
RuntimeMethodInfo: PluginWindowManager.get_Form ()
Run Code Online (Sandbox Code Playgroud)
如果我删除Serializable属性一切正常.这似乎是与LINQPad使用的AppDomain体系结构相关的问题,以及框架无法找到定义MyCustomPrincipal的程序集.此外,我相信将MyCustomPrincipal定义到另一个程序集并将其放入GAC可以解决问题,但这对我来说不是一个选择.有人有想法吗?
谢谢,马可
编辑:我不知道它是否可以帮助,但我遇到了与SqlDependency.Start相同的问题:将Serializable放在IPrincipal上使得框架抛出一个错误,抱怨它无法找到定义类型的程序集IPrincipal的.我用一个可耻的黑客解决了:
System.Security.Principal.IPrincipal principal;
principal = System.Threading.Thread.CurrentPrincipal;
System.Threading.Thread.CurrentPrincipal = null;
try
{
SqlDependency.Start(connectionString);
m_SqlDependencyStarted = true;
}
catch (Exception …Run Code Online (Sandbox Code Playgroud) 我想在AppVeyor上运行一些xUnit测试,需要一个可用的redis实例.我没有在AppVeyor的"服务"中找到Redis,所以我最终得到了一个自定义解决方案,你可以从appveyor.yml看到
version: 1.0.{build}
before_build:
- nuget restore .\Hangfire.Redis.StackExchange.sln
- START .\packages\Redis-32.2.6.12.1\tools\redis-server.exe ".\packages\Redis-32.2.6.12.1\tools\redis.conf"
- '@ECHO Redis Started'
build:
publish_nuget: true
publish_nuget_symbols: true
verbosity: minimal
Run Code Online (Sandbox Code Playgroud)
不幸的是,构建过程陷入困境 START .\packages\Redis-32.2.6.12.1\tools\redis-server.exe ".\packages\Redis-32.2.6.12.1\tools\redis.conf"
任何想法或可能的解决方法?