小编Dev*_*evT的帖子

错误CS1705:"其版本高于引用的程序集"

我现在一直在研究这个问题并且没有得到解决.我收到以下错误消息:

Compiler Error Message: CS1705: Assembly 'My.Model, Version=1.1.4422.23773, Culture=neutral, 
PublicKeyToken=bfde95ba233094b2' uses 
'Common, Version=3.3.4273.24368, Culture=neutral, PublicKeyToken=bfde95ba233094b2' 
which has a higher version than referenced assembly
'Common, Version=3.3.4269.17112, Culture=neutral, PublicKeyToken=bfde95ba233094b2'

c:\WINDOWS\assembly\GAC_MSIL\Common\3.3.4269.17112__bfde95ba233094b2\Common.dll: 
(Location of symbol related to previous error)
Run Code Online (Sandbox Code Playgroud)

Web服务器正在运行Server 2003.我去了c:\ windows\assembly并且确实注意到列出了3个版本的Common.dll.列出的最高版本是3.3.4269.17112

我将版本为3.3.4273.24368的dll复制到汇编目录中.然后我重新编译并重新部署了我的代码(可能是矫枉过正但是很好).当我在新会话中打开浏览器并再次访问网站URL时,我仍然收到相同的消息.

我可以使用Windows资源管理器并验证现在还列出了更高版本的Common.dll.

我还可以考虑解决这个问题吗?我不想将程序集中的引用更改为指向旧版本.

.net web-deployment

93
推荐指数
6
解决办法
11万
查看次数

创建对象的最佳方式

这似乎是非常愚蠢和基本的问题,但我试图谷歌它,但无法找到一个满意的答案,

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public Person(){}
    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }
    //Other properties, methods, events...
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我有这样的课程,创建对象的最佳方法是什么?

Person p=new Person("abc",15)
Run Code Online (Sandbox Code Playgroud)

要么

Person p=new Person();
p.Name="abc";
p.Age=15;
Run Code Online (Sandbox Code Playgroud)

这两种方法有什么区别,创建对象的最佳方法是什么?

.net c# oop constructor instance

25
推荐指数
5
解决办法
13万
查看次数

数据传输对象模式

对不起,我是企业应用程序的新手以及设计模式.可能是这个问题缺乏对设计模式的了解.我发现使用DTO传输数据更好.

我的业务实体类如下:

public class Patient
{    
    public string ID { get; set; }
    public string FullName { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

所以在我的应用程序中,用户只能提供ID和HospitalID.所以它需要另一个Web服务并获取人员信息

 public class PersonDTO
 {
     public string NIC { get; set; }
     public string FullName { get; set; }
     public string FirstName { get; set; }
     public string BirthPlace { get; set; }
     public string BirthCertificateID { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

所以根据这些信息我去了Patient对象.(使用DTO模式)

所以我想写一个新类来转换如下.

public class …
Run Code Online (Sandbox Code Playgroud)

.net c# design-patterns dto

14
推荐指数
1
解决办法
5万
查看次数

数据访问层的设计模式

你可能觉得这是家庭作业,因为我很抱歉.我搜索过但找不到合适的答案.

所以我的问题是:

我有几个类,每个类都有一个保存方法.所以我为数据库处理创建了一个单独的类.

namespace HospitalMgt.Data
{
    public static class DBConnection
    {
        public static string constr = "Data Source=ABD;Initial Catalog=HospitalMgt;User Id=sa;Password=123";
        public static SqlConnection con;
      //  public static SqlCommand com;

        public static SqlConnection OpenConnection()
        {
            con= new SqlConnection(constr);
            con.Open();
            return con;
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我不认为使用DBConnection类实现所有类是合适的.

我的问题 :

  1. 什么设计模式适合克服这个问题?
  2. 将DBConnection创建为类是一种好习惯吗?(或者它应该是一个接口)

我使用Factory方法找到了一些关于DA图层的文章,但据我所知,这种模式不适合我的情况.

.net c# design-patterns

12
推荐指数
3
解决办法
3万
查看次数

实体类型没有定义键 - 代码优先

我是MVC以及实体框架的新手.我搜索了很多并找到了几个类似的问题(例如实体类型没有定义键),但它们没有解决我的问题.

namespace MvcAppInvoice.Models
{
    public class Customer
    {
        public int CustomerID { get; set; }
        public string FirstName { get; set; }
        public string SurName { get; set; }
        public virtual CustomerType Type { get; set; }
    }

    public class CustomerType
    {
        public int TypeId { get; set; }
        public string TypeName { get; set; }
        public virtual ICollection<Customer> customers { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

添加控制器

当我尝试添加控制器时,它会出现以下错误:

错误

asp.net-mvc entity-framework-4

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

如何在C#中使用StreamReader(新手)

我正在尝试读取文本文件的内容,在这种情况下是一个计算机名称列表(Computer1,computer2等),我认为StreamReader将是您将使用的,但是当我执行以下操作时:

StreamReader arrComputer = new StreamReader(FileDialog.filename)();
Run Code Online (Sandbox Code Playgroud)

我有这个例外:

The type or namespace name 'StreamReader' could not be found (are you missing a using directive or an assembly reference?)  
Run Code Online (Sandbox Code Playgroud)

我对C#很新,所以我确定我犯了一个新手的错误.

.net c# stream

8
推荐指数
2
解决办法
3万
查看次数

使用Entity Framework中的select锁定表

我需要做这样的事情

select * from myTable with (xlock,holdlock)
Run Code Online (Sandbox Code Playgroud)

使用实体框架.这可能吗?我已经开了一个TransactionScopeSerializable隔离级别,但我的选择没有锁定表.我希望他们锁定,直到我完成交易范围.

entity-framework transactionscope table-locking

8
推荐指数
1
解决办法
7172
查看次数

System.Security.Cryptography.CryptographicException -object已存在

public RSAKeyPair()
    {
        string keyContainerName="pEncKey"
        CspParameters cspp = new CspParameters();
        cspp.Flags = CspProviderFlags.UseMachineKeyStore;
        cspp.KeyContainerName = keyContainerName;
        try
        {
            m_RSA = new RSACryptoServiceProvider(1024, cspp);
        }
        catch(Exception e){}
    }
Run Code Online (Sandbox Code Playgroud)

抛出以下异常的原因是什么:

  System.Security.Cryptography.CryptographicException - object already exist 
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪如下:

   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
   at System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)
   at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
   at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
   at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters)
   at XXXXXXXX.Core.RSAKeyPair..ctor(String keyContainerName)
Run Code Online (Sandbox Code Playgroud)

.net encryption rsa c#-4.0

8
推荐指数
1
解决办法
1万
查看次数

无法加载文件或程序集SMDiagnostics.dll

我正在尝试构建包含18个项目的c#.NET解决方案.出乎意料的是,我的一个项目(网络gui)收到了一条奇怪的错误消息.

错误如下

"Error 1839 'Could not load file or assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.'"
Run Code Online (Sandbox Code Playgroud)

除了其中一个项目之外,所有项目都在.net framework 3.5上运行,但我的机器上安装了框架4.0.Visual Studio试图从4.0但不是3.5加载文件(我试图将文件移动到3.5,但这不起作用)

有谁知道这里有什么问题,或者知道我能做些什么来解决这个问题?

关于Throstur

.net c# .net-4.0 visual-studio-2010 .net-3.5

6
推荐指数
1
解决办法
1万
查看次数

在WPF中调整图像大小

我有一个图像,我想重新调整大小,需要保存在我的临时文件夹中.

我试过的如下:

UIElement uie = CanvasHost.Child;
int width = 800;
int height = (int)((width / (double)((FrameworkElement)uie).Width) * (int)((FrameworkElement)uie).Height);          
RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(uie);

string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\temp\";
if (!Directory.Exists(dir))
      Directory.CreateDirectory(dir);

long size = 0;

string filePath = dir + DateTime.Now.Ticks.ToString() + (isPng ? ".png" : ".jpg");
BitmapEncoder enc = null;

using (FileStream fs = File.Create(filePath))
{
    if (isPng)
        enc = new PngBitmapEncoder();
    else
        enc = new JpegBitmapEncoder();

    enc.Frames.Add(BitmapFrame.Create(rtb));
    enc.Save(fs);

    size = fs.Length;
} …
Run Code Online (Sandbox Code Playgroud)

c# wpf image image-resizing

6
推荐指数
2
解决办法
3万
查看次数