BUG呢 2020-08-25 14:31 采纳率: 60%
浏览 151
已采纳

“this.IsReusable”引发了类型“System.NotImplementedException”的异常?这是什么问题?

想请问下这个问题是怎么回事,怎么解决呢?
图片说明

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;

namespace EF06URL重写
{
public class VerificationCode : IHttpHandler
{
public bool IsReusable => throw new NotImplementedException();

    Random RandomSeed = new Random();
    public void ProcessRequest(HttpContext context)
    {
        string strWord = "123456789QWERTYUIOPASDFGHJKLZXCVBNM";
        string NumStr = null;
        for (int i = 0; i < 5; i++)
        {
            NumStr += strWord[RandomSeed.Next(0, strWord.Length)];
        }
        context.Session["vcode"] = NumStr.ToLower();
        CreateImages(context, NumStr);
    }

    private void CreateImages(HttpContext context, string numStr)
    {
        int iwidth = numStr.Length * 13;
        Bitmap image = new Bitmap(iwidth, 22);
        Graphics g = Graphics.FromImage(image);
        g.Clear(Color.White);
        Color[] colors = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan };
        string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };
        Random rand = new Random();
        for (int i = 0; i < 50; i++)
        {
            int x = rand.Next(image.Width);
            int y = rand.Next(image.Height);
            g.DrawRectangle(new Pen(Color.LightGray, 0), x, y,1,1);
        }
        for (int i = 0; i < numStr.Length; i++)
        {
            int cIndex = rand.Next(7);
            int fIndex = rand.Next(5);
            Font f = new System.Drawing.Font(font[fIndex], 10, FontStyle.Bold);
            Brush b = new System.Drawing.SolidBrush(colors[cIndex]);
            int ii = 4;
            if ((i + 1) % 2 == 0)
            {
                ii = 2;
            }
            g.DrawString(numStr.Substring(i, 1), f, b, 2 + (i * 12), ii);
        }
        g.DrawRectangle(new Pen(ColorTranslator.FromHtml("#CCCCCC"), 0), 0, 0, image.Width - 1, image.Height - 1);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();//保存到内存当中
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//把图片以jpeg保存到ms流当中
        context.Response.ClearContent();
        context.Response.ContentType = "image/gif";
        context.Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-25 14:43
    关注

    string NumStr = null;
    ->
    string NumStr = string.Empty;

    public bool IsReusable => throw new NotImplementedException();
    ->
    public bool IsReusable => true;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 3月25日

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大